Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Advent of Code - Day 1
let inverseCaptcha = (path) => {
let arr =
Node_fs.readFileSync(path, `utf8)
|> Js.String.trim
|> Js.String.split("");
Js.Array.reducei(
(acc, curr, idx) =>
switch (idx == 0) {
| true =>
let firstValue = int_of_string(curr);
let lastValue = int_of_string(arr[Js.Array.length(arr) - 1]);
firstValue == lastValue ? acc + firstValue : acc;
| _ =>
let prevValue = int_of_string(arr[idx - 1]);
let currValue = int_of_string(curr);
prevValue == currValue ? acc + currValue : acc;
},
0,
arr
);
};
let result = inverseCaptcha("./src/inverse-captcha.txt");
Js.log(result);
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.