Mercurial > lbo > hg > aoc22
view 2022/01/01.jl @ 65:f2fb41098579
Day 12: refactor memoization
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 23 Dec 2023 17:29:13 +0100 |
parents | 05ddc45b4210 |
children |
line wrap: on
line source
const input = "01/input.txt" function count_calories(data::Vector{Vector{Int}})::Int reduced = [sum(v) for v in data]; maximum(reduced) end function top_three(data::Vector{Vector{Int}})::Int reduced = [sum(v) for v in data]; sort!(reduced); sum(reduced[end-2:end]) end function parse_input(filehandle::IO)::Vector{Vector{Int}} input = Vector{Vector{Int}}(); while true current = Vector{Int}(); while true line = readline(filehandle); if isempty(line) break; end push!(current, parse(Int, line)); end if length(current) == 0 break end push!(input, current); end input end function run_01(f::String)::Tuple{Int,Int} input = open(f; read=true) do fh parse_input(fh) end; count_calories(input), top_three(input) end