-
-
Save Czechh/6858eab0743a5b16e5114416935b28d4 to your computer and use it in GitHub Desktop.
Advent2017 - 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
const cal = input => | |
input | |
.split('') | |
.map(Number) | |
.reduce((mem, x, i, arr) => { | |
if (i === (arr.length - 1)) return x === arr[0] ? (mem + x) : mem; | |
if (x === arr[i + 1]) return mem + x; | |
return mem; | |
}, 0); | |
const cal2 = input => | |
input | |
.split('') | |
.map(Number) | |
.reduce((mem, x, i, arr) => { | |
const wi = ((arr.length / 2) + i) % arr.length; | |
if (x === arr[wi]) return mem + x; | |
return mem; | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment