advent-of-code

Perserverance, or the lack thereof

git clone git://git.shimmy1996.com/advent-of-code.git

day-01.jl (470B)

    1 input = map(x -> parse(Int32, x), readlines(open("input.txt")));
    2 
    3 function part_1(module_masses)
    4     sum(module_masses) do mass
    5         div(mass, 3) - 2
    6     end
    7 end
    8 
    9 function part_2(module_masses)
   10     sum(module_masses) do mass
   11         fuel_cost = 0
   12         while mass > 0
   13             mass = div(mass, 3) - 2
   14             fuel_cost += mass
   15         end
   16         fuel_cost
   17     end
   18 end
   19 
   20 println("Julia:")
   21 println("Part 1: ", part_1(input))
   22 println("Part 2: ", part_2(input))