Skip to content

Instantly share code, notes, and snippets.

@tekerson
Created December 1, 2017 23:01
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 tekerson/cb5af2c573ed114f05e42d6950db1710 to your computer and use it in GitHub Desktop.
Save tekerson/cb5af2c573ed114f05e42d6950db1710 to your computer and use it in GitHub Desktop.
Advent of Code 2017 - JavaScript
const solve = (input) => input
.split('').map(v => parseInt(v, 10))
.reduce((acc, value, i, list) => {
const pair = list[(i + 1) % list.length]
return acc + (value === pair ? value : 0)
}, 0)
const solve = (input) => input
.split('').map(v => parseInt(v, 10))
.reduce((acc, value, i, list) => {
const pair = list[(i + list.length / 2) % list.length]
return acc + (value === pair ? value : 0)
}, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment