Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active January 5, 2016 16:29
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 ghaiklor/98f640e9a15720cb5c1d to your computer and use it in GitHub Desktop.
Save ghaiklor/98f640e9a15720cb5c1d to your computer and use it in GitHub Desktop.
Advent of Code (Day 12 Part 2)
const fs = require('fs');
const NUMBER_REGEX = /-?\d+/g;
const INPUT = JSON.parse(fs.readFileSync('./input.txt', 'utf-8'), (key, value) => {
if (!Array.isArray(value)) return Object.keys(value).map(key => value[key]).indexOf('red') !== -1 ? {} : value;
return value;
});
const result = JSON.stringify(INPUT).match(NUMBER_REGEX).reduce((total, number) => total + +number, 0);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment