Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 1.03 KB

solution.org

File metadata and controls

39 lines (33 loc) · 1.03 KB

Advent of Code Day 6 Solution

Parsing the file:

filename = get(ARGS, 1, "sample_input")
input = open(f -> read(f, String), filename) |> chomp
"mjqjpqmgbljsphdztnvjfqwrcgsmlb"

Trying to find first time there’s 4 different characters

l4 = fill("", 4)
for (i, v) in input |> i -> split(i, "") |> enumerate
    push!(l4, v); popfirst!(l4)
    if (l4 |> l -> filter(!isempty, l) |> unique |> length) == 4
        println("Part 1: ", i); break
    end
end
Part 1: 7

Trying to find first time there’s 14 different characters

l14 = fill("", 14)
for (i, v) in input |> i -> split(i, "") |> enumerate
    push!(l14, v); popfirst!(l14)
    if (l14 |> l -> filter(!isempty, l) |> unique |> length) == 14
        println("Part 2: ", i); break
    end
end
Part 2: 19