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 { parseInputFile } = require('../utils/parser'); | |
const Dir = { | |
NORTH: 0, | |
EAST: 90, | |
SOUTH: 180, | |
WEST: 270 | |
}; | |
const inputSteps = parseInputFile('day12-input.txt', /^(\w)(\d+)$/gm) |
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 { parseInputFile } = require('../utils/parser'); | |
const inputSteps = parseInputFile('day12-input.txt', /^(\w)(\d+)$/gm) | |
.map(([, action, num]) => ({ | |
action, | |
amount: parseInt(num) | |
})); | |
// +east -west | |
// +north -south |
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 inputParts = fs.readFileSync('day13-input.txt', 'utf-8').split('\r\n'); | |
const earliestTimestamp = parseInt(inputParts[0].trim()); | |
function findEarliestArrival(id) { | |
let wait = id; | |
while (wait < earliestTimestamp) { | |
wait += id; | |
} | |
return wait; |
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'); | |
/** | |
* @param {bigint} a | |
* @param {bigint} mod | |
*/ | |
function solveMMI(a, mod) { | |
const b = a % mod; | |
for (let x = 1n; x < mod; x++) { | |
if ((b * x) % mod === 1n) { |
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 { parseInputFile } = require('../utils/parser'); | |
/** | |
* Performs a negative-aware modulus operation. | |
* @param {number} a | |
* @param {number} n | |
* @returns {number} | |
*/ | |
function absmod(a, n) { | |
while (a < 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'); | |
/** | |
* | |
* @param {bigint} a | |
* @param {bigint} n | |
*/ | |
function solveMMI(a, n) { | |
let t = 0n; | |
let newT = 1n; |
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 { parseInputFile } = require('../utils/parser'); | |
const inputs = parseInputFile('day14-input.txt', /^(mask|mem)(?:\[(\d+)\])? = ([0-9X]+)$/gm) | |
.map(([, ins, addr, maskOrValue]) => { | |
switch (ins) { | |
case 'mask': return { | |
ins, | |
mask: maskOrValue, | |
maskOR: BigInt(parseInt(maskOrValue.replace(/X/g, '0'), 2)), | |
maskAND: BigInt(parseInt(maskOrValue.replace(/X/g, '1'), 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 { parseInputFile } = require('../utils/parser'); | |
/** @typedef {'0' | '1' | 'X'} Trit */ | |
/** | |
* @param {string} addr | |
*/ | |
function parseAddr(addr) { | |
const arr = Array.from((parseInt(addr) >>> 0).toString(2)); | |
while (arr.length < 36) { |
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 input = [ 6, 4, 12, 1, 20, 0, 16 ]; | |
function part1(debug) { | |
const memory = Array.from(input); | |
for (let i = input.length; i < 2020; i++) { | |
const lastNumber = memory[memory.length - 1]; | |
const lastNumberIndex = memory.lastIndexOf(lastNumber, memory.length - 1); | |
const lastNumberLastIndex = memory.lastIndexOf(lastNumber, lastNumberIndex - 1); |
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
// @ts-ignore | |
const input = [ 6, 4, 12, 1, 20, 0, 16 ]; | |
/** | |
* @template TValue Type of the value held by this ArrayTree | |
*/ | |
class ArrayTree { | |
constructor(scale) { | |
this._lShift = scale; | |
this._rShift = 32 - scale; |