Code giving wrong answer for Advent of Code 2015 day 6

I was trying to write a solution to Advent of Code 2015 day 6 and I am getting a wring answer.

Can someone please help whats going wrong.

function solve()
    path = pwd() * "/AoC/input.txt"
    instructions = readlines(path)
    
    lights = BitArray(zeros(1000,1000))

    for i in instructions
        if split(i," ")[1] == "turn"
                start_x,start_y = map(x -> parse(Int64,x),split(split(i," ")[3],','))
                end_x,end_y = map(x -> parse(Int64,x),split(split(i," ")[5],','))
                start_x += 1
                start_y += 1
                end_y += 1
                end_x += 1

            if split(i," ")[2] == "on"

                lights[start_x:start_y,end_x:end_y] .= 1

            elseif split(i," ")[2] == "off"
               
                lights[start_x:start_y,end_x:end_y] .= 0

            end
        elseif split(i," ")[1] == "toggle"

                start_x,start_y = map(x -> parse(Int64,x),split(split(i," ")[2],','))
                end_x,end_y = map(x -> parse(Int64,x),split(split(i," ")[4],','))
                start_x += 1
                start_y += 1
                end_y += 1
                end_x += 1
                lights[start_x:start_y,end_x:end_y] = .!lights[start_x:start_y,end_x:end_y]

        end
    end

    return sum(lights)

end

println(solve())

Also, I would like to know if there is better way to achieve the same task in more “julia-way” .

Thanks in advance.

i think you should state precisely what is the purpose of the code. it will make it easier for others to help

2 Likes

I have added the link to the problem. The code is my attempt to solve the problem.
Do you mean, I comment the code to identify which part of code addresses which part of the problem?
The problem is pretty easy actually, but I am not sure am I missing on some cases or is there any coding mistake that I made as it gives me wring answer.