Skip to content

Instantly share code, notes, and snippets.

View warriordog's full-sized avatar

Hazel K warriordog

  • United States
View GitHub Profile
@warriordog
warriordog / AOC_2020-20.js
Created December 21, 2020 01:15
Solution to Advent of Code 2020 Day 20
/**
* 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 = [];
@warriordog
warriordog / AOC_2020-19_Cache.js
Created December 20, 2020 03:31
Solution to Advent of Code 2020 Day 19, with a cache for memoization
// 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
@warriordog
warriordog / AOC_2020-19.js
Created December 20, 2020 02:49
Solution to Advent of Code 2020 Day 19
// 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
@warriordog
warriordog / AOC_2020-18-2.js
Created December 18, 2020 14:00
Solution to Advent of Code 2020 Day 18 Part 2
/**
* @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')
@warriordog
warriordog / AOC_2020-18-1.js
Created December 18, 2020 14:00
Solution to Advent of Code 2020 Day 18 Part 1
/**
* @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')
@warriordog
warriordog / AOC_2020-17_Unbounded1.js
Created December 18, 2020 07:11
Solution to Advent of Code 2020 Day 17 that supports an arbitary number of dimensions
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
@warriordog
warriordog / AOC_2020-17_Ubounded2.js
Last active December 18, 2020 15:58
Solution to Advent of Code 2020 Day 17 that supports any arbitrary number of dimensions (version 2 - optimized)
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
@warriordog
warriordog / AOC_2020-16-Dual.js
Last active December 18, 2020 03:15
Solution to Advent of Code 2020 Day 16 that uses two field-position mapping algorithms to solve a challenge input
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 => {
@warriordog
warriordog / AOC_2020-17-2.js
Created December 17, 2020 23:08
Solution to Advent of Code 2020 Day 17 Part 2
/**
* 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 = [];
@warriordog
warriordog / AOC_2020-17-1.js
Created December 17, 2020 23:08
Solution to Advent of Code 2020 Day 17 Part 1
/**
* 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 = [];