diff --git a/aoc.jl b/aoc.jl index 5a76ea0..e129133 100755 --- a/aoc.jl +++ b/aoc.jl @@ -35,15 +35,29 @@ end function _run_parts(day) + input = _input(day) + if "precompile" ∈ ARGS + @info "precompilation is on" + end if isdefined(Main, :p1) - p1_res = @time Main.p1(_input(day)) + if "precompile" ∈ ARGS + i = copy(input) + Main.p1(i) + end + i = copy(input) + p1_res = @time Main.p1(i) @info "Part 1: $p1_res" else @info "p1() not defined. skipping..." end if isdefined(Main, :p2) - p2_res = @time Main.p2(_input(day)) + if "precompile" ∈ ARGS + i = copy(input) + Main.p2(i) + end + i = copy(input) + p2_res = @time Main.p2(i) @info "Part 2: $p2_res" else @info "p2() not defined. skipping..." diff --git a/src/day_6.jl b/src/day_6.jl index 3e2454b..87db4e0 100644 --- a/src/day_6.jl +++ b/src/day_6.jl @@ -3,21 +3,15 @@ import .Aoc: @aoc using Pipe: @pipe -function solve(input, days) +function solve(input::Vector{String}, days::Int64) fish = @pipe split(input[1], ",") |> parse.(Int, _) - state = Dict{Int, Int}([ [x, 0] for x in 0:8 ]) + state = Dict{Int, Int}([ [x, count(==(x), fish)] for x in 0:8 ]) - for f in fish - state[f] += 1 - end - - for d in 1:days + for _ in 1:days next_day = Dict{Int, Int}([ [x, 0] for x in 0:8 ]) - next_day[8] = get(state, 0, 0) - next_day[6] = get(state, 0, 0) + next_day[8] = next_day[6] = state[0] for i in 0:7 - k = get(state, i+1, 0) - next_day[i] += k + next_day[i] += state[i+1] end state = next_day end