Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active January 5, 2016 16:38
Show Gist options
  • Save ghaiklor/041e2df91fad25317bcc to your computer and use it in GitHub Desktop.
Save ghaiklor/041e2df91fad25317bcc to your computer and use it in GitHub Desktop.
Advent of Code (Day 16 Part 1)
const fs = require('fs');
const INPUT = fs.readFileSync('./input.txt', 'utf-8').split('\n');
const AUNT_REGEX = /Sue (\d+): (\w+): (\d+), (\w+): (\d+), (\w+): (\d+)/;
const SIGNATURE = {
children: 3,
cats: 7,
samoyeds: 2,
pomeranians: 3,
akitas: 0,
vizslas: 0,
goldfish: 5,
trees: 3,
cars: 2,
perfumes: 1
};
const result = INPUT.filter(item => {
const parsed = item.match(AUNT_REGEX);
return (
SIGNATURE[parsed[2]] == parsed[3] &&
SIGNATURE[parsed[4]] == parsed[5] &&
SIGNATURE[parsed[6]] == parsed[7]
)
})[0].match(AUNT_REGEX)[1];
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment