Skip to content

Instantly share code, notes, and snippets.

View ablamunits's full-sized avatar

Boris Ablamunits ablamunits

  • Zurich, Switzerland
View GitHub Profile
@ablamunits
ablamunits / day13.ts
Created December 13, 2021 22:48
AoC 2021 Day 13
type FoldInstruction = {
axis: 'x' | 'y';
value: number;
}
type Input = {
points: Map<string, Point>;
foldInstructions: FoldInstruction[];
}
@ablamunits
ablamunits / day12.ts
Created December 12, 2021 20:34
AoC 2021 Day 12
type Node = {
id: string;
}
type GraphMap = Map<string, Set<Node>>;
const parseInput = (input: string): GraphMap => {
let map = new Map<string, Set<Node>>();
const rows = input.trim().split('\n');
export const runNStepsOfSimultation = (grid: Cell[][], n: number): number => {
let flashesCount = 0;
for (let step = 0; step < n; step++) {
const q: Cell[] = [];
// Increase all
grid.forEach((row) => row.forEach(cell => cell.increase()));
// Add naighbours to queue
@ablamunits
ablamunits / day10.ts
Created December 10, 2021 10:54
AoC 2021 Day 10
export const solveP1 = (input: string) => {
const rows = parseInput(input);
const scoreMap = {
')': 3,
']': 57,
'}': 1197,
'>': 25137
};
const parseInput = (input: string): number[][] => {
const rows = input.trim().split('\n');
return rows.reduce((res, rawRow) => {
const nums = rawRow.split('').map(Number);
return [...res, nums];
}, []);
}
export const solveP1 = (input: string) => {
const map = parseInput(input);
@ablamunits
ablamunits / day8.ts
Last active December 8, 2021 21:16
AoC 2021 Day 8 Pt 2.
enum Segment {
Top = 'top',
TopRight = 'top-right',
BottomRight = 'bottom-right',
Bottom = 'bottom',
BottomLeft = 'bottom-left',
TopLeft = 'top-left',
Middle = 'middle',
}