Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Advent of Code - Day 2
let getMax =
Js.Array.reduce((acc, curr) => Js.Math.max_int(acc, curr), min_int);
let getMin =
Js.Array.reduce((acc, curr) => Js.Math.min_int(acc, curr), max_int);
let corruptionChecksum = (path) =>
Node_fs.readFileSync(path, `utf8)
|> Js.String.trim
|> Js.String.split("\n")
|> Js.Array.reduce((acc, curr) => {
let arr = Js.Array.map(int_of_string) @@ Js.String.split("\t") @@ curr;
let diff = getMax(arr) - getMin(arr);
acc + diff;
}, 0);
let res = corruptionChecksum("./src/corruption-checksum.txt");
Js.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.