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 REINDEER_NAME_REGEX = /^\w+/; | |
const REINDEER_ARGS_REGEX = /\d+/g; | |
const REINDEER_POINTS = new Map(); | |
const TIME = 2503; | |
// Get reindeer name from input | |
const getReindeerName = input => input.match(REINDEER_NAME_REGEX)[0]; |
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 INGREDIENT_ATTRIBUTES_REGEX = /(\w+): capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (-?\d+)/; | |
const TEASPOONS_COUNT = 100; | |
// Parse input and get attributes for all of ingredients | |
const getIngredientAttributes = input => { | |
return input.reduce((map, ingredient) => { | |
const parsed = ingredient.match(INGREDIENT_ATTRIBUTES_REGEX); |
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 INGREDIENT_ATTRIBUTES_REGEX = /(\w+): capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (-?\d+)/; | |
const TEASPOONS_COUNT = 100; | |
// Parse input and get attributes for all of ingredients | |
const getIngredientAttributes = input => { | |
return input.reduce((map, ingredient) => { | |
const parsed = ingredient.match(INGREDIENT_ATTRIBUTES_REGEX); |
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: 3, | |
cats: 7, | |
samoyeds: 2, | |
pomeranians: 3, | |
akitas: 0, | |
vizslas: 0, |
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, |
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 Combinatorics = require('./combinatorics'); | |
const CONTAINERS = [11, 30, 47, 31, 32, 36, 3, 1, 5, 3, 32, 36, 15, 11, 46, 26, 28, 1, 19, 3]; | |
let total = 0; | |
for (let i = 1; i < CONTAINERS.length - 1; i++) { | |
let combination = Combinatorics.combination(CONTAINERS, i); | |
let c = []; | |
while (c = combination.next()) { | |
if (c.reduce((a, b) => a + b) === 150) total++; |
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 Combinatorics = require('./combinatorics'); | |
const CONTAINERS = [11, 30, 47, 31, 32, 36, 3, 1, 5, 3, 32, 36, 15, 11, 46, 26, 28, 1, 19, 3].sort((a, b) => b - a); | |
const MIN_COUNT = 4; | |
let total = 0; | |
let combination = Combinatorics.combination(CONTAINERS, MIN_COUNT); | |
let c; | |
while (c = combination.next()) { | |
if (c.reduce((a, b) => a + b) === 150) total++; |
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 WIDTH = 100; | |
const HEIGHT = 100; | |
class Grid { | |
constructor(width, height, cells) { | |
this.width = width; | |
this.height = height; | |
this.cells = cells; |
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 WIDTH = 100; | |
const HEIGHT = 100; | |
class Grid { | |
constructor(width, height, cells) { | |
this.width = width; | |
this.height = height; | |
this.cells = cells; |
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'); | |
const REPLACEMENTS = INPUT.split('\n\n')[0].split('\n'); | |
const MOLECULE = INPUT.split('\n\n')[1]; | |
const ALL_MOLECULES = new Set(); | |
REPLACEMENTS.forEach(replacement => { | |
const from = replacement.split(' => ')[0]; | |
const to = replacement.split(' => ')[1]; | |
const findRegex = new RegExp(from, 'g'); |