clean up day 6 and add "precompilation" function that runs part once to precompile the function and then times the compiled result
This commit is contained in:
parent
9174bfc690
commit
0fc3fcc67b
18
aoc.jl
18
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..."
|
||||
|
16
src/day_6.jl
16
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user