Skip to content

Instantly share code, notes, and snippets.

@nicholastay
Last active December 4, 2022 03:33
Show Gist options
  • Save nicholastay/55b9f07f8faf40672863f9dd89840946 to your computer and use it in GitHub Desktop.
Save nicholastay/55b9f07f8faf40672863f9dd89840946 to your computer and use it in GitHub Desktop.
AOC 2022 random js attempts for fun
// Day 1 Part 1
Math.max(...input.split('\n').reduce((acc, val) => (val === '' ? [...acc, 0] : (acc.slice(0, -1).concat(acc[acc.length-1] + Number(val)))), [0]));
// Day 1 Part 2
new Int32Array(input.split('\n').reduce((acc, val) => (val === '' ? [...acc, 0] : (acc.slice(0, -1).concat(acc[acc.length-1] + Number(val)))), [0])).sort().slice(-3).reduce((a, b) => a + b);
// Day 2 Part 1
input
.split('\n')
.map(x => [x[2].charCodeAt(0)-88, x[0].charCodeAt(0)-65])
.reduce((acc, [hand, opp]) => (acc + hand+1 + ((hand === opp) ? 3 : (((opp + 1) % 3 === hand) ? 6 : 0))), 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment