Created
December 3, 2017 01:42
-
-
Save shaharz/6715917c6436b790c048642592f46790 to your computer and use it in GitHub Desktop.
Advent of Code 2017 - day 2
This file contains hidden or 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
// part 1 | |
read_file("Downloads/input.txt") | |
|> List.map(Str.split(Str.regexp("[ \t]+"))) | |
|> List.map(List.map(int_of_string)) | |
|> List.map( | |
(l) => | |
List.fold_left( | |
((mn, mx), cur) => (min(mn, cur), max(mx, cur)), | |
(List.hd(l), List.hd(l)), | |
l | |
) | |
) | |
|> List.fold_left((acc, (mn, mx)) => acc + (mx - mn), 0); | |
// part 2 | |
read_file("Downloads/input.txt") | |
|> List.map(Str.split(Str.regexp("[ \t]+"))) | |
|> List.map(List.map(int_of_string)) | |
|> List.map( | |
(l) => | |
List.map( | |
(a) => ( | |
a, | |
try (List.find((b) => a != b && a mod b == 0, l)) { | |
| Not_found => (-1) | |
} | |
), | |
l | |
) | |
|> List.fold_left((acc, (a, b)) => b == (-1) ? acc : a / b, 0) | |
) | |
|> List.fold_left((acc, x) => acc + x, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment