Skip to content

Instantly share code, notes, and snippets.

View bluepichu's full-sized avatar

Matthew Savage bluepichu

View GitHub Profile
import { List, Map, Set } from "immutable";
import { Advent, arr } from "advent";
const { compute, computeCheck } = await Advent({ day: 20 });
compute(async (input) => {
// const data = input.tokens(/,/).map(int);
const [alg, imageStr] = input.all().split("\n\n");
let image = imageStr.split("\n").map((c) => c.split(""));
for (let i = 0; i < 50; i++) {
import { List, Map, Set } from "immutable";
import { Advent, int, arr } from "advent";
const { compute, computeCheck } = await Advent({ day: 22 });
interface Cube {
x1: number;
y1: number;
z1: number;
x2: number;
from z3 import *
with open("input.txt") as f:
lines = f.readlines()
iters = []
for i in range(14):
base = i * 18
print(lines[base + 4], lines[base + 5], lines[base + 15])
import { Advent, GridDirectionsWithoutDiagonals } from "advent";
import { Set, Map } from "immutable";
import * as p from "ts-priority-queue";
const { compute, computeCheck } = await Advent({ day: 23 });
interface Entry {
grid: string[][];
cost: number;
}
@bluepichu
bluepichu / aoc22-02.mts
Created December 2, 2022 05:09
aoc22-02.mts
import { Advent, f } from "advent";
const { compute, computeCheck } = await Advent({ day: 2 });
compute(2, async (input) => {
const data = input.parse(f.nl(f.tok(f.str())));
let ans = 0;
for (const [them, us] of data) {
@bluepichu
bluepichu / advent.mts
Created December 2, 2022 05:20
Advent of Code helper library, 2022 edition
import { readFile, writeFile } from "fs/promises";
import { join as pathJoin } from "path";
import fetch from "node-fetch";
import * as readline from "readline";
const readlineInterface = readline.createInterface({ input: process.stdin, output: process.stdout });
const session = (await readFile(pathJoin(process.env.HOME!, ".advent_cookie"))).toString().trim();
export const int = (x: string): number => parseInt(x, 10);
export const num = (x: string): number => parseFloat(x);
import { Advent, f } from "advent";
import { Set } from "immutable";
const { compute, computeCheck } = await Advent({ day: 3 });
// compute(1, async (input) => {
// const data = input.parse(f.nl(f.chrs()));
// let ans = 0;
// for (const line of data) {
import { Advent, arr, f } from "advent";
import { Set, Map } from "immutable";
const { compute, computeCheck } = await Advent({ day: 5 });
compute(2, async (input) => {
const data = input.parse(f.nl(f.str()));
let stacks: string[][] = arr(9, () => []);
for (const line of data.slice(0, 8)) {
import { Advent, f, fm, ord } from "advent";
import { Set, Map } from "immutable";
const { compute, computeCheck } = await Advent({ day: 6 });
compute(2, async (input) => {
const data = input.parse(f.str());
for (let i = 0; i < data.length; i++) {
const slice = data.slice(i, i + 14);
import { Advent, f, fm, chr, ord } from "advent";
import { Set, Map } from "immutable";
const { compute, computeCheck } = await Advent({ day: 7 });
interface Dir {
parent?: Dir;
files: { [name: string]: number };
dirs: { [name: string]: Dir };
}