Skip to content

Instantly share code, notes, and snippets.

@Czechh
Last active December 1, 2017 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Czechh/6858eab0743a5b16e5114416935b28d4 to your computer and use it in GitHub Desktop.
Save Czechh/6858eab0743a5b16e5114416935b28d4 to your computer and use it in GitHub Desktop.
Advent2017 - 1
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