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
/** | |
* An array-like structure that extends infinitely in both positive and negative directions | |
* @template TValue Type of value stored in this Axis | |
*/ | |
class Axis { | |
constructor() { | |
/** @type {TValue[]} */ | |
this._posArray = []; | |
/** @type {TValue[]} */ | |
this._negArray = []; |
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
// Define run parameters | |
const INPUT_FILE = 'day19-input-part2.txt'; | |
const END_OF_LINE = '\r\n'; | |
// Define types | |
/** | |
* @typedef {string[]} Message | |
*/ | |
/** | |
* @typedef {number | string} RuleToken |
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
// Define run parameters | |
const INPUT_FILE = 'day19-input-part2.txt'; | |
const END_OF_LINE = '\r\n'; | |
// Define types | |
/** | |
* @typedef {number | string} RuleToken | |
*/ | |
/** | |
* @typedef {RuleToken[]} RuleSequence |
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
/** | |
* @typedef {'*' | '+'} Operator | |
* @typedef {number} Operand | |
* @typedef {Operator | Operand | Expression} Token | |
* @typedef {Token[]} Expression | |
*/ | |
const inputChars = Array.from( | |
require('fs') | |
.readFileSync('day18-input.txt', 'utf-8') |
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
/** | |
* @typedef {'*' | '+'} Operator | |
* @typedef {number} Operand | |
* @typedef {Array<Operator | Operand | Expression>} Expression | |
*/ | |
const inputChars = Array.from( | |
require('fs') | |
.readFileSync('day18-input.txt', 'utf-8') | |
.split('\r\n') |
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 startTime = process.hrtime.bigint(); | |
// Parameters | |
const DIMENSIONS = 5; | |
const ROUNDS = 6; | |
console.log(`Starting with ${ ROUNDS } rounds in ${ DIMENSIONS } dimensions.`); | |
/** | |
* An array-like structure that extends infinitely in both positive and negative directions |
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 startTime = process.hrtime.bigint(); | |
// Parameters | |
const DIMENSIONS = 6; | |
const ROUNDS = 6; | |
console.log(`Starting with ${ ROUNDS } rounds in ${ DIMENSIONS } dimensions.`); | |
/** | |
* An array-like structure that extends infinitely in both positive and negative directions |
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
function parseInput(path) { | |
// split input into main sections | |
const [ fields, myTicket, nearTickets ] = require('fs').readFileSync(path, 'utf-8').split('\r\n\r\n'); | |
// parse into single object | |
return { | |
// extract list of fields and requirements | |
fields: Array.from(fields.matchAll(/^([\w ]+): ([\w\d -]+)$/gm)).map(([, name, reqs], i) => ({ | |
name, | |
options: reqs.split(' or ').map(req => { |
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
/** | |
* An array-like structure that extends infinitely in both positive and negative directions | |
* @template TValue Type of value stored in this Axis | |
*/ | |
class Axis { | |
constructor() { | |
/** @type {TValue[]} */ | |
this._posArray = []; | |
/** @type {TValue[]} */ | |
this._negArray = []; |
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
/** | |
* An array-like structure that extends infinitely in both positive and negative directions | |
* @template TValue Type of value stored in this Axis | |
*/ | |
class Axis { | |
constructor() { | |
/** @type {TValue[]} */ | |
this._posArray = []; | |
/** @type {TValue[]} */ | |
this._negArray = []; |