Last active
February 7, 2018 15:41
-
-
Save arecvlohe/5cd6a74c56546ed912b8fdec75d4c5a5 to your computer and use it in GitHub Desktop.
Advent of Code - Day 1
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 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