Mercurial > lbo > hg > aoc22
view 01/01.jl @ 10:d110dc63f18e
day 07: finish part 1
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 09 Dec 2022 23:33:39 +0100 |
parents | a6ad52859b77 |
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