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
type FoldInstruction = { | |
axis: 'x' | 'y'; | |
value: number; | |
} | |
type Input = { | |
points: Map<string, Point>; | |
foldInstructions: FoldInstruction[]; | |
} |
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
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'); |
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
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 |
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
export const solveP1 = (input: string) => { | |
const rows = parseInput(input); | |
const scoreMap = { | |
')': 3, | |
']': 57, | |
'}': 1197, | |
'>': 25137 | |
}; |
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 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); |
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
enum Segment { | |
Top = 'top', | |
TopRight = 'top-right', | |
BottomRight = 'bottom-right', | |
Bottom = 'bottom', | |
BottomLeft = 'bottom-left', | |
TopLeft = 'top-left', | |
Middle = 'middle', | |
} |