day 6 p1
This commit is contained in:
parent
594bc3f198
commit
da41491861
1
data/day_6.txt
Normal file
1
data/day_6.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1,4,2,4,5,3,5,2,2,5,2,1,2,4,5,2,3,5,4,3,3,1,2,3,2,1,4,4,2,1,1,4,1,4,4,4,1,4,2,4,3,3,3,3,1,1,5,4,2,5,2,4,2,2,3,1,2,5,2,4,1,5,3,5,1,4,5,3,1,4,5,2,4,5,3,1,2,5,1,2,2,1,5,5,1,1,1,4,2,5,4,3,3,1,3,4,1,1,2,2,2,5,4,4,3,2,1,1,1,1,2,5,1,3,2,1,4,4,2,1,4,5,2,5,5,3,3,1,3,2,2,3,4,1,3,1,5,4,2,5,2,4,1,5,1,4,5,1,2,4,4,1,4,1,4,4,2,2,5,4,1,3,1,3,3,1,5,1,5,5,5,1,3,1,2,1,4,5,4,4,1,3,3,1,4,1,2,1,3,2,1,5,5,3,3,1,3,5,1,5,3,5,3,1,1,1,1,4,4,3,5,5,1,1,2,2,5,5,3,2,5,2,3,4,4,1,1,2,2,4,3,5,5,1,1,5,4,3,1,3,1,2,4,4,4,4,1,4,3,4,1,3,5,5,5,1,3,5,4,3,1,3,5,4,4,3,4,2,1,1,3,1,1,2,4,1,4,1,1,1,5,5,1,3,4,1,1,5,4,4,2,2,1,3,4,4,2,2,2,3
|
45
src/day_6.jl
Normal file
45
src/day_6.jl
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
include(joinpath(readchomp(`git rev-parse --show-toplevel`), "aoc.jl"))
|
||||||
|
import .Aoc: @aoc
|
||||||
|
using Pipe: @pipe
|
||||||
|
|
||||||
|
|
||||||
|
function p1(input::Vector{String})
|
||||||
|
fish = @pipe split(input[1], ",") |> parse.(Int, _)
|
||||||
|
for d in 1:80
|
||||||
|
for f in 1:length(fish)
|
||||||
|
if fish[f] == 0
|
||||||
|
fish[f] = 6
|
||||||
|
push!(fish, 8)
|
||||||
|
else
|
||||||
|
fish[f] -= 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return length(fish)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function p2(input::Vector{String})
|
||||||
|
fish = @pipe split(input[1], ",") |> parse.(Int, _)
|
||||||
|
state = Dict{Int, Int}()
|
||||||
|
fish = [3,4,3,1,2]
|
||||||
|
|
||||||
|
for f in fish
|
||||||
|
haskey(state, f) ? (state[f] += 1) : (state[f] = 1)
|
||||||
|
end
|
||||||
|
@info state
|
||||||
|
|
||||||
|
for d in 1:256
|
||||||
|
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)
|
||||||
|
for i in 0:7
|
||||||
|
k = get(state, i+1, 0)
|
||||||
|
next_day[i] += k
|
||||||
|
end
|
||||||
|
state = next_day
|
||||||
|
end
|
||||||
|
return length(values(state))
|
||||||
|
end
|
||||||
|
|
||||||
|
@aoc(2021, 6)
|
Loading…
x
Reference in New Issue
Block a user