Created
December 2, 2019 12:42
-
-
Save zindel/16679258d6b71080880944b8bef2ca50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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