Skip to content

Instantly share code, notes, and snippets.

@zindel
Created December 2, 2019 12:42
Show Gist options
  • Save zindel/16679258d6b71080880944b8bef2ca50 to your computer and use it in GitHub Desktop.
Save zindel/16679258d6b71080880944b8bef2ca50 to your computer and use it in GitHub Desktop.
let solve lines =
let fuel = fun n -> n / 3 - 2 in
let sum = List.fold_left (+) 0 in
let nums =
lines
|> List.map int_of_string
in
nums
|> List.map fuel
|> sum
|> Printf.printf "Part1 = %d\n";
let all_fuel n =
let rec loop n =
let fuel = fuel n in
if fuel < 0 then [] else fuel :: loop fuel
in
loop n
in
nums
|> List.map all_fuel
|> List.concat
|> sum
|> Printf.printf "Part2 = %d\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment