Skip to content

Instantly share code, notes, and snippets.

View ghaiklor's full-sized avatar

Eugene Obrezkov ghaiklor

View GitHub Profile
@ghaiklor
ghaiklor / aoc-14-2.js
Last active January 5, 2016 16:34
Advent of Code (Day 14 Part 2)
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];
@ghaiklor
ghaiklor / aoc-15-1.js
Last active January 5, 2016 16:37
Advent of Code (Day 15 Part 1)
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);
@ghaiklor
ghaiklor / aoc-15-2.js
Last active January 5, 2016 16:38
Advent of Code (Day 15 Part 2)
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);
@ghaiklor
ghaiklor / aoc-16-1.js
Last active January 5, 2016 16:38
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,
@ghaiklor
ghaiklor / aoc-16-2.js
Last active January 5, 2016 16:39
Advent of Code (Day 16 Part 2)
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,
@ghaiklor
ghaiklor / aoc-17-1.js
Last active January 5, 2016 16:39
Advent of Code (Day 17 Part 1)
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++;
@ghaiklor
ghaiklor / aoc-17-2.js
Last active January 5, 2016 16:41
Advent of Code (Day 17 Part 2)
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++;
@ghaiklor
ghaiklor / aoc-18-1.js
Last active January 5, 2016 16:42
Advent of Code (Day 18 Part 1)
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;
@ghaiklor
ghaiklor / aoc-18-2.js
Last active January 5, 2016 16:43
Advent of Code (Day 18 Part 2)
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;
@ghaiklor
ghaiklor / aoc-19-1.js
Last active January 5, 2016 16:43
Advent of Code (Day 19 Part 1)
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');