trunk
HeNine 3 years ago
parent d85c09244c
commit e26833939c

@ -1,3 +1,5 @@
using Printf
function verify(day, task, case, expresult) function verify(day, task, case, expresult)
taskfun = getfield(Main, Symbol("task", task - 1)) taskfun = getfield(Main, Symbol("task", task - 1))
filename = "day$(@sprintf "%02d" day)\\data\\case$(@sprintf "%02d" case).txt" filename = "day$(@sprintf "%02d" day)\\data\\case$(@sprintf "%02d" case).txt"

@ -0,0 +1,4 @@
name = "day11"
uuid = "eeb063b9-3c05-4ffd-8498-60dcd43cb32f"
authors = ["HeNine "]
version = "0.1.0"

@ -0,0 +1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

@ -0,0 +1,10 @@
7777838353
2217272478
3355318645
2242618113
7182468666
5441641111
4773862364
5717125521
7542127721
4576678341

@ -0,0 +1,83 @@
include("../../AoC2021.jl")
##
function parsefile(file)
(eachline(file) .|> Base.Fix2(split, "") .|>
(x -> parse.(Int, x)) .|>
permutedims) |> x -> vcat(x...)
end
function advancegen(mappe)
mappe .+= 1
reset = []
topop = findall(mappe .> 9)
reset = copy(topop)
while length(topop) > 0
o = pop!(topop)
for ox -1:1, oy -1:1
mappe[o+CartesianIndex(oy, ox)] += 1
if mappe[o+CartesianIndex(oy, ox)] > 9 && o + CartesianIndex(oy, ox) reset
push!(topop, o + CartesianIndex(oy, ox))
push!(reset, o + CartesianIndex(oy, ox))
end
end
end
mappe[reset] .= 0
mappe[1, :] .= -9
mappe[end, :] .= -9
mappe[:, 1] .= -9
mappe[:, end] .= -9
mappe
end
##
function task0(file)
raw_mappe = parsefile(file)::Matrix{Int}
mappe = fill(-9, size(raw_mappe) .+ 2)
mappe[2:(end-1), 2:(end-1)] = raw_mappe
popped = 0
for gen = 1:100
mappe = advancegen(mappe)
popped += sum(mappe .== 0)
end
popped
end
##
verify(11, 1, 0, 1656)
verify(11, 1, 1, 1721)
##
function task1(file)
raw_mappe = parsefile(file)::Matrix{Int}
mappe = fill(-9, size(raw_mappe) .+ 2)
mappe[2:(end-1), 2:(end-1)] = raw_mappe
gen = 0
while !all(mappe[2:(end-1), 2:(end-1)] .== 0)
gen += 1
mappe = advancegen(mappe)
end
gen
end
##
verify(11, 2, 0, 195)
verify(11, 2, 1, 298)
Loading…
Cancel
Save