You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1013 B

#!/usr/bin/env julia
using Test
function elf_max_calories(infile)
max_calories = zeros(Int64, 3)
elf_calories = 0
open(infile, "r") do io
for line in eachline(io)
if length(line) == 0
if elf_calories > max_calories[1]
max_calories[1] = elf_calories
sort!(max_calories)
end
elf_calories = 0
continue
end
snack_calories = parse(Int64, line)
elf_calories += snack_calories
end
if elf_calories > max_calories[1]
max_calories[1] = elf_calories
sort!(max_calories)
end
end
return (max_calories[end], sum(max_calories))
end
function test()
@testset "elf snacks" verbose=true begin
@test elf_max_calories("example.txt") == (24000, 45000)
@test elf_max_calories("input.txt") == (69206, 197400)
end
end
function main()
if size(ARGS, 1) == 0
test()
else
infile = ARGS[1]
println("infile = ", infile)
println("snack calories: ", elf_max_calories(infile))
end
end
main()