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').reduce((map, r) => map.set(r.split(' => ')[1], r.split(' => ')[0]), new Map()); | |
let MOLECULE = INPUT.split('\n\n')[1]; | |
let count = 0; | |
while (MOLECULE !== 'e') { | |
const randomMolecule = Array.from(REPLACEMENTS.keys())[Math.round(Math.random() * REPLACEMENTS.size)]; |
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
var INPUT = 34000000 / 10; | |
var houses = new Uint32Array(INPUT); | |
var houseNumber = INPUT; | |
for (var i = 1; i < INPUT; i++) { | |
for (var j = i; j < INPUT; j += i) { | |
if ((houses[j] += i) >= INPUT && j < houseNumber) houseNumber = j; | |
} | |
} |
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
var INPUT = 34000000 / 10; | |
var houses = new Uint32Array(INPUT); | |
var houseNumber = INPUT; | |
for (var i = 1; i < INPUT; i++) { | |
var visits = 0; | |
for (var j = i; j < INPUT; j += i) { | |
if ((houses[j] = (houses[j] || 11) + i * 11) >= INPUT * 10 && j < houseNumber) houseNumber = j; | |
visits++; |
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 WEAPONS = new Map([ | |
['dagger', {cost: 8, damage: 4, armor: 0}], | |
['shortsword', {cost: 10, damage: 5, armor: 0}], | |
['warhammer', {cost: 25, damage: 6, armor: 0}], | |
['longsword', {cost: 40, damage: 7, armor: 0}], | |
['greataxe', {cost: 74, damage: 8, armor: 0}] | |
]); | |
const ARMOR = new Map([ | |
['nothing', {cost: 0, damage: 0, armor: 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 WEAPONS = new Map([ | |
['dagger', {cost: 8, damage: 4, armor: 0}], | |
['shortsword', {cost: 10, damage: 5, armor: 0}], | |
['warhammer', {cost: 25, damage: 6, armor: 0}], | |
['longsword', {cost: 40, damage: 7, armor: 0}], | |
['greataxe', {cost: 74, damage: 8, armor: 0}] | |
]); | |
const ARMOR = new Map([ | |
['nothing', {cost: 0, damage: 0, armor: 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
class Player { | |
constructor(initial, isWizard) { | |
this.history = []; | |
this.initial = initial; | |
this.isWizard = !!isWizard; | |
if (this.isWizard) { | |
this.spells = [{ | |
cost: 53, | |
effect: (m, o) => o.damage(4) |
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
class Player { | |
constructor(initial, isWizard) { | |
this.history = []; | |
this.initial = initial; | |
this.isWizard = !!isWizard; | |
if (this.isWizard) { | |
this.spells = [{ | |
cost: 53, | |
effect: (m, o) => o.damage(4) |
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 SIMPLE_INSTRUCTION = /(hlf|tpl|inc) (\w+)/; | |
const SIMPLE_JUMP_INSTRUCTION = /(jmp) ([+-]\d+)/; | |
const CONDITIONAL_JUMP_INSTRUCTION = /(jie|jio) (\w+), ([+-]\d+)/; | |
const PROCESSOR = new Map([ | |
['a', 0], | |
['b', 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 SIMPLE_INSTRUCTION = /(hlf|tpl|inc) (\w+)/; | |
const SIMPLE_JUMP_INSTRUCTION = /(jmp) ([+-]\d+)/; | |
const CONDITIONAL_JUMP_INSTRUCTION = /(jie|jio) (\w+), ([+-]\d+)/; | |
const PROCESSOR = new Map([ | |
['a', 1], | |
['b', 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 fs = require('fs'); | |
const INPUT = fs.readFileSync('./input.txt', 'utf-8').split('\n').map(Number); | |
const TOTAL_SUM = INPUT.reduce((total, x) => total + x, 0); | |
const GROUP_WEIGHT = TOTAL_SUM / 3; | |
const VALID_PACKAGES = []; | |
for (var i = 1; VALID_PACKAGES.length === 0; i++) { | |
var combination = Combinatorics.combination(INPUT, ++i); | |
var cmb; |