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
import { map, sum } from "../../lib/arrays.js"; | |
import { gcd } from "../../lib/math.js"; | |
import { pipe } from "../../lib/utils.js"; | |
const parse = input => { | |
const grp = input.split("\n\n"); | |
const net = grp[0] | |
.split("\n") | |
.map(([...line]) => line.map(c => c.trim())); | |
const instr = [...`R${grp[1]}`.matchAll(/(([LR])(\d*))/g)] |
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
import { pipe } from "../../lib/utils.js"; | |
import { | |
sum, | |
product, | |
map, | |
limit, | |
} from "../../lib/arrays.js"; | |
import { MaxHeap } from "../../lib/heaps.js"; | |
const RE = /Blueprint (\d+): Each ore robot costs (\d+) ore. Each clay robot costs (\d+) ore. Each obsidian robot costs (\d+) ore and (\d+) clay. Each geode robot costs (\d+) ore and (\d+) obsidian./; |
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 pipe = (...fns) => v => fns.reduce((a, f) => f(a), v); | |
const MAPPING = "=-012"; | |
const parse = input => | |
input | |
.split("\n") | |
.map(line => | |
line.split("").map(c => MAPPING.indexOf(c) - 2) | |
); | |
const toDecimal = list => |
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
import { pipe } from "../../lib/utils.js"; | |
import { fast_abs as abs, lcm } from "../../lib/math.js"; | |
import { MinHeap } from "../../lib/heaps.js"; | |
const parse = input => input.split("\n").map(([...l]) => l); | |
const mapBlizzard = map => { | |
const [w, h] = [map[0].length - 2, map.length - 2]; | |
const s = Array.from({ length: lcm(w, h) }).map( | |
(_, i) => i |
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
import { pipe } from "../../lib/utils.js"; | |
const X_OFFSET = 1 << 15; | |
const Y_OFFSET = 1 << 29; | |
const W = 1 << 16; | |
// prettier-ignore | |
const MOVES = [ | |
[[-1 -W, 0 -W, 1 -W], 0 -W], | |
[[-1 +W, 0 +W, 1 +W], 0 +W], |
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 pipe = (...fns) => v => fns.reduce((a, f) => f(a), v); | |
const parse = input => { | |
const g = input.split("\n\n"); | |
const map = g[0] | |
.split("\n") | |
.map(line => line.split("").map(c => c.trim())); | |
const instr = [...("R" + g[1]).matchAll(/(([LR])(\d+))/g)] | |
.map(([, , a, b]) => [a, b]) | |
.map(([a, b]) => [a === "L" ? -1 : 1, Number(b)]); |
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 pipe = (...fns) => v => fns.reduce((a, f) => f(a), v); | |
const parse = input => | |
new Map( | |
input | |
.split("\n") | |
.filter(Boolean) | |
.map(line => line.split(": ")) | |
.map(([k, v]) => [k, v.split(" ")]) | |
); |
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
import fs from "fs"; | |
import path from "path"; | |
import { part1, part2 } from "./code.js"; | |
const dir = path.dirname(module.filename); | |
const getLinesFromFile = file => { | |
const filename = `${dir}/${file}`; | |
return fs.readFileSync(filename, "utf8"); | |
}; |
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 pipe = (...fns) => v => fns.reduce((a, f) => f(a), v); | |
const parse = input => | |
input.split("\n").filter(Boolean).map(Number); | |
const mixing = (file, rounds = 1, key = 1) => { | |
file = file.map(v => v * key).map(d => [d]); | |
const buffer = [...file]; | |
while (rounds--) | |
file.forEach(v => { | |
const i = buffer.indexOf(v); | |
buffer.splice(i, 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
const RE = /Blueprint (\d+): Each ore robot costs (\d+) ore. Each clay robot costs (\d+) ore. Each obsidian robot costs (\d+) ore and (\d+) clay. Each geode robot costs (\d+) ore and (\d+) obsidian./; | |
const parse = input => | |
input | |
.split("\n") | |
.map(line => RE.exec(line)) | |
.map(([, ...num]) => num.map(Number)) | |
.map( | |
([ | |
, |
NewerOlder