Last active
January 5, 2016 16:39
-
-
Save ghaiklor/ba6e6dcd0fd0b28ec7b8 to your computer and use it in GitHub Desktop.
Advent of Code (Day 16 Part 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: value => value == 3, | |
cats: value => value > 7, | |
samoyeds: value => value == 2, | |
pomeranians: value => value < 3, | |
akitas: value => value == 0, | |
vizslas: value => value == 0, | |
goldfish: value => value < 5, | |
trees: value => value > 3, | |
cars: value => value == 2, | |
perfumes: value => value == 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