# Code giving wrong answer for Advent of Code 2015 day 6

**URL:** https://discourse.julialang.org/t/code-giving-wrong-answer-for-advent-of-code-2015-day-6/43194
**Category:** Offtopic
**Tags:** question
**Created:** [July 16, 2020, 8:16pm UTC](https://discourse.julialang.org/t/code-giving-wrong-answer-for-advent-of-code-2015-day-6/43194 "2020-07-16T20:16:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sanji\_Vinsmoke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sanji_vinsmoke/32/9015_2.png) [@Sanji\_Vinsmoke](https://discourse.julialang.org/u/Sanji_Vinsmoke)
#### Post date: [July 16, 2020, 8:16pm UTC](https://discourse.julialang.org/t/code-giving-wrong-answer-for-advent-of-code-2015-day-6/43194/1 "2020-07-16T20:16:15Z")

</div>

I was trying to write a solution to [Advent of Code 2015 day 6](https://adventofcode.com/2015/day/6#part1) and I am getting a wring answer.

Can someone please help whats going wrong.

```julia
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.

---

<div class="post-metadata">

### Author: ![francesco.alemanno](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)
#### Post date: [July 16, 2020, 8:29pm UTC](https://discourse.julialang.org/t/code-giving-wrong-answer-for-advent-of-code-2015-day-6/43194/2 "2020-07-16T20:29:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Sanji\_Vinsmoke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sanji_vinsmoke/32/9015_2.png) [@Sanji\_Vinsmoke](https://discourse.julialang.org/u/Sanji_Vinsmoke)
#### Post date: [July 17, 2020, 8:52am UTC](https://discourse.julialang.org/t/code-giving-wrong-answer-for-advent-of-code-2015-day-6/43194/3 "2020-07-17T08:52:07Z")

</div>

I have added the link to the [problem](https://adventofcode.com/2015/day/6#part1). 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.
