├── 1 ├── a.ts ├── b.ts └── input.txt ├── 2 ├── a.ts ├── b.ts └── input.txt ├── 3 ├── a.ts ├── b.ts └── input.txt ├── 4 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 5 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 6 ├── a.ts ├── b.ts └── input.txt ├── 7 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 8 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 9 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 10 ├── a.ts ├── b.ts ├── e2.txt ├── example.txt └── input.txt ├── 11 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 12 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 13 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 14 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 15 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 16 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 17 ├── a.ts ├── b.ts ├── example.txt ├── heap.ts └── input.txt ├── 18 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 19 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 20 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 21 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── 22 ├── a.ts ├── b.ts ├── example.txt └── input.txt ├── .gitignore ├── deno.jsonc └── template ├── a.ts ├── b.ts ├── example.txt └── input.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | -------------------------------------------------------------------------------- /1/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt") 2 | .split("\n") 3 | .map((r) => r.split("")); 4 | 5 | let total = 0; 6 | 7 | input.forEach((row) => { 8 | // first number in row 9 | let first = -1; 10 | let last = -1; 11 | row.forEach((char) => { 12 | // check if number 13 | if (char.match(/\d/)) { 14 | last = parseInt(char); 15 | if (first === -1) first = parseInt(char); 16 | } 17 | }); 18 | 19 | total += first * 10 + last; 20 | }); 21 | 22 | console.log("total", total); 23 | -------------------------------------------------------------------------------- /1/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt") 2 | .split("\n") 3 | .map((r) => r.split("")); 4 | 5 | let total = 0; 6 | 7 | const numbersSpelled = [ 8 | "zero", 9 | "one", 10 | "two", 11 | "three", 12 | "four", 13 | "five", 14 | "six", 15 | "seven", 16 | "eight", 17 | "nine", 18 | ]; 19 | 20 | input.forEach((row) => { 21 | // first number in row 22 | let first = -1; 23 | let last = -1; 24 | 25 | let firstSpelled = ""; 26 | 27 | row.forEach((char) => { 28 | // check if number 29 | if (char.match(/\d/)) { 30 | last = parseInt(char); 31 | if (first === -1) first = parseInt(char); 32 | } else { 33 | firstSpelled += char; 34 | for (let i = firstSpelled.length - 1; i >= 0; i--) { 35 | const num = numbersSpelled.indexOf(firstSpelled.slice(i)); 36 | if (num !== -1) { 37 | last = num; 38 | if (first === -1) first = num; 39 | 40 | break; 41 | } 42 | } 43 | } 44 | }); 45 | 46 | total += first * 10 + last; 47 | }); 48 | 49 | console.log("total", total); 50 | -------------------------------------------------------------------------------- /10/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt") 2 | // const input = Deno.readTextFileSync("example.txt") 3 | .split("\n") 4 | .map((r) => r.split("")); 5 | 6 | const startY = input.findIndex((r) => r.includes("S")); 7 | const startX = input[startY].findIndex((c) => c === "S"); 8 | 9 | const visitedPoints = [ 10 | { x: startX, y: startY }, 11 | { x: startX, y: startY - 1 }, 12 | // { x: startX + 1, y: startY }, // for example 13 | ]; 14 | 15 | const step = () => { 16 | const currentPoint = visitedPoints[visitedPoints.length - 1]!; 17 | const prevPoint = visitedPoints[visitedPoints.length - 2]!; 18 | const current = input[currentPoint.y][currentPoint.x]; 19 | 20 | console.log("visiting", currentPoint, current); 21 | 22 | if (current === "|") { 23 | const newY = currentPoint.y + (currentPoint.y - prevPoint.y); 24 | visitedPoints.push({ x: currentPoint.x, y: newY }); 25 | } else if (current === "-") { 26 | const newX = currentPoint.x + (currentPoint.x - prevPoint.x); 27 | visitedPoints.push({ x: newX, y: currentPoint.y }); 28 | } else if (current === "L") { 29 | // down to right or left to up 30 | if (prevPoint.y < currentPoint.y) { 31 | visitedPoints.push({ x: currentPoint.x + 1, y: currentPoint.y }); 32 | } else { 33 | visitedPoints.push({ x: currentPoint.x, y: currentPoint.y - 1 }); 34 | } 35 | } else if (current === "F") { 36 | // up to right or left to down 37 | if (prevPoint.y > currentPoint.y) { 38 | visitedPoints.push({ x: currentPoint.x + 1, y: currentPoint.y }); 39 | } else { 40 | visitedPoints.push({ x: currentPoint.x, y: currentPoint.y + 1 }); 41 | } 42 | } else if (current === "7") { 43 | // up to left or right to down 44 | if (prevPoint.y > currentPoint.y) { 45 | visitedPoints.push({ x: currentPoint.x - 1, y: currentPoint.y }); 46 | } else { 47 | visitedPoints.push({ x: currentPoint.x, y: currentPoint.y + 1 }); 48 | } 49 | } else if (current === "J") { 50 | // down to left or right to up 51 | if (prevPoint.y < currentPoint.y) { 52 | visitedPoints.push({ x: currentPoint.x - 1, y: currentPoint.y }); 53 | } else { 54 | visitedPoints.push({ x: currentPoint.x, y: currentPoint.y - 1 }); 55 | } 56 | } else if (current === "S") { 57 | console.log("WE DID IT", (visitedPoints.length - 1) / 2); 58 | 59 | throw new Error(); 60 | } 61 | }; 62 | 63 | while (true) { 64 | step(); 65 | } 66 | -------------------------------------------------------------------------------- /10/b.ts: -------------------------------------------------------------------------------- 1 | const data = Deno.readTextFileSync("input.txt") 2 | .split("\n") 3 | .map((x) => x.split("")); 4 | 5 | let startPosition: [number, number] = [0, 0]; 6 | 7 | for (let i = 0; i < data.length; i++) { 8 | for (let j = 0; j < data[i].length; j++) { 9 | if (data[i][j] === "S") { 10 | startPosition = [i, j]; 11 | data[i][j] = "7"; 12 | } 13 | } 14 | } 15 | 16 | let count = 0; 17 | let i = startPosition[0]; 18 | let j = startPosition[1]; 19 | let visited = new Set(`${i},${j}`); 20 | let loop = Array.from(new Array(data.length * 2), () => 21 | new Array(data[0].length * 2).fill(false) 22 | ); 23 | 24 | while (true) { 25 | loop[i * 2][j * 2] = true; 26 | const c = data[i][j]; 27 | const up = c == "|" || c == "L" || c == "J"; 28 | const down = c == "|" || c == "7" || c == "F"; 29 | const left = c == "-" || c == "7" || c == "J"; 30 | const right = c == "-" || c == "L" || c == "F"; 31 | 32 | if (up && !visited.has(`${i - 1},${j}`)) { 33 | loop[i * 2 - 1][j * 2] = true; 34 | i--; 35 | visited = visited.add(`${i},${j}`); 36 | count++; 37 | continue; 38 | } 39 | 40 | if (down && !visited.has(`${i + 1},${j}`)) { 41 | loop[i * 2 + 1][j * 2] = true; 42 | i++; 43 | visited = visited.add(`${i},${j}`); 44 | count++; 45 | continue; 46 | } 47 | 48 | if (left && !visited.has(`${i},${j - 1}`)) { 49 | loop[i * 2][j * 2 - 1] = true; 50 | j--; 51 | visited = visited.add(`${i},${j}`); 52 | count++; 53 | continue; 54 | } 55 | 56 | if (right && !visited.has(`${i},${j + 1}`)) { 57 | loop[i * 2][j * 2 + 1] = true; 58 | j++; 59 | visited = visited.add(`${i},${j}`); 60 | count++; 61 | continue; 62 | } 63 | 64 | break; 65 | } 66 | 67 | for (const line of loop) { 68 | console.log(line.map((x) => (x ? "X" : " ")).join("")); 69 | } 70 | 71 | const queue = [[0, 0]]; 72 | 73 | function neighbors([i, j]: [number, number]) { 74 | const result = [ 75 | [i - 1, j], 76 | [i + 1, j], 77 | [i, j - 1], 78 | [i, j + 1], 79 | ]; 80 | 81 | return result; 82 | } 83 | 84 | while (queue.length > 0) { 85 | const [i, j] = queue.shift()!; 86 | for (const pt of neighbors([i, j])) { 87 | const [ii, jj] = pt; 88 | if ( 89 | ii >= 0 && 90 | jj >= 0 && 91 | ii < loop.length && 92 | jj < loop[0].length && 93 | !loop[ii][jj] 94 | ) { 95 | loop[ii][jj] = true; 96 | queue.push([ii, jj]); 97 | } 98 | } 99 | } 100 | 101 | console.log("\n".repeat(20)); 102 | 103 | for (const line of loop) { 104 | console.log(line.map((x) => (x ? "X" : " ")).join("")); 105 | } 106 | 107 | let ans = 0; 108 | 109 | for (let i = 0; i < loop.length; i++) { 110 | for (let j = 0; j < loop[i].length; j++) { 111 | if (!loop[i][j] && i % 2 == 0 && j % 2 == 0) { 112 | ans++; 113 | } 114 | } 115 | } 116 | 117 | console.log("ANSWER", ans); 118 | -------------------------------------------------------------------------------- /10/e2.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .S-------7. 3 | .|F-----7|. 4 | .||.....||. 5 | .||.....||. 6 | .|L-7.F-J|. 7 | .|..|.|..|. 8 | .L--J.L--J. 9 | ........... 10 | -------------------------------------------------------------------------------- /10/example.txt: -------------------------------------------------------------------------------- 1 | -L|F7 2 | 7S-7| 3 | L|7|| 4 | -L-J| 5 | L|-JF -------------------------------------------------------------------------------- /10/input.txt: -------------------------------------------------------------------------------- 1 | F7.-.|.-F777F7.7-|F-7-7J.-J-7-JFFFJ-F--7FJ-|7F-JF|-F.|F-7-F7-L-.FF-|7.--FL-L7-J-FJF-F7F--77..F|.F--7F777|-JJ7FJF---J-L7L-F-LJ7F.|F7JJ-777.-| 2 | 7F||LF7F7L-J7||.|.JL-7LFFJFF7.LFF7|.J7F7JJ|L-JFJFJF--FF7L|.-.|-FJL7|-FJ.-F7J.FJ|LJF.L|J|F-L7.F|FL-7LJ|7FL7|.|-LJ7JJL--FJL77JJLL7.F||7|L|-7JJ 3 | F-J|L|F7|7JLFF7-L-J7.JFJJ.|LJ7||JJF7|J|J-F-7-F7-|FF-FJ||7.|F-L-7-.L.LJJ77LL-7J.|JJL7.|7FF-||||F---JF7L-7J--FJFJ.L7-FJ7L77JLJ.|LLF7.-|-7LL777 4 | 7JF--|.JJF-7.7-7FLF--J||F|.|LF7LJF7LJ.|L.F-FFFL.-|7-||LLJ777LLLLJF77F|-FL|-|L--FJF-F7L-JLFL--LL----J|F-JJ-|F-7L-7|.LF-7F|7-FLL-F|JFL|.|J.|-- 5 | |.|77|.|LJ7F.|-L--7J|F|FF7.F7||-77F77-LJ7|-J-JJ7|L|LJ7LJ|.L77J|F-FJ|L7-J|......|F|7LJJ.FL-7FJ.L|-F7FJL--7F7J.|FLL77F--J--|FF-|F7|F|-|L77F7|7 6 | F7|L-|F|7L-|FJ7-JFJ|L--JJFJJF|7-J|J|-FJF777LL7FF7J|.||-LL.F-7F77J|7F.|.FFL7--L|J|LF7|.FF7LF|F-.LFJLJF7F7|||F77F.L|7|FF|7-LLFJLL-JJJ.JJF77L77 7 | J-||-LJ-|..L-|LFLJ.FFFJFLJJFL||L-JF|7F7||||.LF7.|.|F|JJ|LFL7||L7FJFFJ|-LL-JF|7|L-7L---F-JJ.L7L7-L--7|LJ||||-JF77F-J77FF-7-|J.7FL7|.7--J.L|L7 8 | |7|777LL|-L-7L-J7LFJ-JJL77.-7L|77F||-||||F77LF-7J-LJL-F7FF7|||FJ7.F77FF|J.L-F-|LF--J..|-LFF|F7LF---JL7|LJ|||FJ|F7|FF-7.L77J7.-L-LL7|.|-JJFJJ 9 | L7J.|J|7L-J|F7LL7.FJ7|..F77|JJ||F7F-7||||||F7L7L7.|7|7||FJ|||||.F7|L-7JJL7FLJ7LFFJ.|FF7.|FF7JF7L----7|F7FJL7L7|||F7|FJ7.F7JF7JL-JLJ--F7JF.|J 10 | FJ.F|L-L|.FLJJL|F.||7L-J|LJ|||F7||L7||LJ|||||-L7L7F---J|L7||||L7|LJF-JJ-F|JL|7|LLF7-FJL7F-J|FJ|F-7F-JLJLJF-JFJ|||||||F7F||.JJFJF--7J.LJF---. 11 | |LJJ..LFL77LJ|-7-7-F|.|FF7-F7F|LJL7||L7FJ|||||LL7|L7F--JL|||LJFJL7FJF7JJF77-F7--FJFFJF-JL-7||FJL7|L---7F7L77L7||||LJLJL-J|J--|-|7LF.|.7JFFJF 12 | J||.---FJ|FJ7FJJL|7J|FLFF7||L7|F7FJ|L7||-|||L-7FJL7|L7F7FJLJF-JF-JL7||F7||F7||L|F-FL7|F7F7||||F7||7F--J|L-JF-JLJ||F------J|JLJ.|F7|F-FLF-7.| 13 | F-|7.|.|FJJFF|.F|JL-F7JFJ|FJFJLJ||FL7||L7||L-7||F-J|FJ||L--7L-7L7F7LJ|||||||||--|7F7|||||||||||LJL7L--7L-7-L---7LJ|F--7F7-|J-J.FJFJLLL-JL|7| 14 | J.LL7FFFLJFLLFJ7|F7L||.L7|L7|F7FJL7FJ||FJ|L--J||L-7||FJL7F-JF-J7LJL-7|||||||||7.F7|||||||||||LJF7FJF7L|F-JF---7|F-J|F-J||7JJ.LFJJ|JJLL7J-7.7 15 | L-LJF7F.|7.||JL--.F7||F7|L-J|||L-7|L7LJL7|F---J|F-J|LJF-JL7FJ|F-----J||||LJ||L-7|LJLJ||||||LJF-JLJFJL-JL-7L--7LJ|-FJL-7|L777L.JJJ||F.|.L7L-J 16 | .FJ|L|.F-JF7-F-J|F|LJLJ|L7F7LJ|FFJL7L7F-J|L--7FJL7FJF7L7F7||F7L---7F7LJ||F7LJF-JL---7|||||L7FJF7F7L7F-7F-JF-7L-7|FJF7FJL7|J7JF..FJ7F-FJ7|FJJ 17 | 7..|.JF-7.7JLF||LFJF7F7L-J||F7L7L7FJFJ|F-JF-7|L-7|L7|L-J|LJLJ|F--7LJL-7|||L7FJF7FF7FJ||LJL-JL-JLJL7LJFJL--JFJFFJLJFJLJ7FJL-7JJF|-FL|LF-|J7J| 18 | L77L|.F|L-L--J.L7L-J|||F7FJ||L7L-JL7L7LJF-J7LJF7||FJL-77L7F--JL-7L7LF-JLJL7LJFJL7|LJFJL-----7F---7|F7L7F---J7FJF7FJF7F7|F--J.F7LFL7L77..L7F| 19 | --7F|FLJ|F7||FF7L7-FJ|LJLJ7LJFL---7|F|F-JF7F--JLJ||F--JF7|L-7F--JFJFJF-7F7|F7|F-JL-7|F7F----JL--7LJ||FJ|F7FF7|FJLJ7|LJ||L7F7FJ|7-7|LLJ|JFLJ| 20 | |F7JL7-LF--L77.JJFFL-J.F-7F-7F7F--JL-J|F7||L--7F-J|L7F7|||F-JL--7L7L7L7|||||LJL7J|FJ|||L----7F--JF-J|L7LJL-JLJL7FF7L-7LJFJ|LJFJ.L|-7.F||FFJ| 21 | FL-JL|7LJ7|L-|.FF-7.LL-|FJL7|||L---7F-J|LJL7F-JL7FJFJ|||LJ|F77F-JFJJ|FJLJLJL--7L7FJFJ||F7F--JL--7L-7L-JF---7F--JFJ|JFJF7L7|F-J..|LL.F7L-J|L- 22 | FLJ7.FJ7|-F-J|F-L7L77LFJ|F-JLJL7F--JL--JF--JL--7|L7L7|||F7||L7|F7L7FJL--7F---7|FJL7|J||||L--7F-7L7JL--7L--7LJ.F-JFJFJFJL-J|L--77L7.FFJ|FLJFJ 23 | .LFJF|-F7FL-7|7L||FJF7L7|L----7|L---7F--JF-7F-7||FJFJ||||LJ|FJLJL7LJF---JL--7LJ|F7||FJ||L-7FJ|LL7L--7L|F--JJF7|F-J|L7L--7FJF--J7-LJ7J|FL7F7| 24 | FF7|L-7|LJ7L7J|7FJL7||FJ|F7-F7||F7F-JL-7FJFJL7LJLJFJFJ|||F7||F7F7L-7L--7F7F-JF7||||||FJ|F-JL7L7FL-7FJFJ|F7.FJ|||F-7FJF--J|FJF--7JJL-J7|-LJL| 25 | ||LFJLLF7LF-F--7|F7LJ|L7LJ|FJ|||||L-7F-J|FJF7L---7|7L7||LJ|||||||F-JF--J||L--J|||LJLJ|F||F--JFJF7FLJ.L7|||FJFJ|||FJL7L--7|L-JF-J.FJL|LFF--7J 26 | |J-L7.LLLFF7|F-JLJL-7L7L-7|L7LJ|||F7||-FJ|FJ|LF7FJ|F-JLJF-J|LJLJ|L-7|F7.||-F--J|L---7|FJ||F7FJF||F-7F-J|||L7L-JLJL-7|F--J|F--J7L7LJ.L.JL--7| 27 | 7J-|7|.LLFJLJ|7F7.F7L7|F7|L7L-7LJLJ||L7|FJ|FJFJ||FJL-7F-JF7L---7|F7|LJL-JL7L--7L7F7FJLJFJLJ|L-7|LJFJL-7LJ|J|F7F--7FJ|L---JL-7F77.||F|..|J.LL 28 | LJFFFLJ-FL--7L-JL-JL-J||||FJF7L---7||FJ|L7|L7|FJ|L---J|F7|L7F-7|LJLJF-7F--JF7LL7LJLJF--JF7FJF7|L7FJF-7L-7L7||LJF7||FJF---7F7LJL7-L--|7|7--.J 29 | F7-777L-LLF7L------7F7|||||FJL7F--J||L7|FJL7LJ|FJF----J|LJFJL7|L7F-7||LJJF7||F7|F--7L-7||||FJLJFJL7L7|F7L7||L-7||LJL7|.F7LJL---J..|JLJ---J|J 30 | -J7L|F7F|J|L7JF--7LLJ|LJLJ|L-7|L--7||FJ|L7FJF-JL7|LF7F7|F-JJFJ|FJL7LJF7F7||||||LJF-JF-JFJ||L--7L-7L7|||L7|LJF-J|L7F7|L-JL-----7F7FF-77J.J-|. 31 | .-J7FJLLJFL7L7L-7|F77L7F-7L-7|L7F-J||L7L7|L7L7F-JL-J||LJL--7L7|L7FJF7|||||LJ||L7FJF-JF7L7LJF--JF7L7|||L7LJF-JJFJFJ|LJF7F------J|L-JFJ77-JLFF 32 | F7LL7-LJ.F-JFJF-J||L7-LJ7L7FJL7||F7LJFJFJ|FJFJL---7FJ|F--7FJFJ|FJL-J||LJ|L7FJ|FJL7L7|||LL7FJF7FJL-J|||FJF7|LF7L7L7|F7|LJJF-----JF7FJJLFJ.F|. 33 | 7J.L|.|.L|F7L7L-7LJFJF--7FJ|F-J|LJL-7L7L7|L7|F7F-7|L7LJF-JL7L7|L7F7FJ|F-JFJL7||F7|FJFJL7FJ|FJ|L---7||LJFJLJFJL7L7|||LJF--JF7F---JLJF7JL--F|7 34 | J7L-J-7|LLJL7|F7|F7L7L-7|L7|L-7L7F--JFJFJ|FJ||||FJL7L7.L--7|FJ|FJ|LJFJL-7L-7|||||||FJF-JL7||FJF7F-J|L-7|F7F|F-JFJLJL7-|F--JLJF--7F7-|7.FL7.J 35 | FF-FJL7JJF--JLJ||||FJF-J|FJ|F7L7||F-7|FL7|L7|||||F7|FJF7F7||L7||FJF7L7F-JF7||||||||L7|7F7||||F||L7FJF7|||L7|L7FJF--7L-JL-----JF7LJL-7----77. 36 | L-7.--||FL--7F7|LJ|L7L-7|L7|||FJ|LJFJL--J|FJ||||||||L7||||||FJ||L7||FJL7FJ||||||||L7||FJ||LJ|FJ|FJL7|||||FJL7||FJF7L7F7F-7F-7FJL7F7FJ-L-J|-- 37 | FJLJFF--7F-7LJ||F7|FJF7||||LJ|L7|F7L---7FJ|FJ|||LJ||FJ|||||||FJL7|||L7FJ|-|||||||L7||||FJ|F-JL7||LFJ|||||L-7|LJL-J|LLJ|L7||JLJ-FLJLJJJJ-FJ.| 38 | 7JF.LL7FJL7L--JLJLJL-JLJL-JF7L7|LJ|F---JL-JL7||L-7||L7||||||||F7||||FJL7L7||||LJ|FJ||LJ|FJL-7FJ|L7L-J||||F7LJF-7F7L--7L-JLJF--7F-7J|.|7|||FJ 39 | LL|J.|||J7L7F-7F-----7F7F7FJL7|L-7|L------7J||L7FJ|L7||LJ|||||||||||L-7L7|||||F-JL7|L-7||F--JL7L7|F--J||||L-7L7||L-7FJF--7FJF-J|FJ7L--F7F-7| 40 | --FJFFJL7F7LJLLJF77F-J|||||F-JL--JL-7F7F7FJFJL7LJFJFJ||F-J|||||||||L--J-||||||L7F-J|F-JLJL---7L7LJL--7|LJL-7|FJ|L-7|L7|F-JL7|F-JL-77J.L|7FL- 41 | LFL7-L-7|||F7FF-JL-JF7|LJLJL7F7F7F-7||LJ||FJF7L7LL7L7||L7FJ|||||||L7FF7FJ|||||FJL-7|L7.F7F7F-JFJF----J|F---J|L7L--JL-J||.F7|LJF7F-JJLFL|-7LJ 42 | LLJ|.|L||||||FJF----J|L7F---J|||||L||L-7||L7|L7L-7|FJ||FJ|FJ|LJ||L7L-J|L7|||LJL-7FJL7L7|LJLJF7L7L-7F-7|L---7L7L-7F7F7FJL7|||F-J|L7F7.7-7-L.. 43 | FL-LFF-JLJLJLJFJLF---JFJL--7FJ||||FJ|F7|LJFJL7L7FJ|L7|||FJ|FJF-JL7|F-7L7LJ|L--7FJL7F|FJL7F-7|L7L-7LJFJ|F---JJL-7LJ|||L7FJ|LJL-7L-J||F7.F7LL| 44 | FLFJLL--7F7F7FJF-JF-7FJF--7LJ-LJLJL7LJLJF7|F-JJ|L7L7|LJ||FJL7L7F7|LJ|L7|F-JF--JL-7L7|L-7LJJ||.L--JF7L-J|F--7F-7L--J|L-JL-JF7F7L7F-JLJ|.L-7FJ 45 | F.L7|.|LLJLJLJLL--JFJ|-L-7L--7|F7F7L---7||LJF--JFJL||F-J|L7FJFJ||L-7F7|||F7L----7|FJL--J.F-J|F----JL-7.LJF-JL7L----JF7F7F-JLJL7LJF-7FJ-JJ|F| 46 | -.L|77J7F--------7|L-JF7LL--7L7|LJL----J||F7L--7|F7LJL-7L7LJ-L7||F-J|LJ||||F-7F7||L----7FJF7|L7F----7L7F-J|F7|F---7FJLJ|L----7|F-JL||J7F|F-- 47 | L-F7J-JFL-------7L----J|F--7L7|L--------JLJL7F-JLJL-7F-JFJF7F7|||L-7L7FJ||||FJ||||F-7F7|L7|LJFJ|F---JFJL---JLJL7F7LJF7FJF----J|L7J7LJ|.|-|-| 48 | LJ||-JJL|F------JF7F-7FJL7FJJ|L7F-----7F7F-7||F7F---J|F7|FJ|||||L-7L7|L7||||L7|||||FLJ|L7||F7L-JL---7|LF----7F7LJ|F7||L-JF---7|FJ-F7||7J.-FJ 49 | F|L-7.FF7L--7F--7|LJFJL7J||LFJFJL----7LJLJLLJ|||L---7LJ||L7LJLJL-7L-J|FJ||LJFJ||||L-7||FJLJ||LF-----JL7L---7LJL--J||||F7FJF7FJ|L-77-7LL7L..F 50 | L|J||L-LF---J|F7LJ-FJF7L-JL7L7|F7F--7L---7F--J||F7F-JF-J|-L---7F-JF-7||FJL7FL7||||F7L7LJF7FJL-JF-7F7F7L----JJF7JF7|LJLJLJFJ|L7L--JJF7-||-|7L 51 | L|-|-JJ|L-7F7||L---JFJL7F-7L-JLJ|L-7|F---JL7F7||||L-7|F7L7.F--JL-7|FJLJ|F7L-7LJ|||||FJFFJ|L--7FJ.LJ|||F7F----JL7|LJF-----JFL-JJF7LF-7-LL7.JJ 52 | FJLF7|-|JL|||||F--7FJ-F||-L--7F7L--J|L7F--7LJLJ|||F7||||FJFJF-7F7LJL--7|||F7|F-J|LJ||F7L7|.F-J|F7F-J|||LJF----7||F7L----7F7FF--JL7L7|J7L-7L7 53 | FJF.LJFJLFJ|LJLJF7LJ||FJ|F---J||F--7L-J|F-J|F-7||||LJ||LJ7L7|FJ||F-7F-J||||LJL7FJF-JLJ|FJL-JF-J||L7FJLJFFJF--7LJ||L--7F7LJL7L7F--J-||.|-.L7J 54 | |-F-|||.FL7|F-7||L7FF-JFJL7F--JLJF-JLF7|L---JFJLJ|L-7|L7LF7LJ|FJ|L7|L7LLJ|||F-J|FJF7F7||F---J7FJL-J|F7F7L-JF7L--JL-7-LJ|F-7L-JL7F--JL-7J7|L7 55 | |.|LFF|7FLLJL7L7L7L7L--JF-J|F----JF--JLJF----J|F7|F7|L7L7|L--JL7|FJL7L--7LJ-L-7||FJ||||||F----JF7F7||LJL--7||F--7F7L--7|L7L---7LJF----J.F-JF 56 | F-|FFJF-L7F||L7L-JFJF--7L--JL7F---JF-7F-JF7F7F-J|LJLJ||FJL---7FJ|L7.|F--JJ|JFFJ|LJFJ|LJLJL-----JLJLJL----7|||L7|LJL-7FJL7L---7|F-JJ7LLJ-JF-7 57 | F7|J..J.F7J|FFJF-7L-JF7L--7J|LJF7F7L7|L--JLJLJF-JF--7FJL7LF--JL7L7|FJL-7F-7-FJFJF7L7|7||.F---------------JLJL7L-7LF7LJJJL----JLJF--7-|7.L7J. 58 | L|L||-LF-.|FFL7|FJF7FJ|F-7L7F--JLJL-JL-------7L--JF7|L-7L7|F-7FJJ||L7F7LJFJ-|FJFJL-JL7JJ7L--7F---------7F---7|F-JFJL7JLF7FF---7FJF7|FF-7FLL7 59 | LJ.FJF7JL|-F77LJL-JLJLLJLL7|L---------------7L7F7FJ|||FJFJ|L7|L7-LJFJ||F-JLLLJJL-7F7FJJ|F7F7LJF7F7JF--7LJF7FJLJF-JF7L7FJL-JF-7LJFJ||-J7L|.|| 60 | FLF-7LL--F-JL-------------J|F7F-------------JJLJ|L7|L7L7|J|FJL7L--7|FJ|L777|-L7F|LJ||LF-JLJL--JLJL7L-7L--JLJF7F|F-J|FJ|F---JJL--J.LJJF7.J-J- 61 | |J|L||FJ.L-7F--------7F-7F7LJ|L-------7F----7F-7L-JL7|-||FJ||L|F7FJLJFL-J7-L.F|L-F-JL7L---------7FJF7L----7J|L-JL-7|L-J|F-------7F7-|L|-L7.J 62 | 777LL7-F-JFJ|F7F-----JL7LJL-7L--------J|F---J|FJF7F7LJFJ|L7L7FJ||L7..7|L|L7--J7.F|F-7|-F7F-7F---JL-JL7F---JFJF7F-7||F-7||F--7F--J||F7L7-F..| 63 | LL7-F|.L-LL-J||L-------JF--7|F---7F7F7FJL7F--JL-JLJL77L-J.|FJL7||FJ..F7L|7LF-LF--LJ-LJFJ|L7|L-----7F7LJF---JFJ|L7LJ||FJLJL-7LJF--JL-77|-LFF| 64 | FF7F7J||||.F-JL---7F7F7FL-7LJ|F--J|LJLJF-J|F-7F7F--7L-7F-7LJLFJ|||J.F|-7J|.77-LJ||J-LFJFJF|||F7JF-J||F-JF---J|L-JF7LJL----7L7JL7F---J-J.LF77 65 | F-J||F-J7L-L-7F7F7LJLJL---JF7|L---JF7F-JF7|L7LJLJF7L-7||FJ||FL7|LJJ.LJLJJ7FLJ77L|JJFFL7L7FJL-JL-JF7|LJF7L--------JL-----7-L-JF7|||F-7JJ-F-7L 66 | FJ-7|J-LF-7|FLJLJL7F7F7F7F7|LJF----JLJF-JLJFJF7F7|L7LLJ|L-7J|-||-JL7-FFJFLJ|.FJ7JJF7J-L7LJF-7F-7FJ||F-JL--7F7F-------7F7L----JLJL-JFJJJFLLL| 67 | F||LJJ|LL-|7F-----J|LJLJLJLJF7L7F---77|F---JFJLJLJFJF7F|F-J-|-||-LLL7JL77|.-L--LFF--7F7L--JJLJLLJFJ|L-7F-7LJLJF7F---7LJ|F7F7F------JJJ.|7-L| 68 | .L|JJFL7|F-FL---7F7|F-7F7F--JL-J|F--JFJL7F77L7F--7|FJL7||F7J.LLJ--7||-7L-7-|.J.LLL-7LJL--7LF-7FF7L7|F7LJ-L----JLJF--JF-J|LJ|L---7F7F7.F|JLFJ 69 | LLL.|LJ-L-FF7FF7LJLJL7||LJF--7F-JL---JF-J|L7FJL7.LJ|F-J|LJL7-7FLJ7|-|.L-||-JFL|LL|LL-7F-7L-JFJFJL7LJ||F7F----7F--JLF7L-7L-7|F-7FJ|LJL7L|FL7J 70 | F|7FL-FF7L-|L-J|7F-7FJLJF7|F7LJ7F-----JF7|FJ|F-JF7FJL--JF7FJ.FF-J|FF-7F-7J||7JLF-F---JL7L--7L7L-7|F7|LJ|L-7F7LJLF--JL-7|F7|||FJL-JF7FJ.F-JJ| 71 | L|-7..F-|7FL--7L7L7|L---JLJ||F--JF-----JLJL-JL-7|||F----JLJ|7FFJ7FF-L7JFL.FL.F7LLL--7F-JF--JFJF7||||L-7L7FJ|L7F7L7F---JLJLJ|||F7F-JLJL|.L-77 72 | L|.FJ-L.|JFF7JL7L-J|F--7F7FJ|L---JF------7F----J|||L---7F----7|F7J-L-JF--F.L--F-----JL-7L--7L-J||LJ|F7L7|L-JFJ|L-JL----7F7LLJLJ|L--7JF|FFJLJ 73 | ||LLJ-LFF7F||F7L--7|L-7LJ|L7|FF7F7L77F7F7LJ7F7F7||L7F-7LJF---JF-7J7.|L|7L7F-7LL--7F----JJF7|F-7|L-7LJL7|L---JFJF7F7F---S||F7F-7L7F-J.FJJ|J.. 74 | --|L7-F7||FJ||L-7FJ|F7L-7L-J|FJLJL7L7|||L---JLJ||L-JL7L--JFF7||FJ-FF7.LF7|7.-JJ.L||F-----J|LJFJ|F7L--7|L-----JFJ|||L---7|||||FJJ|L--7L||-FJ7 75 | L-7FLFJLJ||FJL-7|L7|||F7|F-7LJF--7L-J|||F-----7LJF7F7L-7F7FJL7||-F7||-LL|-FFJJLF-LJL-7F--7L-7L7|||LF-JL-------JFLJ|F7F7||||||L-7|F--J-|J|JF- 76 | F|L-JL7F7LJL-7FJL-JLJLJLJL7L7FJF7L---JLJL----7L7FJ|||F-J||L-7LJL7|LJL7-LFJ.7JJ.L.F7F7LJF7L-7|J|LJL-JF-------7F7F7FLJLJLJ|LJLJF-J||J|J7LL|FJ7 77 | |-7LF-|||F--7LJF7F7F7F7F--JFLJFJL------------JJLJFJ||L--JL--JF7FJL7F-J-7|-F7-F7LF|LJ|F-JL-7|L-JF7F7FJF7F---7LJLJL----7F7|F7F7L-7LJ-|7LF7JF7| 78 | .FJ7L7||LJF-JF7|LJ||LJ||F-7F7FJF7F--------------7L-JL7F---7F-JLJ-FJL7J7FJJ||.J7.LL-7LJF--7LJF7FJ||||FJLJF77L7F7F7F-7FJ||||LJ|F7|JFLJF|JL7|77 79 | F-FJLLLJF-JF7|||F-J|F7LJL7|||L7|LJF----7F-------JF--7|L--7LJF-7F7L7FJ-|LJ-|L7-FF-7-L7FJFFJF7|||FJ|LJL7F7||F7LJLJ|L7|L-JLJL-7||LJJLF7-|7.JJF7 80 | J7FJ7JF-JF7|LJLJL--J||F7FJLJL7LJF7L---7||F-----7FJF7|L7F7L--JFJ|L-JL-7F77FJFJF7L7|.L||F-JFJ|||||FJLF-J|||LJL---7L-J|F-7F-7FJ|L7J7-L7.L--|J|| 81 | LF7--FL-7|||F-7F7F--JLJLJF7F7L--JL--7FJ|LJF7F-7LJFJ|L7LJ|F-7FJ|L-7F--J||FJFJ-||FJL7|LJL-7L7LJLJLJF7L-7|LJF7F---J-F7LJL|L7LJ|L-JJ||J.-|-LJL-. 82 | LLJ-JLL|LJLJL7LJ|L---7F7FJLJL7F--7F7LJJL--JLJLL7FJFL7L-7LJL||F7LFJ||F7|LJFJF7|LJF-JF7F--JFJLF----J|F7||F-JLJF7F7FJL--7L7L7F7F7.LF|LJ|.|||-LF 83 | --LJ|.-F-7F7FL-7L--7LLJLJFF-7||F-J|L7F--7F----7|L--7|F-JFF7LJ||FJFJFJ|L-7|FJ||F-J-FJ|L--7|F-JF---7|||LJL----JLJLJF7F7L7L7LJLJ|7-7L7.-FJ-|.F- 84 | .LJ.|.LL7LJL---JF-7L-----7L7|LJL--JFJ|F-J|F7F7|L-7FJLJF7FJ|F7||L7L7L7L7-||L7||L7JLL7|F7JLJL--JF7FJ|||-F7F------7FJLJ|FJLL7F-7L7.|LJ-|JF7JF-7 85 | 7.FJ.7JL|F-7F-7FJLL-----7L-JL7|F--7L-JL7L||LJLJF7LJLF7|||FJ||||F|FJFJFJFJ|FJ|L7L7F7|||L77F7F7F||L7LJL7||L-----7LJF-7|L-7FJL7|FJ7||F7|FJ|7J-L 86 | LFJ.LLJ.LJF||FJL7F------JF--7L7L-7|F7F7L-JL7|F-JL--7||||||FJ||L7|L7L7L7L7|L7|FJFJ||||L7|FJLJL-J|JL7F7LJL------JF7|FJL-7||F-JLJF7F77L||LJ7F7. 87 | -JL|FJF-F-7LJL--JL--7F--7|F7L7L-7|LJLJL7F-7L7L-7F--J|LJ|||L7||FJ|FJFJFJFJ|FJ|L7L7||||FJ|L-7F7F7|F7LJL---------7|LJL--7LJLJLF77||-LF7F7.L7-F7 88 | FFFL|.J.L7|F7F7F7F-7LJF7LJ|L7L-7|L----7||FJFJF7||F-7|F-J|L7|||L7|L7L7L7L7||FJFJFJ||||L7L-7LJLJ||||F7F--------7LJF-7F-JF7F-7|L7||-F|LJL7.JF|7 89 | FFL-77.FFJLJ||LJ||FJF-JL--JFJF7||F---7|||L7L-J|||L7LJL-7L7LJ||FJ|FJ7L7|L|||L-JFJJ|LJL7|F-JF---JLJLJLJF-7F7F-7L7FJFLJF-J|L7||FJ||F7|F--J7L-77 90 | FLJ-|7-FJF-7|L-7LJL7L-----7|FJLJ|L--7LJ|L7L7F-J||FJF7F-JFL-7||L7|L7F7||FJ||F--JF7L--7|||F7L----------J|LJLJFJ|LJF7F7L-7L-J||L-JLJLJL7J.--LF- 91 | |-|7|L-L-J-||F7L-7FJF-7F--JLJF-7L---JF7L-JFJL--JLJFJLJF7F-7|||FJ|FJ|LJ|L7|||F--J|F-7|LJLJL7F-----7F--------JLF--J|||F-JF--JL7F------J77J-|FJ 92 | 7.-7|-L||F-JLJ|F-JL7L7|L--7F7L7L7F---JL7F7L--7F-7FJF7L|LJFJ|LJL7|L7L-7|FJ||LJF--JL7||F---7|L----7LJF7F-------JF--J||L7FJF7F7||F-------7---|. 93 | LJ7|J7.LLL-7F7LJF-7L-JL---J|L7|FJ|F----J||F-7||FJL7|L7L-7L7|F-7||FJJFJ||FJL7FJ.F-7|||L7F7LJF7F77L--J||F-------JF7|||FJL-JLJ||||F-7F---J--||F 94 | |LL|J7F7.F-J||F-J7L-------7L7LJL-JL-----JLJFJLJL--J|FJF7|FJ|L7LJ|||FJFJ|L7FJ|F7L7|||L7||L7FJLJ|F7F7FJ|L7F7F----J|FJ||F-----J|LJL7LJ.L|LFFJ77 95 | F7|LFL7L-L-7|LJF----------JFJF--7F-------7FJF-7F-7FJL7|||L-JFJF-J|FJFJFJFJL7|||FJ||L7|||FJ|F--J|LJLJFJ-LJLJF----J|FJ|L----7L|F--JJF7L7.F7.|. 96 | 7L7-FF-JJLJ||F-JF-7F7F7F7F7L7L-7|L------7LJ7|FJ|FJL7FJ|LJF-7L7L7FJ|FJFJFJ|FJLJ||FJL7||||L-JL7F7L----JF-7F-7|F7F7FJ|||F----JFJ|F7F7|L--7|J.|J 97 | |.L7FJ.F777LJL--J.LJ||||LJL7|F-J|-F-----JF7FJ|FJL7FJL7L-7L7L-JFJL-JL7|FJF7|F--J|L7FJLJ|L-7F-J||JF7F7LL7|L7LJ|||LJFJFJL-77F7L7||LJLJF--J7.FJJ 98 | F7||L-J-L--F-----7F7LJLJF7JLJ|F7L7L---7F-J||FJL-7|L7FJ7FJFJF-7|F--7FJ|L7||||LF7|FJL--7L7|||F-J|FJ|||F-JL-JF-JLJF7|FJF--JFJL-JLJF-7FJF---7LF7 99 | L--7FL|7.|FL--7F7LJL7F7FJL-7FJ|L7L--7FJL7FJ||LF7||F|L7FJFJFJFJLJF7||FJFJ|||L7|LJL7|F7|FJFJLJF-JL7|||L--7F-JF7F7|LJL7L7F7|F----7L7|L-JF-7|LLJ 100 | L|F7JL7-F-7J||LJ|F-7LJLJF7FJL-JFL7F7|L7J||FJL7|LJ|FJFJL7L7L7||F-JLJLJFJFJ||FJ|F--JFJ||L-JF7FJF7FJLJL7F7LJF-JLJ||F7-L7LJLJL---7|FJ|F-7||LJ-LF 101 | FF-7L-JLL7|F7F7FJ|L|F---J||F--7F7LJ|L-JFJ||F-JL-7|L7L7||FJFJL7L----7FJFJFJ||FJL7F7L7|L7F-JLJFJ|L-7F-J|L--JF-7FLJ|L7FJF7F7F--7||L7|L7|L7JJ7-J 102 | F|JL7J|-FJLJ|||L-JFJ|F-7FJLJF7LJL-7L7F7|FJ||F7FFJL7L7|FJ|FJF-JF-7F-J|LL7|FJ||F-J||FJ|FJ|F-77L7L7FJL-7|F---JFJF7-|FJL7|LJ|L7FLJL-JL-JL-J.|.|. 103 | LL77-F7.|F-7LJL7F7L-JL7LJF-7||F7F7L-J|LJL7|||L7L-7|L|||FJ|FJ-FJFJL7FJF7||L7LJL-7||L7||FJ|FJF7|FJL-7FJLJF---JFJL-JL--JL-7L-JF7FF7F7F7F7F7LFLJ 104 | .FL.FJJ-LJJL7F7LJL7|F7|F7L7||LJLJL--7|F7FJ|||FJF-JL7|||L7||F7L7|F7|L7|LJL7L-7F-J|L7||||FJ|FJ|||F-7|L7F7L----JF-7F7F----JF--JL-JLJLJLJLJ|F7|. 105 | -7-LLJJ.|J.L||L--7L-JLJ|L-JLJF7F----JLJ||.|||||L--7||||FJ||||F|||||FJ|F--JF7||F7|FJ|||||FJL7|||L7||FJ||F7F7F7L7LJ|L-----JF7F--7F-7F7F--J|L77 106 | |F7-|JJF|.LLLJ|F7|F7F-7|7F---J||F-7F7F-JL7||||F7F7||||||FJ|||FJ|||||FJ|F-7|||||||L7|||||L7FJLJL7||||FJ||LJLJL7L-7L-7F--7FJ|L-7|L7|||L---JFJ7 107 | JLJ--7FFF.|JF--J|LJ|L7||FJF--7LJ|FJ|||F--J||||||||||||||L7||LJ-||LJLJ-LJ7||||||||FJ|||||FJL--7FJ|LJ||FJL--7F-JF7L-7||F7LJF|F-JL7|LJ|F-7F-JJJ 108 | |..|JL7|LF7FJF-7L--JFJ||L7|F-JF-J|FJLJ|F-7|LJ||||||||LJL7|LJF--JL----7F--J|||LJ||L7|LJLJL7F7FJL7|F-J||F---JL7FJ|F7||LJL--7||LF7||F7LJFJL7.|J 109 | L|J.LFLJJ.FJFJFJF---JFJ|FJ||F7|F-JL-7FJ|FJL7FJ|||LJ||F7FJL7FJF7F7F7F-J|F-7|||F-J|FJL--7.FJ||L7-||L-7||L----7LJ.LJ|||F7F--J|L-J||||||LL-7|7|7 110 | F-F-7|-JFFL7L7L7|F-7.L7|L-J||LJL-7F7|L7|L-7|L7||L-7|||LJF7||FJ||LJ|L-7LJ|||||L-7||F7F7|FJFJ|FJFJL77LJ|F7F-7L-7F7FJ|LJ|L--7|F7FJ|LJL7LLFJ|-L- 111 | F.JFJ||7FFFJFJFLJL7L-7|||F-JL7F--J|LJFJL-7|L7|||F-J||L7FJ||||FJL7FJF7L7F7||||F-J||||||||FJFJL7L7FJF-7LJ|L7|F7LJ|L7L-7|F7FJ||||7L---J77|FJ||| 112 | J7J|LJ7-|JL-JF7F7J|F-JLJFJF7FJL--7|F-JF7FJ|FJ|||L-7LJJ||FLJ||L7FJL7|L7LJ|||LJL7FJ||||||||FJF7|FJL7L7L--JFJ|||F-J-L7FJ||LJJLJ|L7JF-7L|FLJJ-L7 113 | |7.L-7|.LFJ7FJLJL-J|F77FJFJ||F7F-J|L7FJ||||L7LJL7FJ-F-J|F7FJ|FJL7FJL7|F7||L7F7||JLJ||||||L7||||F7L7L7F7FJFJ||L---7|L7||F77F7L-JFJFJ-7FLJ7L|| 114 | F7-|JL7-F.|-|F--7F7LJ|FJFJ-LJ|LJF7L7||FJL7|FJF--JL7FJF7LJ|L7||F-J|F7||||||FJ|LJL--7||||||FJ|||||L7|FJ||L7L7|L7F-7||FJ|LJL-J|F--JFJF|JL7FJFL7 115 | |J7LJL|7L-LFLJLFJ|L-7LJFJF--7L--J|FJLJL--J|L7L-7F7|L7||F-JL|||L7FJ|||||||||FJF7F7FJ||||LJL7||||L7||L-JL7L7|L7|L7|||L7L--7F7LJF--J-|JL|7L-JL| 116 | F-J7.FJ-FJLLJF-JFJ-FJF7L7L-7|F7F7|L----77FJFJF-J|||.LJ|L-7FJ||FJ|FJ||LJ||||L7|LJLJJ|||L--7||||L7||L7LF7|FJ|FJ|FJ||L7L--7LJL-7L----7J7.|F7--J 117 | 7J.F.|||L--J-L7FJF-JFJL7L7FJLJLJLJF-7F-JFJFJ7L-7|||F--JF7|L-J||J||FJ|F7||||FJL7F---J||F7FJLJ||FJ|L7L7|LJL7LJ-||.LJ||F-7L---7|F----JJF-LL..F| 118 | .FF|FLL777L|7L|L7L-7L-7|FJL----7F7L7|L-7L-JF7F7|||||F7FJ|L-7FJL7LJL7LJ|LJ|||F-JL---7|||LJF-7LJL7L7L7||F7FJF--JL-7F-J|FJF7F-J|L-7J..||F-J77F| 119 | -7.|--.FL--7F-|FJF-JF-JLJ|F7F--J|L7||F7L7F-JLJLJ||||||L7L7FJ|F7|FF-JF-JFFJ|||F----7|||L--JFJ-F-JFJ-LJ|||L7L7F7F7|L-7||FJ|L-7|F-J.|7F-|-|F-FL 120 | .F.J.|F|F|.L--||LL-7|F7F--JLJF7FJFJ||||FJ|F-7F7FJ|||||FJ-LJFJ||L7L-7|F-7|FJ||L7F-7LJ|L7F-7L-7L7FJF7LFJ|L7|FJ|||LJF7||LJFJF7|LJJJ-|F7||7|7-7. 121 | -J.F7--|--7.LJLJ-F-JLJ|L--7F7|LJ-|FJ|||L7||FJ||L7||||LJF--7L7||FJF-JLJFJ|L7||J||F|F7L7|L7L--J||L7||FJFJ7||L7||L7FJLJ|F7L-J||LLJLLL7J7L-JL.F. 122 | |-F-7.LJ|.F||F-LJL-7F-JF--J|||JF-J|||||FJLJL7|L-J|||L--JF-JF||||FJF7F7|-L7|||FJL7||L7|L7L--7F7L-J|LJFJF-JL7||L-JL7F7LJL-7JLJ.L7J.|L||J-F|JJ. 123 | F-JFJ-JFLL7LLJFLF--J|F7L--7|LJFJF7L7|||L7F--JL-7FJ||F-7FJF--J|LJL7||||L-7LJLJL7FJLJF|L7|F-7LJL--7L7FJ|L7F7||L-7||LJ|F-7FJLL-7.JJL--J7--JJ..7 124 | J77|J-J7|.-.|FLJL---J|L---J|F-JFJ|FJ||L7||F-7F-J|FJ|L7LJ-L--7|F--J||||F7L7F7F7||F7F7L7||L7L7F7F-JFJ|F--J||||F7L7F--J|FJL7J|7|F|F|J.FF7||F-FJ 125 | J-|J.||-FJ-FJ--|FLF7F|F7F-7||F7|FJL7|L7LJ||FJ|F-J|7L7L-7F---J|L7F-J||LJL7LJLJ||||LJL-J||FJJ|||L-7L7|L7F-J||LJL7|L-7FJ|F7|LLL7-77L7--J7|-J..| 126 | JF|FJ-7FL7F.F|.77F|L7LJ||J||LJ||L7FJ|FJ.FJ|L-J|F7L-7|F-JL7F-7L7||F-JL--7|F-7FJ||L7F-7FJ||F7LJ|F-JFJL7||F-JL--7LJ7FJ|FJ|LJ7LFJ7L-7|-7LJLF.7.- 127 | LFF|JLJ-JLJ7LLF-F-L7L--JL7|L7.||FJ|-|L-7L-JF--J|L7FJLJJ7L||FJFJLJ|F7F-7|LJL|L7LJ-||FJL7|LJL77|L-7L--JLJL-7F-7L7F-L-J|FJJFJ7LJ|7FF||L-|7|FJL7 128 | F-JL7.|J.F|-.L|.|.L|F7F7FJL7L7||L7|FJF-JJJFJF-7L7|L----7J||L7|F--J|||FJL7JJL7L7JJLJL7FJ|F7FJFJF7||F-7F---JL7L7L7.LL-LJJ|7-|7-LJL7.F|J.L|L-7| 129 | |J.|.7-..|J7L--JLFJ||||LJF-JFJLJFLJL7L--7-L-JLL-JL-7F7FJ-LJ-LJL--7|LJ|F7|F--L-J-FF--JL7||LJ-L7|LJ-L7LJF7F-7|.L-J7JJ|LLFLJL|F-77J.-7F-7-L7J|J 130 | 7JFLJ-7FJ--JJJ.|7.-LJ|L7-L-7|JL|77F-JF7FJ7F|7J|.F--J||L77.|.FF7F-J|F7LJ|L7LF|7J|JL-7F-J|L-7J.LJLLJLL-7|LJFJL7JLJJ.LJ-F||F-F|.J7FL.|7F-.|FJL| 131 | |--JJFJ|-L-7|FFF7-FJ.L-JJ.LLJ7-L--|F7|LJ.-J|F-|-|F--JL-JJF7.FJLJF7LJL-7|FJ||JL777.FJL-7L-7|FFJ|JLLF|LLJ|FL-7L7|-FLF-F7.F|7F77FF7J7||7|-L-.F7 132 | -7-|.L--J7-|--LL-7|FFLJF77L|F|-L|F|||L7|.|FFL7LFLJ7JF|LL-LLFL--7|L-7F-JLJJJL7.|JJFL7F-JJLLJJ|LL77LL7F|FL7LF|FJJFL7|-FJL|J-JJLL-LJF7J-FF7L|7. 133 | L|.7-7FJ-J--7LJ-FLJJ-.FJL77.|.FFL-LJ|FJ7-LL7L|FLJJLFJ.|.LF||FJ|LJF-JL--7|.L---L7.LFJL-7..L||7.LL-F7L7J||F--|||FJ7FJ||FFF.LJ-7JJJ.||FFJ.L..F- 134 | F7-|J||F|-7LJ|F-7|77LL--L-F7LL--F7|FJL-7..|F-F-|L|FL7--.F-F7JF-7.L--7F-J-.J-L-|||LL---J7|-|F77.J.LJLL-77|LFLJ7J.--7|JF|LJFF7.LF7L7-7J.LL-F.J 135 | ||.L-L-7-F7JLF|L|J-7-L-F.|L-FJ|.LJFL---JJFLF7.7|F-JLF7LFJFJ7.JLJFJJFJ|-J|7..|7JF-7LLJ|FL7.-JJLFL.-JL7|LF7FLJJ|.J.L7J.|.FLL--7||FFJ.J-FJJ-F-J 136 | |LF7F|.L----F-77||.|FL7|.L.||L|JJF7FJJJ|LL7FL7L7|7.-L7-J|L|J-L7|L|7|FJ7FL---|7.L.F.|.F-F-|JLJFF..L7J.|-LF7..FL7JF.L----JLJLL---7L.|.-J|7FLF. 137 | |J||7LJ|.||.L7L--7F-|7LJ.|..|7||-JLJJ-77FLJJ-|J||-7|JJ|L-.L7|F|-J.L||J77F7|F-J.|F--77JLLL|-F--|-|-77LJJ|LFLJJL|LF7|-7F--F|7.LFJ7-|.L7FLL|LJ7 138 | J-F-JJJF7-|7.|.LJ-LJ|LL7LFJ-7-|7FLF|.FFL7.||.J--J-|7.L|7|.FJ-7.|J|F||-J7JL|J7.FFJ|7||-..L|-J7F|LF7-|.-.F-JFFL-|L|-7|.|L77.FF7-7L7LFLJ||J.F-7 139 | .FF.J.F7J.L--LF7J.|.LJ7||L|F7|JJF.|JFLJL|7LL7-||JJL|-7JF--|J7|.FFJ7LJ7|JLFJLJ7L.L-77|L|-.L.|-FL7.FJ.FJF-J.F|-FJ||.FJ-.|.F-L-F.F-F-7.FF|JFL7. 140 | -L|JL--J--J.LLLL7-F7-L-L-JL-JL..L-.L|J.F7-JL|--J---JJJLLL-7--FJLLLFJL-|JJL--LFL7.LLL-7JLLJ-7-J.F-FJ-L-LJJF7JL|JLF7J.L-L--JJ.|.LJ.LJ.-7J.L7-7 -------------------------------------------------------------------------------- /11/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | const grid = input.map((line) => line.split("")); 5 | 6 | // identify all rows and columns with no # 7 | const noHashRows: number[] = []; 8 | for (let i = 0; i < grid.length; i++) { 9 | if (!grid[i].includes("#")) { 10 | noHashRows.push(i); 11 | } 12 | } 13 | 14 | const noHashColumns: number[] = []; 15 | for (let i = 0; i < grid[0].length; i++) { 16 | if (!grid.some((row) => row[i] === "#")) { 17 | noHashColumns.push(i); 18 | } 19 | } 20 | 21 | console.log("x", noHashRows, "y", noHashColumns); 22 | 23 | // double all rows and columns with no # 24 | const newGrid: string[][] = [...grid].map((r) => [...r]); 25 | for (let i = 0; i < grid.length; i++) { 26 | const newRow = [...grid[i]]; 27 | 28 | console.log("rowBefore", newRow); 29 | // double columns 30 | for (let j = noHashColumns.length - 1; j >= 0; j--) { 31 | newRow.splice(noHashColumns[j], 0, "."); 32 | } 33 | console.log("rowAfter", newRow); 34 | newGrid[i] = newRow; 35 | } 36 | 37 | const fullGrid: string[][] = []; 38 | 39 | newGrid.forEach((row, i) => { 40 | if (noHashRows.includes(i)) { 41 | fullGrid.push(row); 42 | } 43 | fullGrid.push(row); 44 | }); 45 | 46 | console.log("input?", fullGrid); 47 | 48 | // identify coordinates of all # in fullGrid 49 | const hashes: [number, number][] = []; 50 | for (let i = 0; i < fullGrid.length; i++) { 51 | for (let j = 0; j < fullGrid[i].length; j++) { 52 | if (fullGrid[i][j] === "#") { 53 | hashes.push([i, j]); 54 | } 55 | } 56 | } 57 | 58 | // print fullGrid 59 | fullGrid.forEach((row) => { 60 | console.log(row.join("")); 61 | }); 62 | 63 | console.log("hashes", hashes); 64 | 65 | // calculate distance between two points WITHOUT diagonal movement 66 | function distance(a: [number, number], b: [number, number]) { 67 | return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]); 68 | } 69 | 70 | const distances: number[] = []; 71 | 72 | for (let a = 0; a < hashes.length - 1; a++) { 73 | for (let b = a + 1; b < hashes.length; b++) { 74 | distances.push(distance(hashes[a], hashes[b])); 75 | } 76 | } 77 | 78 | const sum = distances.reduce((a, b) => a + b, 0); 79 | console.log("distances", distances.length, distance(hashes[7], hashes[8])); 80 | 81 | console.log("sum?", sum); 82 | -------------------------------------------------------------------------------- /11/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | const grid = input.map((line) => line.split("")); 5 | 6 | // identify all rows and columns with no # 7 | const noHashRows: number[] = []; 8 | for (let i = 0; i < grid.length; i++) { 9 | if (!grid[i].includes("#")) { 10 | noHashRows.push(i); 11 | } 12 | } 13 | 14 | const noHashColumns: number[] = []; 15 | for (let i = 0; i < grid[0].length; i++) { 16 | if (!grid.some((row) => row[i] === "#")) { 17 | noHashColumns.push(i); 18 | } 19 | } 20 | 21 | console.log("x", noHashRows, "y", noHashColumns); 22 | 23 | // identify coordinates of all # in fullGrid 24 | const hashes: [number, number][] = []; 25 | for (let i = 0; i < grid.length; i++) { 26 | for (let j = 0; j < grid[i].length; j++) { 27 | if (grid[i][j] === "#") { 28 | hashes.push([i, j]); 29 | } 30 | } 31 | } 32 | console.log("hashes", hashes); 33 | 34 | const multiplier = 1000000; 35 | 36 | // calculate distance between two points WITHOUT diagonal movement 37 | function distance(a: [number, number], b: [number, number]) { 38 | const base = Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]); 39 | 40 | // find all rows and columns crossed with no hashes 41 | const crossedRows = noHashRows.filter((row) => { 42 | return row > Math.min(a[0], b[0]) && row < Math.max(a[0], b[0]); 43 | }); 44 | const crossedColumns = noHashColumns.filter((column) => { 45 | return column > Math.min(a[1], b[1]) && column < Math.max(a[1], b[1]); 46 | }); 47 | 48 | return base + (crossedRows.length + crossedColumns.length) * (multiplier - 1); 49 | } 50 | 51 | const distances: number[] = []; 52 | 53 | for (let a = 0; a < hashes.length - 1; a++) { 54 | for (let b = a + 1; b < hashes.length; b++) { 55 | distances.push(distance(hashes[a], hashes[b])); 56 | } 57 | } 58 | 59 | const sum = distances.reduce((a, b) => a + b, 0); 60 | console.log("distances", distances.length, distance(hashes[7], hashes[8])); 61 | 62 | console.log("sum?", sum); 63 | -------------------------------------------------------------------------------- /11/example.txt: -------------------------------------------------------------------------------- 1 | ...#...... 2 | .......#.. 3 | #......... 4 | .......... 5 | ......#... 6 | .#........ 7 | .........# 8 | .......... 9 | .......#.. 10 | #...#..... -------------------------------------------------------------------------------- /12/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | function createPermutations(input: string): string[] { 5 | if (!input.includes("?")) { 6 | return [input]; 7 | } 8 | const permutations = []; 9 | 10 | // replace all ? with . and # 11 | const firstQuestionMark = input.indexOf("?"); 12 | const before = input.slice(0, firstQuestionMark); 13 | const after = input.slice(firstQuestionMark + 1); 14 | const dot = before + "." + after; 15 | const notDot = before + "#" + after; 16 | 17 | return [...createPermutations(dot), ...createPermutations(notDot)]; 18 | } 19 | 20 | const permutated = input.map((p) => createPermutations(p.split(" ")[0])); 21 | 22 | // #.#.### 1,1,3 23 | // First 2 groups of # are length 1, third is length 3 24 | // Calculate if a permutation 25 | 26 | const accuratePermutations = permutated.map((perms, i) => { 27 | const nums = input[i].split(" ")[1].split(",").map(Number); 28 | 29 | const accuratePerms = []; 30 | 31 | perms.forEach((perm) => { 32 | const shiftable = perm.split(".").filter((x) => x !== ""); 33 | if (shiftable.length !== nums.length) { 34 | return; 35 | } 36 | const accurate = shiftable.every((x, i) => x.length === nums[i]); 37 | if (accurate) { 38 | accuratePerms.push(perm); 39 | } 40 | }); 41 | 42 | return accuratePerms.length; 43 | }); 44 | 45 | const sum = accuratePermutations.reduce((a, b) => a + b, 0); 46 | 47 | console.log("answer?", sum); 48 | -------------------------------------------------------------------------------- /12/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | const memo: { [key: string]: number } = {}; 5 | 6 | function doWork(s: string, withinRun: number | null, remain: number[]): number { 7 | // Create a unique key for memoization 8 | const key = `${s}-${withinRun}-${remain.join(",")}`; 9 | if (memo[key] !== undefined) { 10 | return memo[key]; 11 | } 12 | 13 | if (!s) { 14 | if (withinRun === null && remain.length === 0) { 15 | return 1; 16 | } 17 | if (remain.length === 1 && withinRun !== null && withinRun === remain[0]) { 18 | return 1; 19 | } 20 | return 0; 21 | } 22 | 23 | let possibleMore: number = 0; 24 | for (let ch of s) { 25 | if (ch === "#" || ch === "?") { 26 | possibleMore += 1; 27 | } 28 | } 29 | 30 | if ( 31 | withinRun !== null && 32 | possibleMore + withinRun < remain.reduce((a, b) => a + b, 0) 33 | ) { 34 | return 0; 35 | } 36 | if (withinRun === null && possibleMore < remain.reduce((a, b) => a + b, 0)) { 37 | return 0; 38 | } 39 | if (withinRun !== null && remain.length === 0) { 40 | return 0; 41 | } 42 | 43 | let poss: number = 0; 44 | if (s[0] === "." && withinRun !== null && withinRun !== remain[0]) { 45 | return 0; 46 | } 47 | if (s[0] === "." && withinRun !== null) { 48 | poss += doWork(s.substring(1), null, remain.slice(1)); 49 | } 50 | if (s[0] === "?" && withinRun !== null && withinRun === remain[0]) { 51 | poss += doWork(s.substring(1), null, remain.slice(1)); 52 | } 53 | if ((s[0] === "#" || s[0] === "?") && withinRun !== null) { 54 | poss += doWork(s.substring(1), withinRun + 1, remain); 55 | } 56 | if ((s[0] === "?" || s[0] === "#") && withinRun === null) { 57 | poss += doWork(s.substring(1), 1, remain); 58 | } 59 | if ((s[0] === "?" || s[0] === ".") && withinRun === null) { 60 | poss += doWork(s.substring(1), null, remain); 61 | } 62 | 63 | memo[key] = poss; 64 | return poss; 65 | } 66 | 67 | const counts = input.map((l) => { 68 | const parts = l.split(" "); 69 | const s = parts[0]; 70 | const v = parts[1].split(",").map((x) => parseInt(x)); 71 | let news = ""; 72 | for (let j = 0; j < 5; j++) { 73 | news += "?"; 74 | news += s; 75 | } 76 | return doWork(news.substring(1), null, Array(5).fill(v).flat()); 77 | }); 78 | const sum = counts.reduce((a, b) => a + b, 0); 79 | 80 | console.log("answer", sum); 81 | -------------------------------------------------------------------------------- /12/example.txt: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 -------------------------------------------------------------------------------- /13/a.ts: -------------------------------------------------------------------------------- 1 | const parsed = Deno.readTextFileSync("input.txt").split("\n\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n\n"); 3 | 4 | const grids = parsed.map((grid) => 5 | grid.split("\n").map((row) => row.split("")) 6 | ); 7 | 8 | const rotate = (input: string[][]) => { 9 | const output: string[][] = []; 10 | for (let i = 0; i < input[0].length; i++) { 11 | const row: string[] = []; 12 | for (let j = 0; j < input.length; j++) { 13 | row.push(input[j][i]); 14 | } 15 | output.push(row); 16 | } 17 | return output; 18 | }; 19 | 20 | const matching = (a: string[], b: string[]) => { 21 | for (let i = 0; i < a.length; i++) { 22 | if (a[i] !== b[i]) return false; 23 | } 24 | return true; 25 | }; 26 | 27 | function getReflection(grid: string[][]) { 28 | main: for (let r = 0; r < grid.length - 1; r++) { 29 | let safe = true; 30 | const shortest = Math.min(r, grid.length - r); 31 | for (let i = 0; i < shortest + 1; i++) { 32 | const lowRow = r - i; 33 | const highRow = r + 1 + i; 34 | if (lowRow < 0 || highRow >= grid.length) break; 35 | if (!matching(grid[lowRow], grid[highRow])) { 36 | safe = false; 37 | continue main; 38 | } 39 | } 40 | if (safe) { 41 | return r + 1; 42 | } 43 | } 44 | return 0; 45 | } 46 | 47 | const answers = grids.map((grid) => { 48 | const horizontal = getReflection(grid); 49 | const vertical = getReflection(rotate(grid)); 50 | return 100 * horizontal + vertical; 51 | }); 52 | 53 | const sum = answers.reduce((a, b) => a + b, 0); 54 | 55 | console.log("sum", sum); 56 | -------------------------------------------------------------------------------- /13/b.ts: -------------------------------------------------------------------------------- 1 | const parsed = Deno.readTextFileSync("input.txt").split("\n\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n\n"); 3 | 4 | const grids = parsed.map((grid) => 5 | grid.split("\n").map((row) => row.split("")) 6 | ); 7 | 8 | const rotate = (input: string[][]) => { 9 | const output: string[][] = []; 10 | for (let i = 0; i < input[0].length; i++) { 11 | const row: string[] = []; 12 | for (let j = 0; j < input.length; j++) { 13 | row.push(input[j][i]); 14 | } 15 | output.push(row); 16 | } 17 | return output; 18 | }; 19 | 20 | const matching = (a: string[], b: string[]) => { 21 | let diffs = 0; 22 | for (let i = 0; i < a.length; i++) { 23 | if (a[i] !== b[i]) diffs++; 24 | } 25 | return diffs; 26 | }; 27 | 28 | function getReflection(grid: string[][]) { 29 | main: for (let r = 0; r < grid.length - 1; r++) { 30 | let diffs = 0; 31 | const shortest = Math.min(r, grid.length - r); 32 | for (let i = 0; i < shortest + 1; i++) { 33 | const lowRow = r - i; 34 | const highRow = r + i + 1; 35 | if (lowRow < 0 || highRow >= grid.length) break; 36 | diffs += matching(grid[lowRow], grid[highRow]); 37 | if (diffs > 1) { 38 | continue main; 39 | } 40 | } 41 | if (diffs === 1) { 42 | return r + 1; 43 | } 44 | } 45 | return 0; 46 | } 47 | 48 | const answers = grids.map((grid) => { 49 | const horizontal = getReflection(grid); 50 | const vertical = getReflection(rotate(grid)); 51 | return 100 * horizontal + vertical; 52 | }); 53 | 54 | const sum = answers.reduce((a, b) => a + b, 0); 55 | 56 | console.log("sum", sum); 57 | -------------------------------------------------------------------------------- /13/example.txt: -------------------------------------------------------------------------------- 1 | #.##..##. 2 | ..#.##.#. 3 | ##......# 4 | ##......# 5 | ..#.##.#. 6 | ..##..##. 7 | #.#.##.#. 8 | 9 | #...##..# 10 | #....#..# 11 | ..##..### 12 | #####.##. 13 | #####.##. 14 | ..##..### 15 | #....#..# -------------------------------------------------------------------------------- /14/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | type Grid = string[][]; 5 | const grid: Grid = input.map((line) => line.split("")); 6 | 7 | function doMove(grid: Grid) { 8 | // Check for all "O" chars, if "." is above, move up 9 | // Otherwise, do nothing 10 | const updatedGrid = grid.map((row) => row.map((char) => char)); 11 | for (let row = 1; row < grid.length; row++) { 12 | for (let col = 0; col < grid[0].length; col++) { 13 | if (grid[row][col] === "O") { 14 | if (grid[row - 1][col] === ".") { 15 | updatedGrid[row - 1][col] = "O"; 16 | updatedGrid[row][col] = "."; 17 | } 18 | } 19 | } 20 | } 21 | 22 | return updatedGrid; 23 | } 24 | 25 | function compareGrids(grid1: Grid, grid2: Grid) { 26 | return JSON.stringify(grid1) === JSON.stringify(grid2); 27 | } 28 | 29 | let updatedGrid = doMove(grid); 30 | while (!compareGrids(updatedGrid, doMove(updatedGrid))) { 31 | updatedGrid = doMove(updatedGrid); 32 | } 33 | 34 | function printGrid(grid: Grid) { 35 | grid.forEach((row) => console.log(row.join(""))); 36 | } 37 | 38 | function calculageLoad(grid: Grid) { 39 | let load = 0; 40 | for (let row = 0; row < grid.length; row++) { 41 | for (let col = 0; col < grid[0].length; col++) { 42 | if (grid[row][col] === "O") { 43 | load = load + (grid.length - row); 44 | } 45 | } 46 | } 47 | return load; 48 | } 49 | 50 | printGrid(updatedGrid); 51 | 52 | console.log("Answer", calculageLoad(updatedGrid)); 53 | -------------------------------------------------------------------------------- /14/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | type Grid = string[][]; 5 | let grid: Grid = input.map((line) => line.split("")); 6 | 7 | function doMoveInternal(grid: Grid) { 8 | // Check for all "O" chars, if "." is above, move up 9 | // Otherwise, do nothing 10 | const updatedGrid = grid.map((row) => row.map((char) => char)); 11 | for (let row = 1; row < grid.length; row++) { 12 | for (let col = 0; col < grid[0].length; col++) { 13 | if (grid[row][col] === "O") { 14 | if (grid[row - 1][col] === ".") { 15 | updatedGrid[row - 1][col] = "O"; 16 | updatedGrid[row][col] = "."; 17 | } 18 | } 19 | } 20 | } 21 | 22 | return updatedGrid; 23 | } 24 | 25 | function compareGrids(grid1: Grid, grid2: Grid) { 26 | return JSON.stringify(grid1) === JSON.stringify(grid2); 27 | } 28 | 29 | function slide(grid: Grid) { 30 | let updatedGrid = doMoveInternal(grid); 31 | while (!compareGrids(updatedGrid, doMoveInternal(updatedGrid))) { 32 | updatedGrid = doMoveInternal(updatedGrid); 33 | } 34 | 35 | return updatedGrid; 36 | } 37 | 38 | function getScore(grid: Grid) { 39 | const n = grid.length; 40 | let ans = 0; 41 | for (let i = 0; i < n; i++) { 42 | ans += (n - i) * grid[i].filter((cell) => cell === "O").length; 43 | } 44 | return ans; 45 | } 46 | 47 | function rotate(grid: Grid) { 48 | const height = grid.length; 49 | const width = grid[0].length; 50 | const newGrid: Grid = Array.from({ length: width }, () => 51 | Array.from({ length: height }, () => ".") 52 | ); 53 | for (let row = 0; row < height; row++) { 54 | for (let column = 0; column < width; column++) { 55 | newGrid[column][height - row - 1] = grid[row][column]; 56 | } 57 | } 58 | return newGrid; 59 | } 60 | 61 | function toStr(grid: Grid) { 62 | return JSON.stringify(grid); 63 | } 64 | 65 | const seenGrids: { [key: string]: [number, number] } = {}; 66 | const goal = 1000000000; 67 | let runs = 1; 68 | 69 | while (true) { 70 | for (let j = 0; j < 4; j++) { 71 | grid = slide(grid); 72 | grid = rotate(grid); 73 | } 74 | const flattenedGrid = toStr(grid); 75 | if (seenGrids[flattenedGrid]) { 76 | const cycleLen = runs - seenGrids[flattenedGrid][0]; 77 | for (const [index, score] of Object.values(seenGrids)) { 78 | if ( 79 | index >= seenGrids[flattenedGrid][0] && 80 | index % cycleLen === goal % cycleLen 81 | ) { 82 | console.log("ANSWER", score); 83 | break; 84 | } 85 | } 86 | break; 87 | } 88 | seenGrids[flattenedGrid] = [runs, getScore(grid)]; 89 | runs++; 90 | } 91 | -------------------------------------------------------------------------------- /14/example.txt: -------------------------------------------------------------------------------- 1 | O....#.... 2 | O.OO#....# 3 | .....##... 4 | OO.#O....O 5 | .O.....O#. 6 | O.#..O.#.# 7 | ..O..#O..O 8 | .......O.. 9 | #....###.. 10 | #OO..#.... -------------------------------------------------------------------------------- /14/input.txt: -------------------------------------------------------------------------------- 1 | ....#..OO.O..OO..O...#....OO....#........#..#..OOO..#.....#..#.O#O.#...#......#..O......O....O#.#O.# 2 | .O.#.#.O.O.OO...O..O...O.O.OO.....O.....#...#..O#O....OO##.O...O..#........O......O.O#.....O##O.#.O# 3 | O.O#.....#.O#OOO..#O..#OO....###.#...#.O#....O..O...O###.......O...........O...OO.........O.....#.#. 4 | .O.O...O#O##.#.O.#..OOOOO##......##O....O.........#.......#.#.##.O.......O.......#...O.O....#..O.... 5 | ......#..#.##.OO.##..#..#OO.O#.#.O..........O.......#..O.O.O........O...O...##.O.O.#O........O.#OO.. 6 | ......##.O.....#.O..O##.OO.##O#..O.OO......O.OO..O..O#.....O..O.....O#O...........#.O.##..OO..O....O 7 | .....#.....O.O.#.##.....#.#..#.#.O#..##O#....#O..#.......#.O#OOOO...O...OO..O..O..O.#O.#..O.O..O.##. 8 | ......#......O##.#..#..O#............OOO............O.......O...O..OO.....#OOO.#O#....#...O........# 9 | ....#........O..O..O.##...O...#O...#.O.........O.O...#.OO#OO..OO.OO.....O#........#.#O..O.#........# 10 | ..O#.O#....O......O#.#.O#..#...#..O#....OO....O...OO.O..O......O.....O...O##OO........#...OO#..##.O. 11 | .O#.O#..#..#O..O..O.##.O.O#.O.OOO.O.#O....O......OOO.#.....O.........#..#..O.....O..OO.#......OO..#. 12 | ...OOO.#OO#....#.O.#..O...O....#....O...O..O.OO#.O...O....O#.#.O...........#...#.O...#...OO#.O...... 13 | .O.#.O........#.....O..#.O#...O.#....#...O.......O.OO.OO#O..#..O..#.O...#.#....OO..O.O#..#.O.OO##... 14 | .O...OO..#.#.OO#O....O.O.....OO...#O......OO........O.O......#.#.#O#...O..OOO#....##..O.##....#....# 15 | ...O...OO.O.#O.O..##.O.OO...#..O....O..O#.....#O.OO.......O.#........OO.........#..O.#...O#.O....... 16 | O..#.O....O..#..............O.....##.....O.#.....#...........O.#.O...O.....##....O..O..#.O.#O##..O.. 17 | ...O...O..O...O#..O#.OO#..O........#....#.O........#....#.....O...O.OO..O....#.##...O..#.O##..O..O.. 18 | ..OO...O...O..O#.O#O...#.##.#...#..OO.O.#.#..O....O..#O.O.....O...#.#.......O...####.....#.......#.. 19 | .#O...O.O.......OO##...#.......#O.#..#OO...O......O...O#..#.....O#...O..O...........OOO.O........... 20 | #....O.O.O........O.O#...#....O.O.........#..#.#.O.O..O.O......#.O.OOO.O...#O..OO..O#...O....#.O..#. 21 | O.......#..O.......O..O..#.#O.O.....O#....O....O.O#..OO.#...O.#..O...#.O#...#..#.O.......#...O.###.. 22 | .OO#...##.O.OO#..#O#O...O..#.O.O....OOO#.O.#O.OO.#O...O...##O..##....OO#...O.#.........##..#.O....#. 23 | ......#...O.#...#O....O..O...#O.O....#O....#OOO.#....O.O.##..O..O....O........O.....#....O##.....O.. 24 | O.O...O#.#O......#O...#......O..O..#....#...#.O#.O.O..#......#....#......O.#.OO..#..O...O.....#O#.OO 25 | #...O....O......O...#....#O.O..O.#......O#..##..#O#.#..O...O#..O..O##.OOO...#.OO..OO.#.#..##O.OO.... 26 | O.....O...#........#.O....OOOO....O............#..O...O....#..O.....#..O....O...#.......OO....O.#O.. 27 | #.O...#....#....#...#...OO...#O#..##..O...#.....OO....O..##...#..........#.....##OO.#...#.O.OO.#..O. 28 | #O#O#.###.......OOO.#....O....##.O...#.#....O...#.O#.......#...#O..O.O..O#..#...O#.#O..OO...#OO.#.O# 29 | .#O...O.........O...O.#O#O#.O.......##..##..##.O.#.#.O..OO.#.OO...OOO..#.O...O...#O..O.O#..#O#.OO..# 30 | .#..#O...O..O..OO#.#.O..##.......#O.####..#O...OO#O...O........O...OO...OO..O......#..O.......O#.O.. 31 | .....#O#.#....OO.O.....O...###O...#.#........#...O..O....O##O#...###....O......O...O#..#..O...O.#.## 32 | ..O...#..#..O..#.OO..O......O#OO....O...O..#..........##..O#.....#.....#.OO#.#O...O#..O#...#.#.##... 33 | ..O...#...O###......O.O..O.#.O#..........O.......#O...#.##..O....O.O...#.#....O..O.#...#.O.#O....... 34 | ..#.#..#O#.....#......O...##OO.O...#..#O#O..##.O....O##....OO....#....#..O.#........OO..##.O.....OO. 35 | O..#O.#..#.#...O.OO...OO...#.O#.#.O.O..#.........#....O...#.O..O#.....O......O...##.......#.##OO.O.. 36 | ..O.OO..O..#.....#.O#...#.O..OO..OO...OO..O..#O#........O.#.O.#.O...O#O........O.....O#..#.....O...# 37 | ..O...OO.#.#O.OO.O##.##.O.O#O#.OO......OOOO.#........#.....O...#...#.##..#........#.OO..#.O......... 38 | ..##.#OO#..O#.#.#....OO.O..............O..#....#.#.OO.O..O..OO..O.#..O.....O....#.....##...O.#O..O.. 39 | ..O.##..#..O...O....O..#........O.#..#.#.O......OO#OO.OO..OO.O###..#....O#.....#O..#....#OO#...#..O. 40 | .O....O.....#O.#.O...O..#.#....###......O...OO###.O....#.#O..O#..##OO...#..O.........O#...O.....O... 41 | O.OOO.O.#OO..#.......OOO..OO.#........O.O...OO......O....O#.O.O.....O......##....#......O....O...#.. 42 | ..##..#...O....O..#.#..#OO..O..............O.O....#....#OO...#.#.OO##O...OO.O#O....##.OO....#..##.#O 43 | ...O....O#.#OO.O...#.O.##...#..O.#..#O.OO#.....O.O..O.....#....O#O....#.O.O..OO...O#O.O......###.O.. 44 | ...O.O.#.............O.....##OOOO....O...O...#..O......#.##.#O...O#....#..O##.O....#O.O..#OOO....#.. 45 | .##OO..O...O.O.O....#.......O.#..#...OO...#..#..O.#.O.......O....O.....O.O.#.OO#O...#OO.O....#.#O... 46 | ...O.#OOO#.O.#...OOO......O..#.##OOO......O..OO.##.##....##.#..OO....O..O..............#...OOO...... 47 | ........#..OOO.#.#...O.#..##.O#.O##.O.##.##.#..O#O.O#......#..#O.#....OO............#...###.OOO....# 48 | #.O.O.....O...........OO...#OOO#..###...#.O#.#.....O..#..#.#.OO......#....O#.....#.O....#O#.OO.O..O. 49 | O...........#..OO...OO...O..O.O##.....#....O##O.O.....O#..OO#.#O...#...OO..OO.......#O.#.#OO..#O###. 50 | O...O.OO........#...##OO.........O.#....O.......#....#.#...#..#O.#...#..............#...#........O.. 51 | .#O....O.O....#...O##.#..O..OO#..#............#O...........O.OO#..##......O...O..#........#..#...... 52 | ...............#.........#O..#....O..##.O......#....#.OO.#.#.O.O.OO....O.....OOO...........O.#..O..O 53 | ......O.#O..........O#O.#..O#.O#.......#.O...O...#.....O.....#..O...#..#..O...##O#..O#.O...#.OOO..O. 54 | ##O#...#..O#........#O.....O...#.#OO#O...O.##..OO..O....OO.O.#...O......O..#...#.O.#..##OO....O..O.# 55 | ........O......#.OO..OO.OOO.O...O.OO.....O..#..OO#O.O....O......O.#..OO..O#O..#.O#..#....O..O..#.#.. 56 | ##..OOO.#OOO..O.O.O..O.#..O..O#..OOO.#..OO..OO..#.#.OOO...##..O#..O.#..#.#O....O..........#....O..OO 57 | .......#.....O......O#O...##.....###...#O...#....#.#....O....O..O.O..O...#OO...#O..OO.....O.#..O.... 58 | O.#...O..#.....O..#..O....O#.....#..#.#..###....O.OO...#O..#O#.##..O.#...O.##O....OO.O...O#.O..O..#. 59 | ....#.O..#O.....O..OO#OOO#....#...#.#..#.#.....O....O..O....#....O#....O........O..O#.#.#.###O.....O 60 | .....#O...#.#....O.....###...O....#.#...O#..O..##...O.O....#..O#.#...O.OO..#OO.....O...#..OOO....O.. 61 | #O...O.........#...#.OO....O.....#....##.#..#..##O.OO#O...O#O.....#..O...O...###.O#....#OO.##O.#O... 62 | O..OOO..#O.O.O#..O..O.O.##..O..OO#O....O....#..OO#.OO.#.O...O.....O.O..##...#....#...O....O........O 63 | ...OO.O.....#..#.#....O...OO...#O......O.#..O#..O..O.......O.O....#.O....O.##.....OO#..#..O#.OO#O... 64 | ..........OO....#..#O.O..#....O#.#.....#...#...OO...#..O.###O...##.##..#.....#.#..O.O..O...###O..... 65 | O..#...OO..O#....O...#O.....O....#....#..#O...#.O#..#..O...O#O.#O....O#O....O#..O.#.#.#..O.....O...O 66 | .O.O...O.......OO..O...#......OO.#.#.#....#..#....#O.........#OO..O...#..O..O#.#..O..##..O.#O..#..O. 67 | .#.O..O#..O..O#O.O...O#.....O..O..#..#...OO#...........#.O.OO...#..O.#.....#........#O.#.O....#O.O.. 68 | .O.....O..O...O..O......O#.O..O...........##..O.#.O.O.O.OOO....#.O..#O.#.##.......O#.#.....##...#O.. 69 | .O.O....#..#.#O....O.#......O.#.O#......O##..O....#.#...#.#.OO.......#OO#.##OO.....O.#O....OO....... 70 | #O#....OO...O......O....OO#O.....O.#.O.....#.O......O..OO..O..OOO.O..#.O#..#..#.....O.O..#.O...#O.## 71 | .......O.#O..#.#.....#.O.#..O..OOOO.#.O.O#...##.#...O.#OO...##.....#..O.O...#.....O.......#O.O#O...# 72 | #O..#.#..OO.O.O...#.........#O.O#.......O#..#O.O##.#...O.##O.O..#.O......OOO.O....#...O.O...#......# 73 | ..O##O.O#.O...O.......O..#...##..O.#.O.OO.OO#.....O.#..............O.O#.##.O.O....#..#...O.....#..## 74 | ..............O.........#.##......#....##...#...O.O##O.O..##..O.....O#....O.#.....O..##..#..OO....## 75 | #..#......O.O.O..O..O...#.#.#.OO..O#.O..O##OO#...#O...O.O.................#O.....#O.O#O....#......OO 76 | ..O#O#......O..#O......#.........O#O.#.O.....O.#.....O..O..O.##....#....OO....##..O.O.....O...O...O# 77 | ..O.O...O....OO......O....O..O.#O.O........OO......O#...OO##.........#.#...#.#......##O.##O....O.O#. 78 | ..O...#OO...O........O.O.....#.O..###O..#.....O.......#.....O...#O.#.....#....##..#....O.##......... 79 | ..#.#O.......O#..........#.#..#...O.....O.OO#..O...O.#....OO.O.OO....O..O.O#.....#..O.....#O..O..#O# 80 | OO..O##..O.O...#.O..O..#....O..O....O..##.#..#O.O.......#.....O#..O.O.OOO..OOO#O##.#..#O.......#.... 81 | ...O#.O..#.....OO.#O.O#O.O.O##..OO..O......O..##.....O....#.##....O..#.O....OO....O.#OO..O...#..O#.. 82 | O...OOO...#.O#..O#.O.##.#O.O..OOO..O...OO#OOO...O....#..O#...OO#.O..#.....O#.O...#..........OO#.#.## 83 | ...OO.#O#....O#...#.#......O....O#........O#...#O#...#...O.....#.OO#...##.OO.OO...#..O.O.....O..O... 84 | .##..O..#O#O...#O.O..O#....#..#.......#....#.##.......#...##.O#OO......O#O.....O#.O.##...O.....OOOOO 85 | .OO.#.O#....OO.#OO.#O.O.......O.#......#.#O#.....O......##..O#O#O...#....O.O...#...O#....O...#.O.... 86 | .O##.O..O...O.....O#......OO.O..##...........##..#O...#...O#O.O...O#...###..#.O.O#O.#O..#......#.OO. 87 | O.OO#..O..OO.O...#OO.#.OO.#...#.#...O...O..O#OOO..OO..O......O............O.....O#..O...#OO.O.#O#OO# 88 | O##O......#..#...#.##O#.O.......#O#.O.............O.......#..O...#.OOO..O..O..OO#O#.O##..#O.#....OO# 89 | .....OO#.O..O..OOO.O..OO.........O#...#.....O.....#..#..O....#O#.O....O....OO..#...OO.O.O#...#.O.... 90 | ...#....#......#...O#O....O##.OO..#.O#OO#.OO..#.##..OO..#..O#..O......O......OO#..O.O..........O.... 91 | ...O...#...OOOOO......O...#...#.............O#O..OO...O.#...O.O..#O.OO..O.O.O...O.......#.....O.##.. 92 | ....O.#...O..#...#...O.......#....#..O.O..#.#...#..O.....O#O.....O...O.........#OO.O.#...#.......O.. 93 | .#.O...O.#.#O.O.#..##..#O....#OO...OO.#..O#O.OO....#O#OO...#.O......#....#...O....#.....O..#.....##. 94 | ..#.O.OOO#O#.OO.O....#O.........O.OO.#.#.#...O#O........O..#...O....O.O#.O...#....#.OOO.#..##...#.O. 95 | ....#O#O#O#.#.#.#O.....#..O..##O........##.O.......O.O#.##O..O..O......#OO.O.#.OOO...O..#..O.....O.. 96 | #.O...O.#.#OO..OO.O.....O...OOO....##.O...#O....O...O.#O.##.....O#...O.OO.#.....O....O.O..O.O......O 97 | ..OO#......O.....O......O...#.........#.OO....OO......O...#....#OOO...O.O.OO.....#..O...OO....OOO#O# 98 | .O...#.#.O...#..........#.O..O#.....O..##..O....O..#..#....O..O.O.OO#.O...O.#.O....#........###..OO. 99 | ....O.#....O...O.O..#OO##......#.#O.........OO......O#.O.#..OOO.#...OO...#O##.#.O......#...O...O.... 100 | #.O..O..#..O#.#....O...#...O#O#O...OO.OO...##....#..OO#...#...O.#.#O#..O..........#O.O..O...OOO.#... -------------------------------------------------------------------------------- /15/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | const chunks = input[0].split(","); 5 | 6 | function getAsciiNumberForCharacter(character: string): number { 7 | return character.charCodeAt(0); 8 | } 9 | 10 | const answers = chunks.map((chunk) => { 11 | const chars = chunk.split(""); 12 | let sum = 0; 13 | chars.forEach((char) => { 14 | sum += getAsciiNumberForCharacter(char); 15 | sum = sum * 17; 16 | sum = sum % 256; 17 | }); 18 | 19 | return sum; 20 | }); 21 | 22 | const sum = answers.reduce((acc, curr) => acc + curr, 0); 23 | 24 | console.log("input?", sum); 25 | -------------------------------------------------------------------------------- /15/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 3 | 4 | const chunks = input[0].split(","); 5 | 6 | let boxes = new Map(); 7 | 8 | function getAsciiNumberForCharacter(character: string): number { 9 | return character.charCodeAt(0); 10 | } 11 | 12 | const calculateHashForString = (chars: string[]): number => { 13 | let sum = 0; 14 | chars.forEach((char) => { 15 | sum += getAsciiNumberForCharacter(char); 16 | sum = sum * 17; 17 | sum = sum % 256; 18 | }); 19 | 20 | return sum; 21 | }; 22 | 23 | const answers = chunks.map((chunk) => { 24 | if (chunk.includes("-")) { 25 | const chars = chunk.replace("-", "").split(""); 26 | const index = calculateHashForString(chars); 27 | if (boxes.has(index)) { 28 | const existing = boxes.get(index); 29 | boxes.set( 30 | index, 31 | existing?.filter((item) => item.id !== chars.join("")) ?? [] 32 | ); 33 | } 34 | } else { 35 | const [key, focal] = chunk.split("="); 36 | const chars = key.split(""); 37 | const index = calculateHashForString(chars); 38 | if (boxes.has(index)) { 39 | const existing = 40 | boxes 41 | .get(index) 42 | ?.map((item) => 43 | item.id === key ? { id: key, focal: parseInt(focal) } : item 44 | ) ?? []; 45 | 46 | if (existing.some((item) => item.id === key)) { 47 | boxes.set(index, existing); 48 | } else { 49 | boxes.set(index, [...existing, { id: key, focal: parseInt(focal) }]); 50 | } 51 | } else { 52 | boxes.set(index, [{ id: key, focal: parseInt(focal) }]); 53 | } 54 | } 55 | console.log("chunk", chunk); 56 | console.log("updated", boxes); 57 | console.log("\n"); 58 | }); 59 | 60 | const scores = Array.from(boxes.values()).map((box) => { 61 | const base = calculateHashForString(box[0]?.id.split("") ?? []) + 1; 62 | let score = 0; 63 | box.forEach((item, index) => { 64 | score += base * (index + 1) * item.focal; 65 | }); 66 | return score; 67 | }); 68 | 69 | console.log("boxes?", boxes); 70 | console.log("scores?", scores); 71 | 72 | const sum = scores.reduce((acc, curr) => acc + curr, 0); 73 | 74 | console.log("input?", sum); 75 | -------------------------------------------------------------------------------- /15/example.txt: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 -------------------------------------------------------------------------------- /16/a.ts: -------------------------------------------------------------------------------- 1 | // const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 3 | const grid = input.map((line) => line.split("")); 4 | 5 | // velocities: 0 = right, 1 = down, 2 = left, 3 = up 6 | const velocities: [number, number][] = [ 7 | [0, 1], 8 | [1, 0], 9 | [0, -1], 10 | [-1, 0], 11 | ]; 12 | 13 | function reflect(char: string, dir: number): number[] { 14 | if (char === ".") return [dir]; 15 | if (char === "-") { 16 | if (dir === 2 || dir === 0) return [dir]; 17 | return [2, 0]; 18 | } 19 | if (char === "|") { 20 | if (dir === 3 || dir === 1) return [dir]; 21 | return [3, 1]; 22 | } 23 | if (char === "/") { 24 | if (dir === 3) return [0]; 25 | if (dir === 0) return [3]; 26 | if (dir === 1) return [2]; 27 | if (dir === 2) return [1]; 28 | } 29 | if (char === "\\") { 30 | if (dir === 3) return [2]; 31 | if (dir === 2) return [3]; 32 | if (dir === 1) return [0]; 33 | if (dir === 0) return [1]; 34 | } 35 | 36 | throw new Error("not a valid direction"); 37 | } 38 | 39 | function countUniquePoints(s: Set) { 40 | const trimmed = [...s].map((s) => { 41 | const [x, y] = s.split(","); 42 | return `${x},${y}`; 43 | }); 44 | return new Set(trimmed).size; 45 | } 46 | 47 | const path = new Set(); 48 | 49 | // Let's get recursive 50 | function move(x: number, y: number, dr: number) { 51 | const key = `${x},${y},${dr}`; 52 | if (path.has(key)) { 53 | return; 54 | } 55 | path.add(key); 56 | const char = grid[x][y]; 57 | const dirs = reflect(char, dr); 58 | dirs.forEach((next) => { 59 | const [dx, dy] = velocities[next]; 60 | const [nx, ny] = [x + dx, y + dy]; 61 | if (nx >= 0 && nx < grid.length && ny >= 0 && ny < grid[0].length) { 62 | move(nx, ny, next); 63 | } 64 | }); 65 | } 66 | 67 | move(0, 0, 0); 68 | 69 | const sum = countUniquePoints(path); 70 | 71 | console.log("SUM", sum); 72 | -------------------------------------------------------------------------------- /16/b.ts: -------------------------------------------------------------------------------- 1 | // const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 3 | const grid = input.map((line) => line.split("")); 4 | 5 | // velocities: 0 = right, 1 = down, 2 = left, 3 = up 6 | const velocities: [number, number][] = [ 7 | [0, 1], 8 | [1, 0], 9 | [0, -1], 10 | [-1, 0], 11 | ]; 12 | 13 | function reflect(char: string, dir: number): number[] { 14 | if (char === ".") return [dir]; 15 | if (char === "-") { 16 | if (dir === 2 || dir === 0) return [dir]; 17 | return [2, 0]; 18 | } 19 | if (char === "|") { 20 | if (dir === 3 || dir === 1) return [dir]; 21 | return [3, 1]; 22 | } 23 | if (char === "/") { 24 | if (dir === 3) return [0]; 25 | if (dir === 0) return [3]; 26 | if (dir === 1) return [2]; 27 | if (dir === 2) return [1]; 28 | } 29 | if (char === "\\") { 30 | if (dir === 3) return [2]; 31 | if (dir === 2) return [3]; 32 | if (dir === 1) return [0]; 33 | if (dir === 0) return [1]; 34 | } 35 | 36 | throw new Error("not a valid direction"); 37 | } 38 | 39 | function countUniquePoints(s: Set) { 40 | const trimmed = [...s].map((s) => { 41 | const [x, y] = s.split(","); 42 | return `${x},${y}`; 43 | }); 44 | return new Set(trimmed).size; 45 | } 46 | 47 | function runGrid(start: [number, number, number]): number { 48 | const path = new Set(); 49 | 50 | // Let's get recursive 51 | function move(x: number, y: number, dr: number) { 52 | const key = `${x},${y},${dr}`; 53 | if (path.has(key)) { 54 | return; 55 | } 56 | path.add(key); 57 | const char = grid[x][y]; 58 | const dirs = reflect(char, dr); 59 | dirs.forEach((next) => { 60 | const [dx, dy] = velocities[next]; 61 | const [nx, ny] = [x + dx, y + dy]; 62 | if (nx >= 0 && nx < grid.length && ny >= 0 && ny < grid[0].length) { 63 | move(nx, ny, next); 64 | } 65 | }); 66 | } 67 | 68 | move(start[0], start[1], start[2]); 69 | return countUniquePoints(path); 70 | } 71 | 72 | const startingPoints: [number, number, number][] = []; 73 | for (let x = 0; x < grid.length; x++) { 74 | startingPoints.push([x, 0, 0]); 75 | startingPoints.push([x, grid[0].length - 1, 2]); 76 | } 77 | for (let y = 0; y < grid[0].length; y++) { 78 | startingPoints.push([0, y, 1]); 79 | startingPoints.push([grid.length - 1, y, 3]); 80 | } 81 | 82 | const scores = startingPoints.map((test) => runGrid(test)); 83 | 84 | console.log("answer", Math.max(...scores)); 85 | -------------------------------------------------------------------------------- /16/example.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /16/input.txt: -------------------------------------------------------------------------------- 1 | \....\..-...........|..\........|.........|./.\..............\................/.....-............./........... 2 | ......-........../.........--........................|..-../.............................-\.....|............. 3 | ....-.-........................................................../..........................|...|......\|..... 4 | ....\.-......\|...............................-|........\.............................../......\.............. 5 | ..|.|.|...-..-...-..................--........../.......................|.\-.../....................-....\.... 6 | ....\...................|..............|..../../.......................\...................................... 7 | ...............\.|..............\........\.\.-...--..-...\........................|.|......................... 8 | ..........-........\............-....|...|.............\.\...............\./............./.................... 9 | ...\.....\.\...............||...........................................-...............-...../...|........... 10 | ......./......./....-..../...-........./././\..||.......-.|.......\.........\|................./........-..... 11 | ......................|./...|......................./...|....\................-....|....|.\...|.../......../.. 12 | .\...........\-......\.\|..\\..-|//../............/...............................-........|..|............-.. 13 | ..|.............../.............|..-./..\....-|...........................-.|......|....\\......-..../...\.... 14 | ............\......\|.../...............-......./.........\.\.\.../.|......................................... 15 | ....\-......./-........../....................|.........-......../........-.............\..|...../...-........ 16 | |.................|....................-.............|...........-.-....-...-......-................./|.\..... 17 | |................/......./.........|.........................-/...........|.................\-/|.........\../. 18 | ...................-..............\................|..../.||.-....\...............-......................\..\. 19 | .......|......\..-....-...............\.....|../..\..-...........|......../....\.././..........\.|........-..\ 20 | ..\..|............|....\......../............-.\.................................-............-............\.. 21 | .........|.....\...........................................|....|............../..-.............../........... 22 | ...........-................................\...../....|.....|..............|................................. 23 | ./........................\..\...........................|.|................................-................. 24 | ......|\./....................|..../.........\......|.\..-.|.....|........./........|.........-.-............. 25 | .........\.....................-.................\.....|...................../........./..............|....... 26 | .................-.........\........\.....-...................\.....-..\........../........................./| 27 | ............|...........-....\..\............-....-........................|...|........../.............\..... 28 | ........................................../............/..................\............\..../......\../....... 29 | ......../..........-.....-...................../......................-......\..../..\.-...../....|.|....-.... 30 | \.........\.......-.................\.......\-......|.......\......................\......................-... 31 | .........../.................|....................................|...\..../.../|............................. 32 | ..\.......................\...........-..\...../.................\.\..-................-...........|.......... 33 | ...../.../............................\............................../.-../........\.-...|.................... 34 | ...|....\.\...\...........-............\.............|............\.........................../........./..... 35 | ........../......../................/.../........................|............-......................\......./ 36 | .../............................-.....-...|.......\....................|...............\...................... 37 | ......|..-|\..\............../.\.............-....-.......\................./.././/......../.....|....../|.... 38 | .............\.........\.......\........-...........||.......|...-.............\........./................/.|. 39 | ...\...../.-.....................-..........................-..-............../...../......|..|......|......\. 40 | ...|................|.............................|........./....\.....\...................................\.. 41 | ..............-......................../........\.......................|.\/................-.........\....... 42 | .\........\..\.....-.......\.-.-......................\..-........../................../..................--.. 43 | ........|.....-.......|.../../..........|........\..|...../..\....../..|...............\|..................... 44 | ..........|...../........|....../..........-..-................../....-..........|............................ 45 | |...............-......../......./..................\.............\..........|.......\............||.......... 46 | ........|.........|...............|.........../|..-\..........|....|...\..|\.\...............|-..-............ 47 | /......./.............-.....-.......\......-./.......\..\............|...\..\...../...............-.\......... 48 | .-.........|....../.............|........|.......|.....-..............-....../............|............-/\.... 49 | ..-...|........-...............-........\......../.-........................-................../-.......|..... 50 | ...\.-.....................-............................\...................||.....-..........\......\..../... 51 | ..........\./........\.||\...|..........-...../.......\.///......../...|...................../....--.......... 52 | .....\........./../.............-|...-..---.................../....|...\.../.....|./..........|...../......... 53 | /..........-...../........-.................../..................\./.|..............-...-...............|..... 54 | ............\.............\..................................\|....|.../.....|..........\..................|.. 55 | ...........\........./......\.................................../...-.....\.............\..|...........-...... 56 | .............\..-......................\.......|.../...............\.....-...|...|............................ 57 | ................|-...................../|...|......................................\.............|.......|.... 58 | ..|........./.................../...................../.....|.-...\............-.............................\ 59 | |.\........\.-..........|..|.........|\.-|\\.-....-...............................|....|...........-..|.....-. 60 | ./................|.|..|......\.....................-..........\........-...................../......|........ 61 | ........../.........../............../...||..-.........|....\.\.......|..../.......|............./.-......./.. 62 | .........\.\.......-................/.../....|...................\.\|./...../........\.....................|.. 63 | ..............|........-................|..............|.....-.-................\.........|......./......-.... 64 | .........................../.-.-...........................-................-.....-.............|.........\.\. 65 | ....|....|.../..........................|............................-...........--....../..|.............\\|. 66 | ......./...../..............-...............\|............/-..............................-/.....-.\.......... 67 | ....-........-....\\.....|../.....-......../.............|.............|...../.......\\....../.........|...... 68 | ......................-.../.................................................................-..../........|.-/ 69 | .................|...........-..|.-.......|............/................./......-.....................-.|..... 70 | |...|.........\.|\..\....../..........-......\\......\.....................\/../.........../..../..-...|.|.... 71 | .|.|....|.....|\............./.|......-......-............/....-...-......../-|............................... 72 | ....../..............\............../....\..............\............|..\.........|....................|...... 73 | .........................\|.......-..........................................................\|............... 74 | ...............\.........|../.....-......\..................-.........................-..............-......|. 75 | .....|...|.-...........................\..........\......\../.................-...............-........\...... 76 | .|........../........../..............|..../...../...|........-......../.\..........\......................-.. 77 | .............-|..................../.......-.../......-.../......./......|..........-./....................... 78 | ...\.........|.|...................|../.|...........|....................///....-.........-......./.......|... 79 | .\........-.\..................................-\../...../..\......\...................../|.......-........... 80 | ........\..................\.......|...|................../\............|........-............\||.../..-../... 81 | .............\..|/...................../....|.|...//....../|............\..\..|.......-..............-........ 82 | .........|/..................-............/....../............/....||......................................... 83 | .|............-........|.........-//..........-................../........../..-...............|..|.......\... 84 | ........|.../......-..|.\..|..................|./....|.....-................................/.........../..... 85 | ..............-..........|......../.................................../.....\.............../.../..\..|/...... 86 | --................\...............|.........-.....|...../.........................-.....-.\\..........\....... 87 | .......\.........\.................-..................../......\.....................\.................-...... 88 | ....|....|......|...\.........\......../............/..../....\.......\...\....\.........|...................| 89 | ..........|....\\.............|........./.....|............../...-/...-.||......./......\..................... 90 | ..-./..-./.|...............-/.-.............|...............................\.....-........................... 91 | /......|..|\........\........../...................-.\.......-...............-..\.......|.......|..-.......... 92 | ./..\................................/.-..................-................-......../.......-.....|........... 93 | ............|..|.....\............\.\............\......|.-....../........\..|............../...........|..... 94 | ...|....|............|......../....|.|............./......................................|....../.|..-....... 95 | ............\......\........-.../....................-./....-.../.\....|........|......-...\........../....... 96 | ...........................-................./.......\...........................-.......\.................... 97 | .-.-.......|.......|.......-..................................../......-\......./..\.-.............-.......... 98 | .............../............-...................|..........................\.-..............\................. 99 | ..................................../|..............................|.../....\............/|.........\......./ 100 | .\...../\.-.........../....-.-|................./.../..../..........|..................................|.....- 101 | ..|......................\..................-...........\....-........\......-...-..-........................| 102 | ..-.......-......................\....-...........................|.......-../-...-......................|.... 103 | .............-..........................|..................................\./.........................-...../ 104 | ....\......|........................|..................../........................|.|\.......\......../......\ 105 | .../........./..................\..../.../\............|.......|...\.\...../...\.....-...........|..|.\....... 106 | ....\../..................\...|.........|../..../.......................|..........-...|....\../............./ 107 | ../......-......\.......\...........\|.......|...-./..........|................|../|......./.................. 108 | ........../\/............................-.....|...-..|...............|.........................-.\........... 109 | ......................|..........\..................../..-........-...../.........-........./.........../..... 110 | /.........-...................\.-\..............\...\....\.......\...|....................../.........|....... -------------------------------------------------------------------------------- /17/a.ts: -------------------------------------------------------------------------------- 1 | import MinHeap from "./heap.ts"; 2 | 3 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 4 | 5 | type Node = { x: number; y: number; repeat: number; dx: number; dy: number }; 6 | 7 | function genNeighbors(node: Node, data: string[]) { 8 | const neighbors: [Node, number][] = []; 9 | const { x, y, repeat, dx, dy } = node; 10 | 11 | if ( 12 | repeat < 3 && 13 | x + dx >= 0 && 14 | x + dx < data.length && 15 | y + dy >= 0 && 16 | y + dy < data[0].length 17 | ) { 18 | neighbors.push([ 19 | { x: x + dx, y: y + dy, repeat: repeat + 1, dx, dy }, 20 | parseInt(data[x + dx][y + dy]), 21 | ]); 22 | } 23 | 24 | const lr = [ 25 | { dx: -dy, dy: dx }, 26 | { dx: dy, dy: -dx }, 27 | ]; 28 | 29 | lr.forEach(({ dx, dy }) => { 30 | if ( 31 | x + dx >= 0 && 32 | x + dx < data.length && 33 | y + dy >= 0 && 34 | y + dy < data[0].length 35 | ) { 36 | neighbors.push([ 37 | { x: x + dx, y: y + dy, repeat: 1, dx, dy }, 38 | parseInt(data[x + dx][y + dy]), 39 | ]); 40 | } 41 | }); 42 | 43 | return neighbors; 44 | } 45 | 46 | function pathfind(data: string[]) { 47 | const visited = new Set(); 48 | const start1: Node = { x: 0, y: 0, repeat: 0, dx: 1, dy: 0 }; 49 | const start2: Node = { x: 0, y: 0, repeat: 0, dx: 0, dy: 1 }; 50 | const dist: { [key: string]: number } = {}; 51 | dist[JSON.stringify(start1)] = 0; 52 | dist[JSON.stringify(start2)] = 0; 53 | 54 | const Q = new MinHeap<[number, Node]>((a, b) => a[0] - b[0]); 55 | Q.add([0, start1]); 56 | Q.add([0, start2]); 57 | 58 | const target: [number, number] = [data.length - 1, data[0].length - 1]; 59 | 60 | while (!Q.isEmpty()) { 61 | const [_, current] = Q.pop()!; 62 | const uKey = JSON.stringify(current); 63 | 64 | if (visited.has(uKey)) continue; 65 | visited.add(uKey); 66 | 67 | if (current.x === target[0] && current.y === target[1]) { 68 | return dist[uKey]; 69 | } 70 | 71 | const neighbors = genNeighbors(current, data); 72 | 73 | neighbors.forEach(([v, cost]) => { 74 | const vKey = JSON.stringify(v); 75 | if (visited.has(vKey)) return; 76 | const alt = dist[uKey] + cost; 77 | if (!dist[vKey] || alt < dist[vKey]) { 78 | dist[vKey] = alt; 79 | Q.add([alt, v]); 80 | } 81 | }); 82 | } 83 | } 84 | 85 | const answer = pathfind(input); 86 | 87 | console.log("ans", answer); 88 | -------------------------------------------------------------------------------- /17/b.ts: -------------------------------------------------------------------------------- 1 | import MinHeap from "./heap.ts"; 2 | 3 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 4 | 5 | type Node = { x: number; y: number; repeat: number; dx: number; dy: number }; 6 | 7 | function genNeighbors(node: Node, data: string[]) { 8 | const neighbors: [Node, number][] = []; 9 | const { x, y, repeat, dx, dy } = node; 10 | 11 | if ( 12 | repeat < 10 && 13 | x + dx >= 0 && 14 | x + dx < data.length && 15 | y + dy >= 0 && 16 | y + dy < data[0].length 17 | ) { 18 | neighbors.push([ 19 | { x: x + dx, y: y + dy, repeat: repeat + 1, dx, dy }, 20 | parseInt(data[x + dx][y + dy]), 21 | ]); 22 | } 23 | 24 | const lr = [ 25 | { dx: -dy, dy: dx }, 26 | { dx: dy, dy: -dx }, 27 | ]; 28 | 29 | lr.forEach(({ dx, dy }) => { 30 | if ( 31 | x + dx >= 0 && 32 | x + dx < data.length && 33 | y + dy >= 0 && 34 | y + dy < data[0].length && 35 | repeat > 3 36 | ) { 37 | neighbors.push([ 38 | { x: x + dx, y: y + dy, repeat: 1, dx, dy }, 39 | parseInt(data[x + dx][y + dy]), 40 | ]); 41 | } 42 | }); 43 | 44 | return neighbors; 45 | } 46 | 47 | function pathfind(data: string[]) { 48 | const visited = new Set(); 49 | const start1: Node = { x: 0, y: 0, repeat: 0, dx: 1, dy: 0 }; 50 | const start2: Node = { x: 0, y: 0, repeat: 0, dx: 0, dy: 1 }; 51 | const dist: { [key: string]: number } = {}; 52 | dist[JSON.stringify(start1)] = 0; 53 | dist[JSON.stringify(start2)] = 0; 54 | 55 | const Q = new MinHeap<[number, Node]>((a, b) => a[0] - b[0]); 56 | Q.add([0, start1]); 57 | Q.add([0, start2]); 58 | 59 | const target: [number, number] = [data.length - 1, data[0].length - 1]; 60 | 61 | while (!Q.isEmpty()) { 62 | const [_, current] = Q.pop()!; 63 | const uKey = JSON.stringify(current); 64 | 65 | if (visited.has(uKey)) continue; 66 | visited.add(uKey); 67 | 68 | if ( 69 | current.x === target[0] && 70 | current.y === target[1] && 71 | current.repeat > 3 72 | ) { 73 | return dist[uKey]; 74 | } 75 | 76 | const neighbors = genNeighbors(current, data); 77 | 78 | neighbors.forEach(([v, cost]) => { 79 | const vKey = JSON.stringify(v); 80 | if (visited.has(vKey)) return; 81 | const alt = dist[uKey] + cost; 82 | if (!dist[vKey] || alt < dist[vKey]) { 83 | dist[vKey] = alt; 84 | Q.add([alt, v]); 85 | } 86 | }); 87 | } 88 | } 89 | 90 | const answer = pathfind(input); 91 | 92 | console.log("ans", answer); 93 | -------------------------------------------------------------------------------- /17/example.txt: -------------------------------------------------------------------------------- 1 | 2413432311323 2 | 3215453535623 3 | 3255245654254 4 | 3446585845452 5 | 4546657867536 6 | 1438598798454 7 | 4457876987766 8 | 3637877979653 9 | 4654967986887 10 | 4564679986453 11 | 1224686865563 12 | 2546548887735 13 | 4322674655533 -------------------------------------------------------------------------------- /17/heap.ts: -------------------------------------------------------------------------------- 1 | // ChatGPT generated this for me 2 | export default class MinHeap { 3 | private heap: T[]; 4 | private comparator: (a: T, b: T) => number; 5 | 6 | constructor(comparator: (a: T, b: T) => number) { 7 | this.heap = []; 8 | this.comparator = comparator; 9 | } 10 | 11 | private getLeftChildIndex(parentIndex: number): number { 12 | return 2 * parentIndex + 1; 13 | } 14 | 15 | private getRightChildIndex(parentIndex: number): number { 16 | return 2 * parentIndex + 2; 17 | } 18 | 19 | private getParentIndex(childIndex: number): number { 20 | return Math.floor((childIndex - 1) / 2); 21 | } 22 | 23 | private swap(indexOne: number, indexTwo: number): void { 24 | [this.heap[indexOne], this.heap[indexTwo]] = [ 25 | this.heap[indexTwo], 26 | this.heap[indexOne], 27 | ]; 28 | } 29 | 30 | private heapifyUp(): void { 31 | let index = this.heap.length - 1; 32 | while ( 33 | this.getParentIndex(index) >= 0 && 34 | this.comparator(this.heap[this.getParentIndex(index)], this.heap[index]) > 35 | 0 36 | ) { 37 | this.swap(this.getParentIndex(index), index); 38 | index = this.getParentIndex(index); 39 | } 40 | } 41 | 42 | private heapifyDown(): void { 43 | let index = 0; 44 | while (this.getLeftChildIndex(index) < this.heap.length) { 45 | let smallerChildIndex = this.getLeftChildIndex(index); 46 | if ( 47 | this.getRightChildIndex(index) < this.heap.length && 48 | this.comparator( 49 | this.heap[this.getRightChildIndex(index)], 50 | this.heap[smallerChildIndex] 51 | ) < 0 52 | ) { 53 | smallerChildIndex = this.getRightChildIndex(index); 54 | } 55 | 56 | if (this.comparator(this.heap[index], this.heap[smallerChildIndex]) < 0) { 57 | break; 58 | } else { 59 | this.swap(index, smallerChildIndex); 60 | } 61 | 62 | index = smallerChildIndex; 63 | } 64 | } 65 | 66 | public add(item: T): void { 67 | this.heap.push(item); 68 | this.heapifyUp(); 69 | } 70 | 71 | public pop(): T | undefined { 72 | if (this.size() === 0) return undefined; 73 | const item = this.heap[0]; 74 | this.heap[0] = this.heap[this.size() - 1]; 75 | this.heap.pop(); 76 | this.heapifyDown(); 77 | return item; 78 | } 79 | 80 | public size(): number { 81 | return this.heap.length; 82 | } 83 | 84 | public isEmpty(): boolean { 85 | return this.size() === 0; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /18/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | 3 | type Point = { x: number; y: number }; 4 | 5 | // shoelace for area 6 | function shoelaceArea(vertices: Point[]): number { 7 | let area = 0.0; 8 | for (let i = 0; i < vertices.length; i++) { 9 | const j = (i + 1) % vertices.length; 10 | const [p1, p2] = [vertices[i], vertices[j]]; 11 | 12 | area += p1.x * p2.y; 13 | area -= p1.y * p2.x; 14 | } 15 | 16 | return Math.abs(area / 2.0); 17 | } 18 | 19 | let loc: Point = { x: 0, y: 0 }; 20 | let totalDistance = 0; 21 | const vertices: Point[] = []; 22 | const dirMap: Record = { 23 | D: { x: 0, y: 1 }, 24 | L: { x: -1, y: 0 }, 25 | U: { x: 0, y: -1 }, 26 | R: { x: 1, y: 0 }, 27 | }; 28 | 29 | input.forEach((line) => { 30 | const [a, b] = line.split(" "); 31 | 32 | const dir = dirMap[a]; 33 | const dist = parseInt(b); 34 | 35 | totalDistance += dist; 36 | loc = { x: loc.x + dist * dir.x, y: loc.y + dist * dir.y }; 37 | vertices.push(loc); 38 | }); 39 | 40 | const innerArea = shoelaceArea(vertices); 41 | 42 | // pick's for interior 43 | const interior = innerArea + 1 - Math.floor(totalDistance / 2); 44 | 45 | // add to exterior for final answer 46 | const answer = interior + totalDistance; 47 | 48 | console.log("ans", answer); 49 | -------------------------------------------------------------------------------- /18/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | 3 | type Point = { x: number; y: number }; 4 | 5 | // shoelace for area 6 | function shoelaceArea(vertices: Point[]): number { 7 | let area = 0.0; 8 | for (let i = 0; i < vertices.length; i++) { 9 | const j = (i + 1) % vertices.length; 10 | const [p1, p2] = [vertices[i], vertices[j]]; 11 | 12 | area += p1.x * p2.y; 13 | area -= p1.y * p2.x; 14 | } 15 | 16 | return Math.abs(area / 2.0); 17 | } 18 | 19 | let loc: Point = { x: 0, y: 0 }; 20 | let totalDistance = 0; 21 | const vertices: Point[] = []; 22 | const dirMap: Point[] = [ 23 | { x: 0, y: 1 }, 24 | { x: -1, y: 0 }, 25 | { x: 0, y: -1 }, 26 | { x: 1, y: 0 }, 27 | ]; 28 | 29 | input.forEach((line) => { 30 | const [a, b, c] = line.split(" "); 31 | 32 | const dir = dirMap[parseInt(c.slice(-2, -1))]; 33 | const dist = parseInt(c.slice(-7, -2), 16); 34 | 35 | totalDistance += dist; 36 | loc = { x: loc.x + dist * dir.x, y: loc.y + dist * dir.y }; 37 | vertices.push(loc); 38 | }); 39 | 40 | const innerArea = shoelaceArea(vertices); 41 | 42 | // pick's for interior 43 | const interior = innerArea + 1 - Math.floor(totalDistance / 2); 44 | 45 | // add to exterior for final answer 46 | const answer = interior + totalDistance; 47 | 48 | console.log("ans", answer); 49 | -------------------------------------------------------------------------------- /18/example.txt: -------------------------------------------------------------------------------- 1 | R 6 (#70c710) 2 | D 5 (#0dc571) 3 | L 2 (#5713f0) 4 | D 2 (#d2c081) 5 | R 2 (#59c680) 6 | D 2 (#411b91) 7 | L 5 (#8ceee2) 8 | U 2 (#caa173) 9 | L 1 (#1b58a2) 10 | U 2 (#caa171) 11 | R 2 (#7807d2) 12 | U 3 (#a77fa3) 13 | L 2 (#015232) 14 | U 2 (#7a21e3) -------------------------------------------------------------------------------- /18/input.txt: -------------------------------------------------------------------------------- 1 | L 4 (#38ce32) 2 | U 3 (#55f513) 3 | L 6 (#46c2c2) 4 | U 3 (#2c5aa3) 5 | R 7 (#3137a2) 6 | U 4 (#3bc623) 7 | R 6 (#924a52) 8 | D 4 (#2880c3) 9 | R 7 (#924a50) 10 | U 6 (#639303) 11 | R 5 (#3137a0) 12 | U 3 (#6ada33) 13 | L 6 (#3f9e92) 14 | U 4 (#2f1fa3) 15 | R 6 (#471352) 16 | U 4 (#2fd2a3) 17 | L 5 (#09d272) 18 | U 4 (#213a13) 19 | L 6 (#78b222) 20 | U 3 (#2fc1a3) 21 | L 3 (#4cbb52) 22 | U 3 (#4ac623) 23 | R 4 (#70efe2) 24 | U 2 (#5eb1f3) 25 | R 5 (#70efe0) 26 | U 3 (#2bf113) 27 | L 6 (#1882e2) 28 | U 3 (#3fca23) 29 | R 4 (#62ba80) 30 | U 5 (#2c54c3) 31 | L 4 (#1dee90) 32 | U 6 (#73a233) 33 | R 5 (#2c7800) 34 | U 4 (#4ad3a3) 35 | L 7 (#4f8940) 36 | U 3 (#48d041) 37 | R 7 (#5221c0) 38 | U 4 (#75a591) 39 | R 2 (#03ec80) 40 | U 4 (#2c54c1) 41 | R 4 (#1bbc10) 42 | D 4 (#4f1b13) 43 | R 4 (#7f90f0) 44 | D 5 (#2752d3) 45 | R 4 (#1eae30) 46 | D 3 (#2a9653) 47 | L 6 (#36eb10) 48 | D 2 (#2a9651) 49 | L 2 (#454ad0) 50 | D 3 (#1557e3) 51 | R 3 (#7707d0) 52 | D 4 (#73c6b3) 53 | R 5 (#295690) 54 | D 6 (#24a233) 55 | R 3 (#7bc852) 56 | U 6 (#15b743) 57 | R 3 (#224732) 58 | U 4 (#4a0323) 59 | R 4 (#810412) 60 | U 7 (#5fba61) 61 | L 4 (#1c2ee2) 62 | U 4 (#6977f3) 63 | R 4 (#3ff1b0) 64 | U 6 (#8ee1f3) 65 | R 4 (#544e00) 66 | U 4 (#244c23) 67 | R 2 (#5bc1f0) 68 | U 4 (#1e5873) 69 | L 3 (#6420d2) 70 | U 4 (#836a83) 71 | R 6 (#6420d0) 72 | U 3 (#024693) 73 | L 6 (#0a2540) 74 | U 4 (#65eda3) 75 | L 2 (#2649e0) 76 | U 2 (#195ba3) 77 | L 4 (#74d120) 78 | U 3 (#795ca3) 79 | R 3 (#31c470) 80 | U 2 (#59afe3) 81 | R 6 (#873020) 82 | U 4 (#695263) 83 | L 9 (#1dc2b0) 84 | U 3 (#288a33) 85 | L 4 (#090860) 86 | D 8 (#00eb93) 87 | L 4 (#5de760) 88 | D 2 (#00eb91) 89 | L 3 (#5ae5c0) 90 | D 4 (#162813) 91 | L 3 (#182e50) 92 | D 5 (#5848f1) 93 | L 2 (#89c410) 94 | D 6 (#5848f3) 95 | L 4 (#549dc0) 96 | D 4 (#7e5a93) 97 | L 2 (#5ac572) 98 | U 4 (#39f613) 99 | L 4 (#300c42) 100 | U 3 (#2c94e1) 101 | R 6 (#68ae32) 102 | U 7 (#2c94e3) 103 | L 3 (#289422) 104 | U 5 (#06ded3) 105 | L 3 (#025d52) 106 | U 2 (#1c4373) 107 | L 5 (#21b252) 108 | U 4 (#8646d3) 109 | L 3 (#764a62) 110 | U 5 (#8646d1) 111 | L 6 (#6d5762) 112 | U 6 (#1c4371) 113 | R 3 (#3c7462) 114 | U 3 (#041483) 115 | R 4 (#01cab2) 116 | U 5 (#784883) 117 | R 3 (#60f6c2) 118 | U 6 (#057d73) 119 | R 2 (#1fb832) 120 | U 2 (#775953) 121 | R 4 (#3c9532) 122 | U 4 (#404733) 123 | R 7 (#2423b2) 124 | U 3 (#1eee81) 125 | R 7 (#797832) 126 | U 3 (#1eee83) 127 | R 4 (#220652) 128 | U 5 (#15f0b3) 129 | R 3 (#4c0d62) 130 | D 4 (#2083c3) 131 | R 4 (#1c5cf2) 132 | D 3 (#5f0f33) 133 | R 3 (#5494e2) 134 | D 5 (#684523) 135 | R 4 (#1202b2) 136 | U 9 (#455503) 137 | R 2 (#15d2a2) 138 | D 9 (#36e533) 139 | R 4 (#1c78a0) 140 | D 3 (#4bcc43) 141 | R 6 (#4baf50) 142 | D 3 (#66edf3) 143 | R 4 (#4baf52) 144 | D 4 (#222a23) 145 | L 9 (#1c78a2) 146 | D 2 (#043003) 147 | R 9 (#1d0a42) 148 | D 4 (#1e6941) 149 | R 5 (#3a6662) 150 | U 4 (#1df801) 151 | R 3 (#8b8d92) 152 | U 7 (#35c951) 153 | R 4 (#8b8d90) 154 | U 3 (#4d8771) 155 | R 3 (#1b5502) 156 | U 3 (#4a6233) 157 | R 5 (#71c6c2) 158 | D 4 (#408383) 159 | R 5 (#057732) 160 | U 4 (#076963) 161 | R 4 (#045692) 162 | U 6 (#4e80e1) 163 | R 3 (#5f77d2) 164 | U 3 (#114573) 165 | R 2 (#6c4b92) 166 | U 3 (#114571) 167 | L 8 (#07cc82) 168 | U 3 (#4e80e3) 169 | R 8 (#166fe2) 170 | U 4 (#924f11) 171 | R 3 (#496b52) 172 | U 2 (#912dc3) 173 | R 3 (#0e9052) 174 | D 3 (#2e8443) 175 | R 4 (#572312) 176 | D 4 (#31d0d3) 177 | L 5 (#745c00) 178 | D 5 (#058313) 179 | R 5 (#2847e0) 180 | D 3 (#5ba6c3) 181 | R 7 (#58b860) 182 | U 4 (#560193) 183 | R 4 (#5e3d90) 184 | U 7 (#36d363) 185 | R 6 (#02d030) 186 | D 7 (#49d633) 187 | R 4 (#4e03d2) 188 | U 4 (#8d4853) 189 | R 8 (#3b9d12) 190 | U 4 (#8d4851) 191 | R 5 (#302542) 192 | U 6 (#40e003) 193 | R 7 (#130d32) 194 | D 4 (#5323d1) 195 | R 6 (#4ed652) 196 | D 6 (#5323d3) 197 | R 4 (#541fd2) 198 | U 2 (#0f08e3) 199 | R 3 (#16bd42) 200 | U 5 (#603191) 201 | R 6 (#3545f2) 202 | U 3 (#011651) 203 | R 4 (#3ecb62) 204 | U 6 (#963781) 205 | R 5 (#2c7612) 206 | D 6 (#509971) 207 | R 6 (#885a52) 208 | D 6 (#3b0dd3) 209 | R 2 (#2afe62) 210 | D 4 (#1f4e53) 211 | R 3 (#2c0ab2) 212 | D 5 (#3be5a3) 213 | L 3 (#2c0ab0) 214 | D 4 (#55e5c3) 215 | L 7 (#2afe60) 216 | D 4 (#5bf153) 217 | L 5 (#617782) 218 | U 4 (#094123) 219 | L 4 (#5186f2) 220 | U 4 (#544353) 221 | L 3 (#40f5c2) 222 | D 3 (#325493) 223 | L 6 (#40b782) 224 | D 5 (#713cc3) 225 | L 4 (#3fdd60) 226 | D 8 (#0b87f3) 227 | L 5 (#41cfe0) 228 | D 3 (#340bf3) 229 | L 2 (#718d12) 230 | D 7 (#6a0d63) 231 | R 6 (#88f440) 232 | U 3 (#612011) 233 | R 2 (#4eb270) 234 | U 4 (#6f7821) 235 | R 5 (#077c50) 236 | U 6 (#209901) 237 | R 4 (#1eeaa0) 238 | D 3 (#1176f1) 239 | R 2 (#2b79f0) 240 | D 5 (#6cd941) 241 | R 5 (#72d3a0) 242 | D 3 (#25a453) 243 | R 3 (#09e140) 244 | D 3 (#7944e3) 245 | R 4 (#071320) 246 | U 9 (#540d61) 247 | R 2 (#63bb30) 248 | U 5 (#317753) 249 | R 3 (#5a9e00) 250 | D 5 (#056963) 251 | R 3 (#385080) 252 | D 3 (#75cda3) 253 | R 2 (#331280) 254 | D 7 (#23db43) 255 | R 2 (#11d3e2) 256 | D 3 (#2f8123) 257 | R 4 (#77eef2) 258 | D 3 (#2f8121) 259 | R 4 (#3c3e32) 260 | D 5 (#541c03) 261 | R 6 (#531fb0) 262 | D 3 (#43a463) 263 | R 3 (#2a8950) 264 | D 6 (#2a8193) 265 | R 3 (#078660) 266 | D 3 (#668ce3) 267 | R 3 (#640a50) 268 | D 3 (#64e5a3) 269 | R 5 (#961a02) 270 | D 6 (#492053) 271 | R 4 (#4d71d0) 272 | D 3 (#48f563) 273 | R 4 (#14d310) 274 | D 5 (#48f561) 275 | R 5 (#53be70) 276 | U 5 (#195313) 277 | R 3 (#0b2550) 278 | U 2 (#5fde13) 279 | R 2 (#7dbeb0) 280 | U 4 (#5fde11) 281 | R 6 (#145d90) 282 | U 4 (#34b771) 283 | R 6 (#834300) 284 | U 3 (#34b773) 285 | L 6 (#0387d0) 286 | U 4 (#469471) 287 | R 6 (#9406f0) 288 | U 6 (#469473) 289 | R 3 (#2a4d50) 290 | D 5 (#037633) 291 | R 7 (#14d340) 292 | D 6 (#11daf1) 293 | R 7 (#337f90) 294 | D 4 (#526051) 295 | R 4 (#757a30) 296 | D 8 (#643b43) 297 | R 3 (#1185a0) 298 | D 6 (#07f453) 299 | R 3 (#621c50) 300 | D 2 (#07f451) 301 | R 3 (#30dcf0) 302 | D 4 (#0a7101) 303 | L 4 (#08b2b0) 304 | D 3 (#0c9b51) 305 | L 2 (#1c5e10) 306 | D 7 (#6bf7c1) 307 | L 4 (#5702a0) 308 | D 2 (#6bf7c3) 309 | L 8 (#2d1240) 310 | D 5 (#5cf4e1) 311 | L 6 (#14c4d2) 312 | D 4 (#98b1f1) 313 | L 3 (#4b01e2) 314 | D 8 (#2711a1) 315 | L 2 (#4dca52) 316 | U 8 (#41b261) 317 | L 3 (#114f32) 318 | U 5 (#842761) 319 | L 6 (#3f4122) 320 | U 4 (#842763) 321 | L 3 (#4d3102) 322 | D 3 (#41b263) 323 | L 2 (#1118e2) 324 | D 5 (#59cc03) 325 | L 8 (#8b9742) 326 | D 2 (#65f793) 327 | R 8 (#328982) 328 | D 4 (#85c501) 329 | L 3 (#441702) 330 | D 5 (#0a1f51) 331 | L 8 (#2ccc92) 332 | D 3 (#52f541) 333 | L 6 (#5dfc42) 334 | D 5 (#52f543) 335 | L 4 (#1d83f2) 336 | D 6 (#5eeab1) 337 | R 4 (#4634e0) 338 | D 4 (#968ca1) 339 | L 3 (#437e40) 340 | D 7 (#968ca3) 341 | L 3 (#62b0a0) 342 | D 5 (#38aa71) 343 | L 5 (#3c8e22) 344 | U 5 (#7bb931) 345 | L 6 (#172202) 346 | U 3 (#809981) 347 | L 5 (#172200) 348 | D 4 (#0b1ac1) 349 | L 2 (#3c8e20) 350 | D 4 (#1d0d71) 351 | L 6 (#82ea50) 352 | D 2 (#373bd1) 353 | L 2 (#1ec200) 354 | D 7 (#471d01) 355 | R 6 (#3b6472) 356 | D 4 (#0273b3) 357 | R 3 (#2b4df2) 358 | D 2 (#0273b1) 359 | R 7 (#3af9f2) 360 | D 4 (#432781) 361 | R 6 (#161170) 362 | D 3 (#682741) 363 | L 6 (#5aee90) 364 | D 4 (#574c13) 365 | L 4 (#4c3770) 366 | D 2 (#5eadb3) 367 | R 4 (#3b4a30) 368 | D 5 (#5eadb1) 369 | L 3 (#4700c0) 370 | D 5 (#574c11) 371 | L 5 (#4569e0) 372 | D 5 (#250471) 373 | L 5 (#014740) 374 | D 4 (#61e5f1) 375 | L 3 (#772650) 376 | D 3 (#1e6f21) 377 | R 3 (#1d3220) 378 | D 6 (#430041) 379 | R 2 (#608810) 380 | D 6 (#341ae3) 381 | R 4 (#5bd730) 382 | U 6 (#3132d3) 383 | R 2 (#3fab42) 384 | U 6 (#90b273) 385 | R 4 (#3fab40) 386 | D 7 (#263173) 387 | R 4 (#5bd732) 388 | D 5 (#423813) 389 | R 5 (#6ba250) 390 | D 2 (#773ab1) 391 | R 5 (#37ed60) 392 | D 4 (#048871) 393 | L 10 (#4de780) 394 | D 3 (#185e81) 395 | R 3 (#40d660) 396 | D 6 (#5dd3d3) 397 | L 7 (#4d2210) 398 | U 3 (#364dd3) 399 | L 4 (#2208a0) 400 | U 7 (#13db53) 401 | L 4 (#1ff800) 402 | D 3 (#74fa63) 403 | L 8 (#5405c0) 404 | D 6 (#7a2ee3) 405 | L 2 (#4ac3c0) 406 | D 3 (#30c2e3) 407 | L 2 (#15a070) 408 | D 6 (#0cac13) 409 | L 5 (#495b10) 410 | U 8 (#8c3253) 411 | L 3 (#495b12) 412 | U 2 (#2b5c03) 413 | L 5 (#1bbdb0) 414 | U 8 (#203f53) 415 | L 3 (#57a1e2) 416 | U 3 (#5032f3) 417 | L 4 (#57a1e0) 418 | U 6 (#327c63) 419 | R 4 (#50a820) 420 | U 4 (#2b3343) 421 | L 3 (#7014d0) 422 | U 4 (#12bef3) 423 | L 3 (#656f40) 424 | U 4 (#2dc663) 425 | L 6 (#113020) 426 | U 4 (#3a26d3) 427 | L 5 (#133f60) 428 | U 8 (#024a51) 429 | L 2 (#584c70) 430 | U 3 (#024a53) 431 | L 4 (#364750) 432 | U 4 (#3a26d1) 433 | L 3 (#023e50) 434 | U 6 (#07ffd3) 435 | R 6 (#6a4610) 436 | U 3 (#0a1a53) 437 | R 4 (#1d5f72) 438 | U 4 (#3dc7a3) 439 | L 10 (#43bdc0) 440 | U 3 (#2c8853) 441 | L 8 (#43bdc2) 442 | U 6 (#646bb3) 443 | R 6 (#1d5f70) 444 | U 7 (#2d4373) 445 | R 3 (#8264e0) 446 | U 5 (#35f151) 447 | R 4 (#2b1760) 448 | U 4 (#999c03) 449 | R 3 (#4175f0) 450 | D 8 (#999c01) 451 | R 5 (#3c0e70) 452 | D 2 (#32a5e1) 453 | R 3 (#1b64a0) 454 | D 6 (#261bc1) 455 | R 3 (#0b6c22) 456 | U 2 (#2d3081) 457 | R 4 (#72b8a2) 458 | U 4 (#236cb1) 459 | R 6 (#45dba2) 460 | U 4 (#209921) 461 | L 6 (#128470) 462 | U 6 (#4d6b01) 463 | L 2 (#190550) 464 | U 3 (#40f381) 465 | L 7 (#804a40) 466 | U 4 (#1accd1) 467 | L 4 (#5d9a40) 468 | U 2 (#042311) 469 | L 6 (#1fa392) 470 | U 3 (#3b7471) 471 | L 3 (#565ac2) 472 | U 5 (#3b7473) 473 | L 7 (#4c7822) 474 | U 7 (#47ab31) 475 | L 3 (#184fa2) 476 | U 7 (#417391) 477 | L 4 (#4cffd2) 478 | U 3 (#3bf361) 479 | L 3 (#84fdd0) 480 | D 7 (#178953) 481 | L 2 (#5ddab0) 482 | D 3 (#178951) 483 | L 5 (#44ed60) 484 | D 5 (#6eb101) 485 | L 3 (#455aa0) 486 | U 4 (#231db1) 487 | L 8 (#2511b0) 488 | U 4 (#886b31) 489 | R 4 (#2511b2) 490 | U 3 (#36b861) 491 | R 4 (#421320) 492 | U 4 (#267471) 493 | L 3 (#43b980) 494 | U 3 (#214141) 495 | R 3 (#2491c0) 496 | U 2 (#214143) 497 | R 7 (#4ae330) 498 | U 3 (#4c5d41) 499 | R 8 (#1897d0) 500 | D 5 (#39eba1) 501 | R 5 (#6c3442) 502 | D 7 (#439aa1) 503 | R 4 (#652a42) 504 | U 7 (#5437e1) 505 | R 3 (#3c7ae2) 506 | U 6 (#3653c1) 507 | L 5 (#6b4d52) 508 | U 4 (#5cb7f1) 509 | L 3 (#073a02) 510 | U 5 (#360581) 511 | L 3 (#6d9fd2) 512 | U 7 (#7901a1) 513 | L 2 (#123b32) 514 | U 3 (#4b1f83) 515 | L 4 (#2d6582) 516 | U 10 (#342933) 517 | R 4 (#538792) 518 | U 5 (#263fd3) 519 | L 5 (#0a3c42) 520 | D 2 (#433c41) 521 | L 3 (#4c3042) 522 | D 5 (#35f621) 523 | L 6 (#42f670) 524 | D 6 (#466371) 525 | R 6 (#42f672) 526 | D 7 (#6248a1) 527 | L 2 (#670152) 528 | D 5 (#90e203) 529 | L 5 (#4495b2) 530 | U 4 (#90fc73) 531 | L 2 (#5707b2) 532 | U 8 (#4c76e1) 533 | L 4 (#540512) 534 | U 3 (#492111) 535 | R 4 (#540510) 536 | U 6 (#0ff091) 537 | L 4 (#2b4272) 538 | U 5 (#05b161) 539 | L 3 (#7483e2) 540 | D 6 (#6b3f11) 541 | L 3 (#480342) 542 | D 6 (#307111) 543 | L 5 (#0f29d2) 544 | D 6 (#019f91) 545 | L 6 (#342822) 546 | D 4 (#180cb1) 547 | R 8 (#00f720) 548 | D 4 (#31b091) 549 | L 8 (#2f1380) 550 | D 3 (#4ab461) 551 | L 6 (#2194c0) 552 | U 5 (#6bee03) 553 | L 5 (#65f3b0) 554 | U 8 (#1076f3) 555 | L 3 (#1c34c0) 556 | U 3 (#1151c1) 557 | R 6 (#0bed40) 558 | U 3 (#3db921) 559 | L 4 (#4e4190) 560 | U 2 (#674151) 561 | L 2 (#2f95c0) 562 | U 8 (#097d01) 563 | L 3 (#4f5a20) 564 | D 2 (#69a8c1) 565 | L 2 (#04b560) 566 | D 3 (#2ca343) 567 | L 4 (#70ccd0) 568 | D 5 (#6c7323) 569 | R 4 (#377f50) 570 | D 4 (#3ae061) 571 | L 2 (#5883f0) 572 | D 6 (#5e3601) 573 | L 2 (#27eb00) 574 | D 7 (#6fffc3) 575 | L 4 (#06e992) 576 | D 4 (#43dee3) 577 | L 4 (#06e990) 578 | D 4 (#759353) 579 | L 6 (#7da150) 580 | D 5 (#5f0761) 581 | R 5 (#0ec360) 582 | D 3 (#4b82f1) 583 | R 3 (#400b40) 584 | D 3 (#72f301) 585 | R 4 (#288900) 586 | D 3 (#4b0f11) 587 | R 8 (#288902) 588 | D 4 (#471d21) 589 | L 8 (#708912) 590 | D 4 (#2264e1) 591 | R 4 (#708910) 592 | D 6 (#3c2e31) 593 | R 2 (#23e370) 594 | D 2 (#6e40f1) 595 | R 4 (#2ccbc0) 596 | U 9 (#51a4c1) 597 | R 4 (#1e2560) 598 | D 9 (#1dafa1) 599 | R 3 (#44ac70) 600 | D 5 (#028461) 601 | R 9 (#3d9be0) 602 | D 4 (#929d31) 603 | L 6 (#5e7b02) 604 | D 6 (#559df1) 605 | L 8 (#5e7b00) 606 | D 4 (#48ec01) 607 | L 5 (#93cfe2) 608 | D 8 (#1cafe1) 609 | L 4 (#0459f2) 610 | U 8 (#724081) 611 | L 4 (#47c962) 612 | D 4 (#5e74e1) 613 | L 3 (#495f80) 614 | D 5 (#7299e1) 615 | L 5 (#495f82) 616 | D 5 (#045f61) 617 | R 7 (#47c960) 618 | D 3 (#2335f1) 619 | R 6 (#499fd2) 620 | D 6 (#43b841) 621 | R 6 (#031222) 622 | D 6 (#48f681) 623 | L 5 (#727da2) 624 | D 4 (#41d7e1) 625 | R 5 (#113942) 626 | D 5 (#03ee33) 627 | R 4 (#0350c2) 628 | D 2 (#4727a3) 629 | R 4 (#148620) 630 | D 4 (#33d453) 631 | R 8 (#148622) 632 | D 3 (#210703) 633 | L 3 (#1c3d42) 634 | D 3 (#19c743) 635 | L 7 (#3991b2) 636 | D 4 (#4fb431) 637 | L 3 (#0563c2) 638 | D 4 (#6a0431) 639 | L 5 (#592952) 640 | D 6 (#0898b1) 641 | L 4 (#1f2f32) 642 | D 6 (#42ac11) 643 | L 3 (#045bb2) 644 | D 5 (#62d0c1) 645 | L 6 (#84e602) 646 | D 2 (#68e891) 647 | L 6 (#2c8512) 648 | D 5 (#16e5c1) 649 | L 5 (#2dc202) 650 | U 3 (#08e561) 651 | L 2 (#1d84c0) 652 | U 8 (#64b671) 653 | L 4 (#1d84c2) 654 | U 3 (#2d4741) 655 | L 4 (#5342c2) 656 | D 3 (#012ce1) 657 | L 6 (#229ca2) 658 | D 3 (#5d0f51) 659 | L 2 (#6f27a2) 660 | D 5 (#3102b1) 661 | L 2 (#39f292) 662 | D 3 (#0e1d31) 663 | L 4 (#1fe602) 664 | U 6 (#1fbbb1) 665 | L 6 (#001c52) 666 | U 3 (#880b71) 667 | L 4 (#001c50) 668 | U 7 (#12db41) 669 | L 2 (#2d7072) 670 | U 3 (#941843) 671 | R 8 (#255d72) 672 | U 3 (#0ac063) 673 | L 5 (#481670) 674 | U 4 (#7f2aa3) 675 | L 5 (#481672) 676 | U 3 (#379e93) 677 | L 4 (#255d70) 678 | U 5 (#025ca3) 679 | R 3 (#958792) 680 | U 2 (#258701) 681 | R 5 (#32e690) 682 | D 4 (#6c9431) 683 | R 2 (#32e692) 684 | U 4 (#850cf1) 685 | R 4 (#1f6942) 686 | U 4 (#8dc581) 687 | L 8 (#5949e2) 688 | U 3 (#62cf01) 689 | R 3 (#930cf2) 690 | U 2 (#014781) 691 | R 5 (#39d8b2) 692 | U 4 (#9a50e1) 693 | R 2 (#4e2032) 694 | D 4 (#1129e1) 695 | R 4 (#68c522) 696 | U 5 (#030c91) 697 | R 6 (#46e632) 698 | U 3 (#54c0c1) 699 | R 3 (#1104c2) 700 | U 6 (#3b3a11) 701 | L 7 (#72ea42) 702 | U 7 (#5eaf41) 703 | L 3 (#140192) 704 | D 4 (#05dbd1) 705 | L 2 (#507802) 706 | D 2 (#05dbd3) 707 | L 7 (#732442) 708 | U 6 (#144931) 709 | L 4 (#2e2f92) 710 | U 7 (#29bd33) 711 | L 4 (#1b1ca2) 712 | U 4 (#89f183) -------------------------------------------------------------------------------- /19/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n\n"); 3 | 4 | const [rulesIn, messagesIn] = input; 5 | 6 | type Rule = 7 | | { min: number; max: number; variable: string; destination: string } 8 | | { destination: string }; 9 | const rules: Record = {}; 10 | 11 | rulesIn.split("\n").forEach((rule) => { 12 | const [id, ruleString] = rule.split("{"); 13 | const steps = ruleString.replace("}", "").split(","); 14 | // format example: rr{s>898:A,s>537:A,a<2567:R,A} 15 | const ruleSet: Rule[] = steps.map((step) => { 16 | if (step.includes(":")) { 17 | const [ins, destination] = step.split(":"); 18 | 19 | if (ins.includes("<")) { 20 | const [variable, max] = ins.split("<"); 21 | return { 22 | min: -Infinity, 23 | max: parseInt(max), 24 | variable, 25 | destination, 26 | }; 27 | } else if (ins.includes(">")) { 28 | const [variable, min] = ins.split(">"); 29 | return { 30 | min: parseInt(min), 31 | max: Infinity, 32 | variable, 33 | destination, 34 | }; 35 | } else { 36 | throw new Error("should not happen"); 37 | } 38 | } else { 39 | return { destination: step }; 40 | } 41 | }); 42 | 43 | rules[id] = ruleSet; 44 | }); 45 | console.log("rules?", rules); 46 | 47 | // console.log("input?", messagesIn); 48 | 49 | const inParsed: Record[] = messagesIn 50 | .split("\n") 51 | .map((message) => { 52 | // current format: 53 | // {x=4,m=211,a=430,s=167} 54 | // Desired as JSON object 55 | const json = message 56 | .replace(/{/g, '{"') 57 | .replace(/}/g, "}") 58 | .replace(/=/g, '":') 59 | .replace(/,/g, ',"'); 60 | return JSON.parse(json); 61 | }); 62 | 63 | console.log("inParsed?", inParsed); 64 | 65 | const validMessages = inParsed.filter((message) => { 66 | console.log("message", message); 67 | let currentRule = "in"; 68 | while (currentRule !== "R" && currentRule !== "A") { 69 | const cr = rules[currentRule]; 70 | 71 | console.log("cr", currentRule, cr); 72 | const rule = cr.find((rule) => { 73 | if ("min" in rule) { 74 | const value = message[rule.variable]; 75 | return rule.min < value && rule.max > value; 76 | } else { 77 | return true; 78 | } 79 | }); 80 | 81 | if (!rule) throw new Error("no rule found"); 82 | 83 | currentRule = rule.destination; 84 | } 85 | 86 | if (currentRule === "A") { 87 | return true; 88 | } 89 | }); 90 | 91 | console.log("valid?", validMessages); 92 | 93 | // sum all values from a message 94 | function sumMessage(message: Record) { 95 | return Object.values(message).reduce((acc, value) => { 96 | return acc + value; 97 | }, 0); 98 | } 99 | 100 | // add all values for all valid messages 101 | const sum = validMessages.reduce((acc, message) => { 102 | return acc + sumMessage(message); 103 | }, 0); 104 | 105 | console.log("sum", sum); 106 | -------------------------------------------------------------------------------- /19/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n\n"); 3 | 4 | const [rulesIn, messagesIn] = input; 5 | 6 | interface Constraint { 7 | lower?: string; 8 | upper?: string; 9 | } 10 | 11 | type Constraints = Constraint[]; 12 | 13 | type Rule = 14 | | { min: number; max: number; variable: string; destination: string } 15 | | { destination: string }; 16 | const rules: Record = {}; 17 | 18 | rulesIn.split("\n").forEach((rule) => { 19 | const [id, ruleString] = rule.split("{"); 20 | const steps = ruleString.replace("}", "").split(","); 21 | // format example: rr{s>898:A,s>537:A,a<2567:R,A} 22 | const ruleSet: Rule[] = steps.map((step) => { 23 | if (step.includes(":")) { 24 | const [ins, destination] = step.split(":"); 25 | 26 | if (ins.includes("<")) { 27 | const [variable, max] = ins.split("<"); 28 | return { 29 | min: -Infinity, 30 | max: parseInt(max), 31 | variable, 32 | destination, 33 | }; 34 | } else if (ins.includes(">")) { 35 | const [variable, min] = ins.split(">"); 36 | return { 37 | min: parseInt(min), 38 | max: Infinity, 39 | variable, 40 | destination, 41 | }; 42 | } else { 43 | throw new Error("should not happen"); 44 | } 45 | } else { 46 | return { destination: step }; 47 | } 48 | }); 49 | 50 | rules[id] = ruleSet; 51 | }); 52 | 53 | function checkPathWithRange(ins: string, ranges: number[][]): number { 54 | if (ins === "R") return 0; 55 | if (ins === "A") return ranges.reduce((acc, curr) => acc * curr.length, 1); 56 | 57 | const entry = rules[ins]; 58 | const pathVals = entry.map((rule) => { 59 | if (!("min" in rule)) return checkPathWithRange(rule.destination, ranges); 60 | 61 | const newRanges = ranges.map((arr) => [...arr]); 62 | const index = "xmas".indexOf(rule.variable); 63 | 64 | const check = (x: number) => rule.max > x && x > rule.min; 65 | 66 | newRanges[index] = newRanges[index].filter(check); 67 | ranges[index] = ranges[index].filter((x) => !check(x)); 68 | 69 | return checkPathWithRange(rule.destination, newRanges); 70 | }); 71 | 72 | return pathVals.reduce((acc, curr) => acc + curr, 0); 73 | } 74 | 75 | const answer = checkPathWithRange( 76 | "in", 77 | Array(4) 78 | .fill(null) 79 | .map(() => Array.from({ length: 4000 }, (_, i) => i + 1)) 80 | ); 81 | 82 | console.log("answer", answer); 83 | -------------------------------------------------------------------------------- /19/example.txt: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} -------------------------------------------------------------------------------- /2/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | 3 | function defaultCounts() { 4 | return { 5 | red: 12, 6 | green: 13, 7 | blue: 14, 8 | }; 9 | } 10 | 11 | const parsedPairs = input.map((line, i) => { 12 | const [, row] = line.split(": "); 13 | 14 | let counts = defaultCounts(); 15 | 16 | let valid = true; 17 | 18 | const textGroups = row 19 | .split("; ") 20 | .map((g) => g.split(", ").map((p) => p.split(" "))); 21 | 22 | textGroups.forEach((round) => { 23 | round.forEach(([count, color]) => { 24 | counts[color] = counts[color] - Number(count); 25 | }); 26 | const isInvalid = Object.values(counts).some((c) => c < 0); 27 | if (isInvalid) { 28 | valid = false; 29 | } 30 | counts = defaultCounts(); 31 | }); 32 | 33 | // check no counts are below 0 34 | 35 | return { 36 | row: i + 1, 37 | isInvalid: !valid, 38 | counts, 39 | }; 40 | }); 41 | 42 | // sum of valid row numbers 43 | const validRows = parsedPairs.filter((p) => !p.isInvalid); 44 | const validRowNumbers = validRows.map((p) => p.row); 45 | const sum = validRowNumbers.reduce((a, b) => a + b, 0); 46 | 47 | console.log(sum); 48 | -------------------------------------------------------------------------------- /2/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | 3 | function defaultCounts() { 4 | return { 5 | red: 0, 6 | green: 0, 7 | blue: 0, 8 | }; 9 | } 10 | 11 | const parsedPairs = input.map((line, i) => { 12 | const [, row] = line.split(": "); 13 | 14 | const counts = defaultCounts(); 15 | 16 | const textGroups = row 17 | .split("; ") 18 | .map((g) => g.split(", ").map((p) => p.split(" "))); 19 | 20 | textGroups.forEach((round) => { 21 | round.forEach(([count, color]) => { 22 | if (counts[color] < Number(count)) { 23 | counts[color] = Number(count); 24 | } 25 | }); 26 | }); 27 | 28 | // check no counts are below 0 29 | 30 | const product = Object.values(counts).reduce((a, b) => a * b, 1); 31 | console.log("PRODUCT", product); 32 | return { 33 | product, 34 | }; 35 | }); 36 | 37 | // sum of valid row numbers 38 | const validRowNumbers = parsedPairs.map((p) => p.product); 39 | const sum = validRowNumbers.reduce((a, b) => a + b, 0); 40 | 41 | console.log(sum); 42 | -------------------------------------------------------------------------------- /2/input.txt: -------------------------------------------------------------------------------- 1 | Game 1: 2 red, 2 green; 6 red, 3 green; 2 red, 1 green, 2 blue; 1 red 2 | Game 2: 2 green; 15 red, 5 blue; 2 green, 4 blue, 5 red; 3 green, 6 blue, 6 red; 6 blue, 1 green 3 | Game 3: 10 blue, 8 red, 5 green; 5 green, 3 red; 12 red, 2 green, 9 blue; 6 green, 11 red 4 | Game 4: 2 green, 3 blue, 1 red; 17 green, 1 blue, 1 red; 1 green, 5 red 5 | Game 5: 4 green, 13 red, 3 blue; 14 blue, 5 green, 5 red; 2 blue, 7 green, 3 red; 5 green, 11 blue, 10 red 6 | Game 6: 1 green, 4 red; 1 blue, 19 red, 5 green; 15 red, 1 green, 1 blue; 8 green, 12 red; 19 green, 7 red; 2 blue, 14 red, 12 green 7 | Game 7: 1 blue, 3 red, 3 green; 4 green; 1 blue, 6 red, 5 green 8 | Game 8: 1 green; 1 green, 16 red, 1 blue; 3 red, 1 green, 1 blue; 1 green; 2 blue; 9 red 9 | Game 9: 5 green, 1 red; 6 red, 4 blue, 1 green; 9 green, 7 red, 6 blue; 11 red, 12 green, 4 blue 10 | Game 10: 12 green, 4 blue, 7 red; 6 blue, 2 red; 7 green, 6 blue, 6 red 11 | Game 11: 18 green, 2 red; 19 green, 14 red, 9 blue; 8 blue, 12 red, 5 green; 4 green, 12 red; 14 red, 7 green, 10 blue 12 | Game 12: 8 red, 4 blue; 4 green, 1 red, 2 blue; 1 blue, 11 green, 12 red 13 | Game 13: 5 green, 4 blue, 4 red; 4 red, 5 blue, 2 green; 1 red, 5 blue, 10 green 14 | Game 14: 14 red, 1 green; 2 green, 3 blue, 7 red; 2 red, 4 blue; 3 green, 8 red, 4 blue; 2 green, 14 red, 4 blue; 3 green, 9 red, 6 blue 15 | Game 15: 17 blue, 5 red, 1 green; 1 green, 2 red; 3 red, 2 green; 11 blue, 4 red, 2 green 16 | Game 16: 5 red, 5 green, 1 blue; 5 blue, 15 red, 13 green; 3 blue, 6 red, 12 green; 1 green, 13 red, 9 blue; 15 blue, 13 green, 6 red; 5 green, 7 red, 3 blue 17 | Game 17: 17 red, 9 blue; 19 red, 9 blue, 2 green; 18 red, 1 green, 8 blue; 10 blue, 2 red, 1 green; 7 red, 5 blue, 1 green; 2 green, 2 red, 5 blue 18 | Game 18: 1 blue, 9 green, 1 red; 8 green, 5 blue; 4 blue, 9 green; 1 red, 6 green; 3 green, 3 blue, 1 red; 1 red, 1 blue, 4 green 19 | Game 19: 3 blue, 3 red; 1 blue, 2 red, 4 green; 4 green, 2 red; 7 blue, 1 red 20 | Game 20: 1 blue, 2 red, 6 green; 4 red, 10 green, 5 blue; 7 green, 1 blue; 3 green, 10 red, 1 blue; 3 blue, 11 red, 2 green; 10 green, 1 blue, 11 red 21 | Game 21: 1 green, 17 blue, 8 red; 13 green, 8 blue, 7 red; 7 blue, 10 green, 2 red 22 | Game 22: 4 green, 13 blue; 13 blue, 10 green; 8 green, 12 blue, 3 red; 6 green, 3 blue, 3 red 23 | Game 23: 11 green, 7 red; 11 blue, 11 red; 12 green, 3 red; 7 red, 7 green, 15 blue; 10 green, 5 blue 24 | Game 24: 1 blue, 15 green, 6 red; 2 red, 1 blue, 5 green; 13 green, 1 blue, 7 red; 1 blue; 19 green, 1 blue, 12 red; 13 green, 1 blue, 2 red 25 | Game 25: 15 green, 1 blue, 2 red; 9 green, 5 blue; 16 green, 4 red; 3 blue, 2 red, 7 green 26 | Game 26: 5 blue, 1 red; 9 blue, 1 green, 1 red; 1 red, 1 green, 4 blue 27 | Game 27: 3 red, 4 blue, 2 green; 2 red, 3 blue; 1 blue, 1 red, 5 green 28 | Game 28: 1 red, 3 green, 6 blue; 5 red, 2 blue, 3 green; 6 green, 4 red 29 | Game 29: 8 green, 6 red, 18 blue; 18 blue, 2 green, 8 red; 2 red, 14 blue, 2 green; 2 red, 4 green, 19 blue; 11 green, 9 red, 8 blue 30 | Game 30: 9 red, 11 blue, 6 green; 4 red, 6 green, 1 blue; 13 blue, 1 red, 1 green; 7 red, 1 green, 1 blue 31 | Game 31: 11 red, 3 green; 3 green, 2 red; 6 red, 4 green; 4 blue, 9 red; 4 green, 2 red, 3 blue; 2 red, 1 blue, 6 green 32 | Game 32: 4 red, 16 blue, 12 green; 10 blue, 7 green, 3 red; 7 blue, 4 green; 1 green, 8 blue, 3 red 33 | Game 33: 6 green, 2 blue, 2 red; 1 red, 3 green, 7 blue; 9 blue, 1 green; 10 blue, 1 green, 1 red; 8 blue, 4 red, 6 green; 1 green, 2 red, 7 blue 34 | Game 34: 4 blue, 6 red; 7 red, 5 green, 3 blue; 2 blue, 1 red; 5 blue, 2 green 35 | Game 35: 8 green, 1 blue; 12 blue; 6 green, 13 blue; 9 blue, 4 green; 5 green, 1 red, 7 blue; 5 blue, 1 red, 6 green 36 | Game 36: 10 red, 4 blue, 6 green; 15 blue, 1 green, 2 red; 16 red, 14 blue, 2 green 37 | Game 37: 3 green, 1 red, 2 blue; 5 blue, 2 green, 4 red; 2 red, 3 green; 4 blue, 4 red, 1 green; 3 red, 4 blue, 3 green 38 | Game 38: 9 red, 1 green, 16 blue; 1 green, 4 blue, 1 red; 10 blue, 1 red, 1 green; 3 red, 17 blue; 7 blue, 5 red 39 | Game 39: 9 red, 16 blue, 3 green; 8 green, 3 red, 3 blue; 8 blue, 13 red, 1 green; 3 red, 17 blue, 3 green; 11 blue, 9 red, 3 green 40 | Game 40: 4 blue, 2 green, 8 red; 3 blue; 7 blue 41 | Game 41: 3 blue, 10 green, 7 red; 1 blue; 8 green, 4 blue, 1 red; 8 green, 7 red, 4 blue 42 | Game 42: 6 green, 5 blue, 1 red; 5 blue, 2 red, 6 green; 1 green, 3 red, 3 blue; 1 red, 1 blue, 8 green; 2 red, 10 green; 4 red, 6 green 43 | Game 43: 12 blue, 9 green, 9 red; 8 blue, 6 red, 2 green; 1 green, 8 blue, 12 red; 15 blue, 5 green, 13 red; 15 blue, 7 green, 8 red; 16 blue, 11 red, 8 green 44 | Game 44: 4 green, 16 blue, 1 red; 5 green, 1 blue; 1 blue, 1 green; 11 blue, 1 red, 3 green; 10 blue, 1 red; 15 blue, 1 red, 3 green 45 | Game 45: 12 blue, 6 green, 9 red; 5 red, 6 blue, 2 green; 4 blue, 5 green, 5 red; 2 green, 6 blue, 8 red; 9 red, 7 green, 7 blue 46 | Game 46: 7 blue, 1 red; 1 green, 2 blue, 2 red; 3 red 47 | Game 47: 10 blue, 11 green, 1 red; 10 green; 4 red, 6 blue, 16 green; 20 green, 2 blue; 1 green, 3 red, 6 blue; 4 red, 5 blue, 13 green 48 | Game 48: 1 red, 4 blue, 3 green; 20 blue, 1 red, 8 green; 1 red, 12 green, 12 blue 49 | Game 49: 5 green, 8 red, 2 blue; 2 blue, 2 red, 1 green; 3 red, 3 blue; 3 blue, 12 green 50 | Game 50: 7 green, 8 red; 2 blue, 6 green; 1 green, 1 blue, 7 red 51 | Game 51: 19 red, 13 blue, 4 green; 9 green, 10 red, 2 blue; 2 green, 20 red; 20 red, 2 green; 6 green, 10 blue, 5 red 52 | Game 52: 1 red, 13 green; 11 green; 15 green; 1 red, 9 green, 1 blue 53 | Game 53: 7 blue, 3 green; 1 red, 6 blue, 6 green; 7 blue, 1 red, 6 green 54 | Game 54: 12 red, 1 green; 14 red, 10 green; 1 green, 7 red, 4 blue 55 | Game 55: 1 blue, 5 green, 3 red; 3 green, 4 red; 6 red, 1 blue, 4 green 56 | Game 56: 5 red, 1 blue, 2 green; 6 green; 4 red, 6 green; 6 green, 2 blue, 2 red; 4 red, 2 green, 2 blue; 4 red, 2 blue 57 | Game 57: 6 green, 3 blue; 8 blue, 6 green, 5 red; 5 red, 2 green, 12 blue; 5 red, 7 green, 5 blue 58 | Game 58: 2 blue, 1 red, 4 green; 1 red, 14 green; 2 green, 2 blue, 1 red 59 | Game 59: 10 red, 11 blue, 6 green; 2 blue, 8 green; 1 green, 5 blue, 15 red; 3 red, 7 blue, 9 green; 9 green, 9 blue, 14 red; 8 green, 13 blue, 15 red 60 | Game 60: 1 blue, 11 red, 7 green; 7 red, 3 blue; 16 red, 3 blue, 2 green; 2 red, 9 green, 2 blue; 2 blue, 8 red, 9 green; 15 red, 1 blue, 9 green 61 | Game 61: 8 green, 15 blue; 16 blue, 1 green; 1 green, 11 blue; 1 green, 9 blue, 1 red; 8 green, 9 blue; 8 blue, 15 green 62 | Game 62: 5 green, 4 blue; 1 blue, 2 green; 1 red, 16 green, 2 blue; 1 blue, 16 green, 1 red; 13 green, 2 blue 63 | Game 63: 1 red, 1 blue; 1 green, 1 red; 1 green; 1 green, 2 red; 1 blue; 2 red 64 | Game 64: 5 red, 1 blue, 5 green; 10 red, 4 green, 2 blue; 8 red, 1 blue 65 | Game 65: 1 red, 8 green, 10 blue; 11 blue, 5 green, 1 red; 2 red, 5 blue, 1 green; 8 green, 7 blue 66 | Game 66: 5 red, 1 green; 1 blue, 7 red; 4 red, 15 green, 1 blue; 8 red, 4 green; 1 blue, 15 green, 3 red 67 | Game 67: 15 green, 7 blue, 1 red; 8 green, 7 blue; 5 blue, 1 red, 4 green; 2 green, 9 blue; 1 red, 6 blue 68 | Game 68: 14 green, 17 red; 1 red, 2 blue, 17 green; 10 green; 3 red, 7 green, 2 blue 69 | Game 69: 8 green, 12 red, 11 blue; 8 red, 2 blue, 10 green; 2 green, 6 blue, 2 red; 10 red, 12 green, 3 blue 70 | Game 70: 2 blue, 8 green; 9 green; 2 red; 2 red, 5 green; 3 green, 2 blue, 3 red; 4 red, 1 blue 71 | Game 71: 3 green, 4 blue; 13 red, 13 blue; 4 green, 3 red, 1 blue; 1 green, 7 blue, 3 red; 3 green, 9 blue, 13 red; 10 red, 12 blue, 5 green 72 | Game 72: 4 green, 17 red, 4 blue; 4 green, 2 blue; 1 red, 10 blue, 1 green; 3 green; 2 blue, 15 red, 3 green; 6 red, 10 blue 73 | Game 73: 14 green, 9 red, 6 blue; 10 red, 4 green, 7 blue; 9 green, 5 red, 6 blue; 6 red, 2 blue; 5 blue, 7 red, 14 green; 4 green, 6 blue, 5 red 74 | Game 74: 19 blue, 7 green, 1 red; 12 blue, 11 green, 1 red; 2 red, 5 blue, 14 green; 5 green, 5 blue, 7 red 75 | Game 75: 12 green, 5 blue, 12 red; 17 green, 10 red, 7 blue; 1 blue, 8 red, 1 green; 11 red, 10 green, 4 blue; 1 blue, 10 green; 1 green, 5 blue, 7 red 76 | Game 76: 9 green, 2 red, 3 blue; 6 red, 13 green, 5 blue; 14 green, 9 red, 2 blue; 1 blue, 6 red, 2 green; 8 red, 10 green, 1 blue; 2 red, 15 green, 7 blue 77 | Game 77: 5 blue, 2 green, 1 red; 4 blue, 14 red; 3 blue, 1 green, 8 red; 13 red, 8 blue; 17 blue, 2 green, 9 red; 11 blue, 1 green 78 | Game 78: 5 blue, 4 green, 4 red; 1 red, 9 green, 4 blue; 8 green 79 | Game 79: 5 blue, 6 red; 2 blue, 1 green, 9 red; 3 green; 8 red, 1 green, 5 blue; 2 green, 5 red 80 | Game 80: 1 green, 2 blue, 8 red; 9 green, 12 red; 17 green, 8 red, 11 blue 81 | Game 81: 8 red, 11 green, 13 blue; 9 red, 14 blue, 14 green; 14 blue, 11 green, 1 red; 5 red, 13 green, 3 blue; 4 green, 9 red, 2 blue; 11 red, 5 blue, 2 green 82 | Game 82: 13 green, 2 red, 1 blue; 10 green, 2 blue; 2 blue, 11 green; 4 red, 1 green, 3 blue; 14 green, 1 blue, 2 red 83 | Game 83: 6 blue, 2 red; 3 blue, 11 red, 1 green; 12 red, 1 green, 1 blue; 2 red; 10 red, 6 blue 84 | Game 84: 1 green, 13 blue, 2 red; 4 red, 17 blue, 18 green; 17 green, 13 blue, 4 red; 4 blue, 15 green, 3 red; 3 red; 15 blue, 1 red, 12 green 85 | Game 85: 11 green, 7 red; 7 green, 4 blue, 6 red; 8 red, 7 blue, 2 green; 11 green, 10 red, 3 blue 86 | Game 86: 10 green, 5 blue; 4 blue, 7 red, 16 green; 8 red, 1 blue, 12 green 87 | Game 87: 7 red, 3 green; 1 blue, 5 red, 14 green; 13 red, 4 green; 19 green, 9 red; 12 green, 1 red 88 | Game 88: 5 red, 16 blue; 2 green, 14 blue, 1 red; 14 blue, 1 green 89 | Game 89: 1 green, 2 blue, 1 red; 10 blue; 4 blue; 2 green, 14 blue; 14 blue, 1 red, 2 green 90 | Game 90: 1 blue, 13 green, 1 red; 4 blue, 1 red, 17 green; 9 green, 7 blue, 5 red; 1 blue, 3 red, 15 green; 3 red, 4 blue, 15 green 91 | Game 91: 1 green; 9 green, 2 red, 2 blue; 3 blue, 12 green, 1 red; 2 red, 1 blue, 6 green 92 | Game 92: 1 green, 4 blue, 10 red; 12 blue, 9 red, 3 green; 10 blue, 8 red, 2 green 93 | Game 93: 7 blue, 5 red; 2 green, 1 blue, 6 red; 1 blue, 6 red 94 | Game 94: 8 red, 3 green, 8 blue; 3 red, 1 green, 4 blue; 4 green, 17 blue, 2 red; 2 green, 9 red, 7 blue; 13 red, 4 green, 18 blue 95 | Game 95: 9 blue, 11 green; 14 green, 10 blue, 11 red; 13 blue, 10 green, 1 red; 6 red, 4 green, 1 blue; 9 blue, 13 green 96 | Game 96: 3 red, 3 green; 16 green, 2 blue; 7 blue, 3 red, 16 green; 10 green, 1 red 97 | Game 97: 4 red, 6 blue; 2 red; 13 red, 6 blue, 3 green; 1 green, 12 red; 3 green, 2 blue, 16 red 98 | Game 98: 1 red, 6 green, 7 blue; 14 red, 3 green, 2 blue; 16 blue, 14 red, 11 green; 5 blue; 9 red, 1 green, 15 blue 99 | Game 99: 3 blue, 8 green, 1 red; 4 green, 1 blue, 2 red; 1 red, 4 green; 2 blue, 4 green 100 | Game 100: 8 red, 2 blue, 1 green; 2 blue, 4 red, 2 green; 9 red, 1 green; 2 green, 2 red; 3 red, 5 blue; 5 blue, 8 red -------------------------------------------------------------------------------- /20/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | // Example 5 | // broadcaster -> a, b, c 6 | // %a -> b 7 | // %b -> c 8 | // %c -> inv 9 | // &inv -> a 10 | 11 | type InvPipe = { 12 | type: "&"; 13 | 14 | // k/v of every pipe that outputs to this pipe 15 | memory: Record; 16 | }; 17 | type FlipFlopPipe = { 18 | type: "%"; 19 | on: boolean; 20 | }; 21 | 22 | type Pipe = { 23 | key: string; 24 | destinations: string[]; 25 | } & (InvPipe | FlipFlopPipe); 26 | 27 | type Signal = { key: string; type: "low" | "high"; from: string }; 28 | 29 | let startingDestinations: Signal[] = []; 30 | 31 | let pipes: Pipe[] = []; 32 | 33 | input.forEach((line) => { 34 | const [key, destinations] = line.split(" -> "); 35 | if (key === "broadcaster") { 36 | startingDestinations = destinations 37 | .split(", ") 38 | .map((key) => ({ key, type: "low", from: "broadcaster" })); 39 | return; 40 | } 41 | if (key.startsWith("&")) { 42 | pipes.push({ 43 | key: key.slice(1), 44 | destinations: destinations.split(", "), 45 | type: "&", 46 | memory: {}, 47 | }); 48 | return; 49 | } 50 | if (key.startsWith("%")) { 51 | pipes.push({ 52 | key: key.slice(1), 53 | destinations: destinations.split(", "), 54 | type: "%", 55 | on: false, 56 | }); 57 | return; 58 | } 59 | }); 60 | 61 | // map all inv pipes sources into memory 62 | pipes.forEach((pipe) => { 63 | pipe.destinations.forEach((dest) => { 64 | const destPipe = pipes.find((p) => p.key === dest); 65 | if (destPipe?.type === "&") { 66 | destPipe.memory[pipe.key] = "low"; 67 | } 68 | }); 69 | }); 70 | 71 | function runBoard() { 72 | let heap = [...startingDestinations]; 73 | 74 | console.log("current heap", heap); 75 | 76 | let lowSignals = 1; 77 | let highSignals = 0; 78 | 79 | while (heap.length) { 80 | const signal = heap.shift()!; 81 | 82 | console.log(`${signal.from} -${signal.type}-> ${signal.key}`); 83 | 84 | if (signal.type === "low") lowSignals++; 85 | if (signal.type === "high") highSignals++; 86 | 87 | const pipe = pipes.find((p) => p.key === signal.key); 88 | // console.log("through pipe", pipe); 89 | 90 | if (!pipe) { 91 | continue; 92 | } 93 | if (pipe.type === "%") { 94 | if (signal.type === "high") continue; 95 | pipe.on = !pipe.on; 96 | pipe.destinations.forEach((dest) => { 97 | heap.push({ 98 | key: dest, 99 | type: pipe.on ? "high" : "low", 100 | from: signal.key, 101 | }); 102 | }); 103 | } else if (pipe.type === "&") { 104 | if (!signal.from) throw new Error("No signal from"); 105 | pipe.memory[signal.from] = signal.type; 106 | 107 | const allAreHigh = Object.values(pipe.memory).every((v) => v === "high"); 108 | 109 | pipe.destinations.forEach((dest) => { 110 | heap.push({ 111 | key: dest, 112 | type: allAreHigh ? "low" : "high", 113 | from: signal.key, 114 | }); 115 | }); 116 | } 117 | 118 | // console.log("updated heap", heap); 119 | } 120 | 121 | return { lowSignals, highSignals }; 122 | } 123 | 124 | let sumLow = 0; 125 | let sumHigh = 0; 126 | 127 | let x = 0; 128 | while (x < 1000) { 129 | let newAnswers = runBoard(); 130 | sumLow += newAnswers.lowSignals; 131 | sumHigh += newAnswers.highSignals; 132 | x++; 133 | } 134 | 135 | console.log("input?", sumLow, sumHigh, sumLow * sumHigh); 136 | // console.log("board", runBoard()); 137 | -------------------------------------------------------------------------------- /20/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | // Example 5 | // broadcaster -> a, b, c 6 | // %a -> b 7 | // %b -> c 8 | // %c -> inv 9 | // &inv -> a 10 | 11 | type InvPipe = { 12 | type: "&"; 13 | 14 | // k/v of every pipe that outputs to this pipe 15 | memory: Record; 16 | }; 17 | type FlipFlopPipe = { 18 | type: "%"; 19 | on: boolean; 20 | }; 21 | 22 | type Pipe = { 23 | key: string; 24 | destinations: string[]; 25 | } & (InvPipe | FlipFlopPipe); 26 | 27 | type Signal = { key: string; type: "low" | "high"; from: string }; 28 | 29 | let startingDestinations: Signal[] = []; 30 | 31 | let pipes: Pipe[] = []; 32 | 33 | input.forEach((line) => { 34 | const [key, destinations] = line.split(" -> "); 35 | if (key === "broadcaster") { 36 | startingDestinations = destinations 37 | .split(", ") 38 | .map((key) => ({ key, type: "low", from: "broadcaster" })); 39 | return; 40 | } 41 | if (key.startsWith("&")) { 42 | pipes.push({ 43 | key: key.slice(1), 44 | destinations: destinations.split(", "), 45 | type: "&", 46 | memory: {}, 47 | }); 48 | return; 49 | } 50 | if (key.startsWith("%")) { 51 | pipes.push({ 52 | key: key.slice(1), 53 | destinations: destinations.split(", "), 54 | type: "%", 55 | on: false, 56 | }); 57 | return; 58 | } 59 | }); 60 | 61 | // map all inv pipes sources into memory 62 | pipes.forEach((pipe) => { 63 | pipe.destinations.forEach((dest) => { 64 | const destPipe = pipes.find((p) => p.key === dest); 65 | if (destPipe?.type === "&") { 66 | destPipe.memory[pipe.key] = "low"; 67 | } 68 | }); 69 | }); 70 | 71 | // There is ONE pipe that goes to rx (the one we care about) 72 | // It happens to be an inv pipe 73 | // So we log all the things that go to it 74 | const rxIngest = pipes.find((p) => p.destinations.includes("rx"))!; 75 | if (!rxIngest) throw new Error("No rx ingest pipe"); 76 | const keyPlayers = pipes 77 | .filter((p) => p.destinations.includes(rxIngest.key)) 78 | .map((p) => p.key); 79 | 80 | const keyPlayersFound = [-1, -1, -1, -1]; 81 | 82 | function runBoard(x: number) { 83 | let heap = [...startingDestinations]; 84 | 85 | // console.log("current heap", heap); 86 | 87 | let lowSignals = 1; 88 | let highSignals = 0; 89 | 90 | while (heap.length) { 91 | const signal = heap.shift()!; 92 | 93 | if (signal.key === rxIngest.key && signal.type === "high") { 94 | console.log("FOUND ONE", signal.from, x); 95 | const idx = keyPlayers.indexOf(signal.from); 96 | if (idx === -1) throw new Error("not found"); 97 | keyPlayersFound[idx] = x; 98 | } 99 | 100 | // console.log(`${signal.from} -${signal.type}-> ${signal.key}`); 101 | 102 | if (signal.type === "low") lowSignals++; 103 | if (signal.type === "high") highSignals++; 104 | 105 | const pipe = pipes.find((p) => p.key === signal.key); 106 | // console.log("through pipe", pipe); 107 | 108 | if (!pipe) { 109 | continue; 110 | } 111 | if (pipe.type === "%") { 112 | if (signal.type === "high") continue; 113 | pipe.on = !pipe.on; 114 | pipe.destinations.forEach((dest) => { 115 | heap.push({ 116 | key: dest, 117 | type: pipe.on ? "high" : "low", 118 | from: signal.key, 119 | }); 120 | }); 121 | } else if (pipe.type === "&") { 122 | if (!signal.from) throw new Error("No signal from"); 123 | pipe.memory[signal.from] = signal.type; 124 | 125 | const allAreHigh = Object.values(pipe.memory).every((v) => v === "high"); 126 | 127 | pipe.destinations.forEach((dest) => { 128 | heap.push({ 129 | key: dest, 130 | type: allAreHigh ? "low" : "high", 131 | from: signal.key, 132 | }); 133 | }); 134 | } 135 | 136 | // console.log("updated heap", heap); 137 | } 138 | 139 | return { lowSignals, highSignals }; 140 | } 141 | 142 | let sumLow = 0; 143 | let sumHigh = 0; 144 | 145 | let x = 0; 146 | while (keyPlayersFound.some((v) => v === -1)) { 147 | x++; 148 | let newAnswers = runBoard(x); 149 | 150 | const stRx = pipes.find((p) => p.destinations.includes("rx")); 151 | if (!stRx || stRx.type !== "&") throw new Error("rx is not an inv pipe"); 152 | 153 | sumLow += newAnswers.lowSignals; 154 | sumHigh += newAnswers.highSignals; 155 | } 156 | 157 | // calculate LCM 158 | function gcd(a: number, b: number): number { 159 | if (b === 0) return a; 160 | return gcd(b, a % b); 161 | } 162 | function lcm(a: number, b: number): number { 163 | return (a * b) / gcd(a, b); 164 | } 165 | 166 | console.log("kp", keyPlayersFound); 167 | 168 | const lcmOfKeyPlayers = keyPlayersFound.reduce((acc, v) => lcm(acc, v), 1); 169 | 170 | console.log("lcm", lcmOfKeyPlayers); 171 | -------------------------------------------------------------------------------- /20/example.txt: -------------------------------------------------------------------------------- 1 | broadcaster -> a, b, c 2 | %a -> b 3 | %b -> c 4 | %c -> inv 5 | &inv -> a -------------------------------------------------------------------------------- /20/input.txt: -------------------------------------------------------------------------------- 1 | %cf -> tz 2 | %kr -> xn, gq 3 | %cp -> sq, bd 4 | broadcaster -> vn, sj, tg, kn 5 | %hc -> pm 6 | %fd -> xn, mj 7 | %qz -> xf 8 | %vf -> mc, pm 9 | %zm -> rz, pm 10 | %cn -> bd, qz 11 | %jj -> bp 12 | %ks -> ff 13 | %nb -> xn, ks 14 | %bm -> pm, vf 15 | &xn -> kc, jb, cb, tg, ks, tx 16 | %lm -> rk 17 | %dn -> bd, cn 18 | %ft -> dn 19 | %pn -> pm, ll 20 | %rk -> bp, fs 21 | %tz -> bp, gp 22 | %mc -> jx 23 | %fs -> kx 24 | %jf -> bd, fm 25 | %rz -> hc, pm 26 | %tg -> cb, xn 27 | &hf -> rx 28 | %vp -> pn 29 | &pm -> ll, mc, sj, vd, vp 30 | %rn -> kc, xn 31 | %vn -> bd, cp 32 | &nd -> hf 33 | %fm -> bd, gc 34 | %ff -> xn, fd 35 | &bp -> cf, fh, pc, kn, fs, gn, lm 36 | &pc -> hf 37 | %mj -> xn 38 | %qg -> bd 39 | %fh -> lm 40 | %kc -> nb 41 | %xf -> bd, jf 42 | %gc -> qg, bd 43 | &bd -> vn, sq, qz, ft, nd 44 | %jb -> kr 45 | %gp -> bp, rp 46 | %gq -> xn, rn 47 | %sj -> pm, bm 48 | %rp -> bp, jj 49 | %sq -> ft 50 | %cb -> jb 51 | &vd -> hf 52 | %gn -> cf 53 | %kx -> gn, bp 54 | %ll -> zm 55 | &tx -> hf 56 | %jx -> md, pm 57 | %md -> pm, vp 58 | %kn -> fh, bp -------------------------------------------------------------------------------- /21/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | const map = input.map((line) => line.split("")); 5 | type Position = { x: number; y: number }; 6 | // start = character S 7 | const startY = map.findIndex((line) => line.includes("S")); 8 | const startX = map[startY].findIndex((char) => char === "S"); 9 | 10 | let validPositions = new Set([`${startX},${startY}`]); 11 | 12 | map[startY][startX] = "."; 13 | 14 | let steps = 0; 15 | 16 | while (steps < 64) { 17 | const newPositions = new Set(); 18 | validPositions.forEach((position) => { 19 | console.log("CHECKING POS", position); 20 | const { x, y }: { x: number; y: number } = JSON.parse(position); 21 | const up = { x, y: y - 1 }; 22 | const down = { x, y: y + 1 }; 23 | const left = { x: x - 1, y }; 24 | const right = { x: x + 1, y }; 25 | const positions = [up, down, left, right]; 26 | positions.forEach((position) => { 27 | const { x, y } = position; 28 | const char = map[y]?.[x]; 29 | if (char === ".") { 30 | newPositions.add(JSON.stringify(position)); 31 | } 32 | }); 33 | }); 34 | validPositions = newPositions; 35 | steps++; 36 | 37 | // Log grid with O for all valid positions 38 | const grid = map.map((line) => line.map((char) => char)); 39 | validPositions.forEach((position) => { 40 | const [x, y] = position.split(",").map(Number); 41 | grid[y][x] = "O"; 42 | }); 43 | console.log(grid.map((line) => line.join("")).join("\n")); 44 | } 45 | 46 | console.log("input?", validPositions.size); 47 | -------------------------------------------------------------------------------- /21/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | const map = input.map((line) => line.split("")); 5 | type Position = { x: number; y: number }; 6 | // start = character S 7 | const startY = map.findIndex((line) => line.includes("S")); 8 | const startX = map[startY].findIndex((char) => char === "S"); 9 | 10 | let validPositions = new Set([JSON.stringify({ x: startX, y: startY })]); 11 | 12 | const length = map.length; 13 | 14 | map[startY][startX] = "."; 15 | 16 | let steps = 0; 17 | 18 | const acceptedSpots: number[] = []; 19 | 20 | const GOAL = 26501365; 21 | 22 | while (acceptedSpots.length < 3) { 23 | const newPositions = new Set(); 24 | validPositions.forEach((position) => { 25 | // console.log("CHECKING POS", position); 26 | const { x, y }: { x: number; y: number } = JSON.parse(position); 27 | const up = { x, y: y - 1 }; 28 | const down = { x, y: y + 1 }; 29 | const left = { x: x - 1, y }; 30 | const right = { x: x + 1, y }; 31 | const positions = [up, down, left, right]; 32 | positions.forEach((position) => { 33 | const { x, y } = position; 34 | const char = map[Math.abs(y) % length]?.[Math.abs(x) % length]; 35 | if (char === ".") { 36 | newPositions.add(JSON.stringify(position)); 37 | } 38 | }); 39 | }); 40 | validPositions = newPositions; 41 | steps++; 42 | 43 | if (steps % length === GOAL % length) { 44 | acceptedSpots.push(validPositions.size); 45 | console.log("valid size", steps, validPositions.size); 46 | } 47 | 48 | // Log grid with O for all valid positions 49 | // const grid = map.map((line) => line.map((char) => char)); 50 | // validPositions.forEach((position) => { 51 | // const [x, y] = position.split(",").map(Number); 52 | // grid[y][x] = "O"; 53 | // }); 54 | // console.log(grid.map((line) => line.join("")).join("\n")); 55 | } 56 | 57 | console.log("input?", validPositions.size); 58 | 59 | // Quadratic formula 60 | function quad(a: number, b: number, c: number) { 61 | const root = Math.sqrt(b * b - 4 * a * c); 62 | const x1 = (-b + root) / (2 * a); 63 | const x2 = (-b - root) / (2 * a); 64 | return [x1, x2]; 65 | } 66 | 67 | function f(n: number): number { 68 | const a0 = acceptedSpots[0]; 69 | const a1 = acceptedSpots[1] - a0; 70 | const a2 = acceptedSpots[2] - a1; 71 | return a0 + a1 * n + Math.floor((n * (n - 1)) / 2) * (a2 - a1); 72 | } 73 | 74 | const answer = f(Math.floor(GOAL / length)); 75 | console.log(answer); 76 | -------------------------------------------------------------------------------- /21/example.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .....###.#. 3 | .###.##..#. 4 | ..#.#...#.. 5 | ....#.#.... 6 | .##..S####. 7 | .##..#...#. 8 | .......##.. 9 | .##.#.####. 10 | .##..##.##. 11 | ........... -------------------------------------------------------------------------------- /21/input.txt: -------------------------------------------------------------------------------- 1 | ................................................................................................................................... 2 | .........#.............#..#.................................#..........#......##.............#.#..#.#......................##...... 3 | ...#.................#.....#........#.#............#...#...#................##............#...#.............#.....#.......#........ 4 | ...........#.#.#...........#................#....#....................................#........#..#...............#................ 5 | ...#.......#...#...#...........#.#....##...........#...#...............................#..................#..#.#..#....#.#.#....... 6 | ..##.#.................#........#...........................................#...#...................................#.............. 7 | ......#......................##....##......#.......................................#.........#........#...........#.#.............. 8 | ...#.....#.......#...............#....##...#......#..#.......................#...#.#....#.........#.#.......#...................... 9 | ..................................#...#.............#.............#.#..............#.......#.....................#.#............... 10 | ..#........#...............#....#....##.....#.....#..............................#.....#...#...#..#..............#................. 11 | .#................................#.............##................#...#...................#............#.#....#...#.#.....#..#..... 12 | ..............#......#......................#.............#..#.........................#......##....#...........#.........#...###.. 13 | ...#..............#.............#.....##.........#...................#...#...........#.....#..........#...............#.........#.. 14 | ...#........#......................#.#....#...#...............#....................................#.#..#.......................... 15 | ..........#.#.........#...#...#..........#..#...............#.........#....#..................................##.#................. 16 | ..#...........#...............#.........#...#.........##...#....#....................#....#..#.....#.....###.#.....#............... 17 | ...........................................#................#..............##............#.....#...#...............#...##.....##... 18 | .......#...........#....#.....#.......................#.##..........#...#.................#.......#...................##........... 19 | ...........#.....#............#........#............#..........#.........##..#...................#..........................#...... 20 | .......#....#..##..........#..........#..............#.##.............................................#.....#.....#...#.#....#..... 21 | ..#...#.............#......#.#....#....#.........#.....#............#....#.......#.......#..#.#.....#...........#.............#.#.. 22 | ...#.......#.....#...#.......##....#............................#...........#.............................#........#........#....#. 23 | .............#.....##.#............#.#............................................#........#........#...#........#........##.#..#.. 24 | .....#..#..#......#.............................#.......#.........#..#.............#................##..#.........#........#....... 25 | ....#.......#...............#......#............................#.......#.#.............................................#..#....... 26 | .....#.........#..............#..............#...............#..........#.........................#.#...#..#.......#........#...#.. 27 | .........................#.............................#...#.......#................................#.....#.#.....#...........#.... 28 | ..............#......#......................##....#................#....#...........##.................#.........#.....##.......... 29 | ..........#.....................#.........#...........#.....#........#...................................#......................... 30 | ..#...#..##..............#..............#.......#...............#.#.......#...........#.#.................##......#.........#.#.... 31 | .....##........#....##......#..................#...#...................#...........##.##..#...........#............#............... 32 | ...#............#..#...#.................#................................#.....#..#.....#...........#..#......#.##...#..#.....#... 33 | ......#.#...#...#......................#..#....................#......................................#......#...........#..#...#.. 34 | ..............................................#..##...............#.......#..#...#.......##.#.#.........................#...#...... 35 | ..#......#...#...........#..........#.....................#..........##...#....#.#......#..#....................................... 36 | ....#.......##..............................................#........##.....#......#.#..............................#........#..... 37 | ..................##..#.................................#........................................................#............#.... 38 | ......#....#.........................#.#......#.....##......#........#.#........#.............#...........#..................#..... 39 | .##....................#.............#.....#..........#...#.........##..........#............##.............#........#............. 40 | ..............#.....#............#.......................#.....##.........##..#........................................#........... 41 | ..............#...................................#.#.#......#..#....#............##.#..#.................................#........ 42 | ....#..#............................#..#...#.......................................................#...........................#... 43 | ........#......#...........#.#.........##.#................#.##.....................#...............................#.............. 44 | ...........................#......#.........................#..#..#...........#.................#.............................#..#. 45 | ......#...................#...#.........#.....#.........#.......#....#.......#......#...#.................................#........ 46 | ....#.#..#...#...........#....#...........#..........#.........#........................#.#...............#.............#.......... 47 | .#............#.......................................#......#.#............###...................##.....#.............#........... 48 | .......#....................................#.#..........#.#...#.........#.....#................#.....#...#........................ 49 | ...........#.......................##.....#..#........##..............#.............#...........................................#.. 50 | ........#.##.........#..........#........#.................#..............#......###....#........#.....................#.#.....#... 51 | .....##.#...................#.............#........................#..................#..................###.............#......... 52 | ......................#.............#.#.....#..#............#......#...#.#.................#....#........#...................#..... 53 | ..#..................#.#..#............#.......#..............................................................#.#................#. 54 | ..#...#.................#..#.........#........#...#.#.#......#....#.#...#............#...........#.......#......................... 55 | ..#........................##...............................#.......#.......##.........#....#........#......#...............#...... 56 | ...............#.#...........#...........#................#.#..#.........#.........#.........#..................#..#..........#.... 57 | .............#......#......#..#.#......#...#.#.................................#........#..#......#................#...........##.. 58 | ............#.........................#..................................#......#...........#........#............................. 59 | ...#.......#.................#............#........................#.#...........#.#.............#................................. 60 | .............#.......#.........#..............#..#..#.......#..............##.........#....#........##.#...#....................... 61 | .....................#.#.........#.....#..#.........#................##.....#.#....................#........#...................... 62 | ........#.........#......#...#.#............................#.......#..............#....#............#..###....#....#.#............ 63 | ..................#.##..##.....#....#........................#..#....................#..#.....#..#..............#.................. 64 | ..........#..##..........#.......##.#..#...........#..............#..#..........................#....#........#........#........... 65 | .............#...#..#......#.#.....................................#..#.............#.......#....#............#.................... 66 | .................................................................S................................................................. 67 | .................##.#...#.......#.....................#.#..............#......#..........#.##.........#.........##................. 68 | ............................#..#..................#............##................#.......#.....##........................##........ 69 | ..................#......................#............#....#.#..#.....#..........#.#........................#.......#....#......... 70 | ........##.....#.#.........................#..#.....#...#.....#....#...#...#............#...............#.#........................ 71 | ..............#....#.#...............#......#...............................#......#......#..............#......................... 72 | .#.............##..#...................#.......#...........#...#................#.......#.........#.#...#..........#.#..#.......... 73 | ......................#....................#.........................#.#........#........#............#....#......#.............#.. 74 | ...#...............#......##......#.......#.....#..#.....#.................#..#.#.........#.....#........#....#.................... 75 | ......................#....#...............#.....................................#.................#.........................#.#... 76 | .....#.............#.....................#................#.......##............................................................... 77 | ...#...........#..................#............#........#...............#.............#......................................#.#... 78 | .....#...............#.#......#.#...#..#...#..#........#.............................#.............#.........................#..... 79 | .#.................#.....................#.......#..........#..........#....#.......#............#...#...#......................... 80 | .........#..............##...............#.............#..#...#..............##....#..#.#.#..#...#.....#...#.....................#. 81 | .#.......#.#...................#.#...............#.....#...#............................#....#......#.............................. 82 | ....................#...#.....#................#..........#.....................................#....#.#.....#..................... 83 | .........................................#.....#...............#.......#.........#.#.#......#...#.........................#...##... 84 | ..#.##...........................#.#.................................................#.......#.#....................#.....#..##.... 85 | ..#.........#..#........##................#.......#..................#.#.........#.#.......#................................#...... 86 | ....#....#................#..........#.#..........#...........#...#............#.....#................#..............#..#....#..... 87 | ..#.............#........#.....#...#..........#.........#...........#.......#............................#..................#.##... 88 | ....##...........##.............#...........#......#..........#.....#........................#.###................#.......#.....#.. 89 | ........#..#.......................................................#.......#..........##.#..........#.#.............#.....#.#.#.#.. 90 | .#.#......#.###.................#....................................#...#..#..............#....#.#..##............#..#............ 91 | ...........#....#...............##.#......#....#...#............................................#....#.........................#... 92 | ....#.............#................................#.......#...#..........##..................#...............................#.... 93 | ........#.#.#..#.....................#.....##.#..#.......#..........#............................#........................#........ 94 | ...........#.....................##.........#...#..........#....................##....................................##....#...#.. 95 | .....#.#......................................##........#..................#................................#.........#............ 96 | ...#....#......#.....#....................#.............#...#......#.#...#............#..##...........................#........#... 97 | ..#....................#.............................#..........#.................##..##.#...#...................#....#.....##..... 98 | ...........................................##................#..#...........................#.............#.....#.............#.#.. 99 | .....................#......#.........#......#.......#.............................#...............................#........###.... 100 | ............#........#......#.#..............##................#...#...................................................#........... 101 | .................#...........#....................#..#............#.........#......................#..#.....................#...... 102 | .#..............#............##..................#..#...#....#....##.......#..#.#........#.........#.......#..#...#................ 103 | ............#...#.................................#.#........................###....#..........................#.................#. 104 | .......#.....#.........#....................#.............#..........#............#............................................##.. 105 | ............#..#..............#....#............#.......#...#.....#........#........#...........#..#...#.....................#.#... 106 | ....#.#...........................#..............#...........#.......#................#...........#.##.....#............#..#....... 107 | ..........#...........#...#......#...............#.............#.......#......................#..........................#......... 108 | ..#.......#.#............#.......#...............#.......#................................................#.......#................ 109 | ............#..............#........#..........#...#.....................#....#.............#.#.###.......#....#................... 110 | ....#..........#.#.....#.............#.................#......##.........#.......#..........#..................#........#.......... 111 | ..#.#.#.........##....#.........#..........................###............................#......##...#.......#........#.......#... 112 | ....#....#.....................#..................#.#.#...............#........#..........................#.....#..............##.. 113 | .......#...#......#.......#..............#..................#.##........#.#.................................#......#..........#.... 114 | ...#.....#...........##..##....#.....#.................#.....................................#......#....##...#.............#...... 115 | ..........#.........................#...........................#.#........#.........#..#.....#.........#....#..##...#.#......#.... 116 | ............................#.....#.#..#...#..................#.....................#........##..#............#.................... 117 | ......#.............#........................................#.........#........................#..#...........#...#..#.....#...... 118 | ...........#.....#................#.#..#........#...........#.....##...............................#...............#..........##... 119 | ......................#.........................#.........#....#...............................##.......#..#....#...#.............. 120 | ..#.....#.......#....................##...........#...........#.................#.......#.......................................... 121 | ....#....#..#............#......#..#..#.#..#......#...................#.........#...............#.#..#....................#........ 122 | ........##..............................#.#.................##......................#...............#..#......#......#..........#.. 123 | .....#..#...........#.#.......#...............#.................................#......#........................................... 124 | ....##.##............#..............#..#..............#.........#...................................#.......#...................... 125 | .....#....#.....#........#......#..............................#...........#.........##......#...#............##................... 126 | ....#..........#..#............##..#....#.#....#..#.............#...........#.#............#......#........#.......#.#............. 127 | ........#..##.....#......##...............#......#.#.............................#..#...#........#....#..............#........#.... 128 | ..#.................#....#...#........##.....#.............................#..#.#......#.....#...#................#................ 129 | ...........#.#....................#.......##.........................................#..............#..#.............#.......#..... 130 | ..#.....#......#.....................................#......................................#................#.#........#.......... 131 | ................................................................................................................................... -------------------------------------------------------------------------------- /22/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | type Brick = [number, number, number, number, number, number]; 5 | 6 | let bricks: Brick[] = input.map((line) => { 7 | const parts = line.split("~").map((coord) => coord.split(",").map(Number)); 8 | 9 | return [...parts[0], ...parts[1]] as Brick; 10 | }); 11 | 12 | function isSupported( 13 | allPoints: Set, 14 | x: number, 15 | y: number, 16 | z: number 17 | ): boolean { 18 | if (z === 0) { 19 | return true; 20 | } 21 | return allPoints.has(`${x},${y},${z}`); 22 | } 23 | 24 | function move(bricks: Brick[]): [boolean, Brick[]] { 25 | let unstable = false; 26 | const allPoints = new Set(); 27 | bricks.forEach(([sx, sy, sz, ex, ey, ez]) => { 28 | for (let x = sx; x <= ex; x++) { 29 | for (let y = sy; y <= ey; y++) { 30 | allPoints.add(`${x},${y},${ez}`); 31 | } 32 | } 33 | }); 34 | 35 | const newBricks: Brick[] = []; 36 | bricks.forEach((brick) => { 37 | let supp = false; 38 | const [sx, sy, sz, ex, ey, ez] = brick; 39 | for (let x = sx; x <= ex; x++) { 40 | for (let y = sy; y <= ey; y++) { 41 | if (isSupported(allPoints, x, y, sz - 1)) { 42 | supp = true; 43 | break; 44 | } 45 | } 46 | if (supp) break; 47 | } 48 | if (!supp) { 49 | unstable = true; 50 | newBricks.push([sx, sy, sz - 1, ex, ey, ez - 1]); 51 | } else { 52 | newBricks.push(brick); 53 | } 54 | }); 55 | return [unstable, newBricks]; 56 | } 57 | 58 | let unstable = true; 59 | while (unstable) { 60 | [unstable, bricks] = move(bricks); 61 | } 62 | 63 | let validToRemove = 0; 64 | 65 | for (let i = 0; i < bricks.length; i++) { 66 | const bricksMinusOne = [...bricks]; 67 | bricksMinusOne.splice(i, 1); 68 | if (!move(bricksMinusOne)[0]) { 69 | validToRemove += 1; 70 | } 71 | } 72 | 73 | console.log(validToRemove); 74 | -------------------------------------------------------------------------------- /22/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | type Brick = [number, number, number, number, number, number]; 5 | 6 | let bricks: Brick[] = input.map((line) => { 7 | const parts = line.split("~").map((coord) => coord.split(",").map(Number)); 8 | 9 | return [...parts[0], ...parts[1]] as Brick; 10 | }); 11 | 12 | function isSupported( 13 | allPoints: Set, 14 | x: number, 15 | y: number, 16 | z: number 17 | ): boolean { 18 | if (z === 0) { 19 | return true; 20 | } 21 | return allPoints.has(`${x},${y},${z}`); 22 | } 23 | 24 | function move(bricks: Brick[]): [boolean, Brick[]] { 25 | let unstable = false; 26 | const allPoints = new Set(); 27 | bricks.forEach(([sx, sy, sz, ex, ey, ez]) => { 28 | for (let x = sx; x <= ex; x++) { 29 | for (let y = sy; y <= ey; y++) { 30 | allPoints.add(`${x},${y},${ez}`); 31 | } 32 | } 33 | }); 34 | 35 | const newBricks: Brick[] = []; 36 | bricks.forEach((brick) => { 37 | let supp = false; 38 | const [sx, sy, sz, ex, ey, ez] = brick; 39 | for (let x = sx; x <= ex; x++) { 40 | for (let y = sy; y <= ey; y++) { 41 | if (isSupported(allPoints, x, y, sz - 1)) { 42 | supp = true; 43 | break; 44 | } 45 | } 46 | if (supp) break; 47 | } 48 | if (!supp) { 49 | unstable = true; 50 | newBricks.push([sx, sy, sz - 1, ex, ey, ez - 1]); 51 | } else { 52 | newBricks.push(brick); 53 | } 54 | }); 55 | return [unstable, newBricks]; 56 | } 57 | 58 | let unstable = true; 59 | while (unstable) { 60 | [unstable, bricks] = move(bricks); 61 | } 62 | 63 | let ans = 0; 64 | for (let i = 0; i < bricks.length; i++) { 65 | let trimmedBricks = [...bricks]; 66 | trimmedBricks.splice(i, 1); 67 | let unstable = true; 68 | while (unstable) { 69 | [unstable, trimmedBricks] = move(trimmedBricks); 70 | } 71 | let mm = 0; 72 | 73 | const referenceBricks = [...bricks]; 74 | referenceBricks.splice(i, 1); 75 | for (let j = 0; j < trimmedBricks.length; j++) { 76 | if (trimmedBricks[j].toString() !== referenceBricks[j].toString()) { 77 | mm += 1; 78 | } 79 | } 80 | ans += mm; 81 | } 82 | 83 | console.log(ans); 84 | -------------------------------------------------------------------------------- /22/example.txt: -------------------------------------------------------------------------------- 1 | 1,0,1~1,2,1 2 | 0,0,2~2,0,2 3 | 0,2,3~2,2,3 4 | 0,0,4~0,2,4 5 | 2,0,5~2,2,5 6 | 0,1,6~2,1,6 7 | 1,1,8~1,1,9 -------------------------------------------------------------------------------- /3/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt") 2 | .split("\n") 3 | .map((line) => line.split("")); 4 | 5 | let total = 0; 6 | 7 | const RED = "\u001b[31m"; 8 | const BLUE = "\u001b[34m"; 9 | const GREEN = "\u001b[32m"; 10 | const RESET = "\u001b[0m"; 11 | 12 | input.forEach((line, rowNum) => { 13 | let cnum = ""; 14 | let rowTextToPrint = `${RESET}`; 15 | line.forEach((char, charNum) => { 16 | // if char is a digit, append to current cnum 17 | if (char.match(/\d/)) { 18 | cnum += char; 19 | } 20 | 21 | if ((cnum.length > 0 && !char.match(/\d/)) || charNum === line.length - 1) { 22 | // check if any surrounding characters are symbols 23 | const surrounding = []; 24 | for (let y = rowNum - 1; y <= rowNum + 1; y++) { 25 | for (let x = charNum - cnum.length - 1; x <= charNum; x++) { 26 | if (input[y] && input[y][x]) { 27 | surrounding.push(input[y][x]); 28 | } 29 | } 30 | } 31 | // console.log(cnum, surrounding); 32 | 33 | if ( 34 | surrounding.some((char) => { 35 | // return true if NOT digit OR period 36 | return !(char.match(/\d/) || char === "."); 37 | }) 38 | ) { 39 | // console.log("valid", cnum); 40 | total += parseInt(cnum); 41 | rowTextToPrint += `${GREEN}${cnum}${RESET}`; 42 | } else { 43 | rowTextToPrint += `${RED}${cnum}${RESET}`; 44 | } 45 | cnum = ""; 46 | } 47 | if (char === ".") { 48 | rowTextToPrint += `${char}`; 49 | } else if (!char.match(/\d/)) { 50 | rowTextToPrint += `${BLUE}${char}${RESET}`; 51 | } 52 | }); 53 | console.log(rowTextToPrint); 54 | }); 55 | 56 | console.log("total", total); 57 | 58 | // console.log("input?", input); 59 | -------------------------------------------------------------------------------- /3/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt") 2 | .split("\n") 3 | .map((line) => line.split("")); 4 | 5 | let total = 0; 6 | 7 | const gearMap = new Map(); 8 | 9 | const RED = "\u001b[31m"; 10 | const BLUE = "\u001b[34m"; 11 | const GREEN = "\u001b[32m"; 12 | const RESET = "\u001b[0m"; 13 | input.forEach((line, rowNum) => { 14 | let cnum = ""; 15 | let rowTextToPrint = `${RESET}`; 16 | line.forEach((char, charNum) => { 17 | // if char is a digit, append to current cnum 18 | if (char.match(/\d/)) { 19 | cnum += char; 20 | } 21 | 22 | let hasGear = false; 23 | if ((cnum.length > 0 && !char.match(/\d/)) || charNum === line.length - 1) { 24 | if (charNum === line.length - 1 && char.match(/\d/)) { 25 | charNum++; 26 | } 27 | // check if any surrounding characters are symbols 28 | for (let y = rowNum - 1; y <= rowNum + 1; y++) { 29 | for (let x = charNum - cnum.length - 1; x <= charNum; x++) { 30 | // console.log(cnum, "checking", y, x); 31 | if (input[y] && input[y][x] && input[y][x] === "*") { 32 | // console.log(cnum, "found gear", x, y); 33 | hasGear = true; 34 | const current = gearMap.get(`${x},${y}`) ?? []; 35 | current.push(parseInt(cnum)); 36 | gearMap.set(`${x},${y}`, current); 37 | } 38 | } 39 | } 40 | if (hasGear) { 41 | rowTextToPrint += `${GREEN}${cnum}${RESET}`; 42 | } else { 43 | rowTextToPrint += `${RED}${cnum}${RESET}`; 44 | } 45 | cnum = ""; 46 | } 47 | if (char === ".") { 48 | rowTextToPrint += `${char}`; 49 | } else if (!char.match(/\d/)) { 50 | rowTextToPrint += `${BLUE}${char}${RESET}`; 51 | } 52 | }); 53 | console.log(rowTextToPrint); 54 | }); 55 | 56 | // console.log(gearMap); 57 | 58 | gearMap.forEach((values, key) => { 59 | if (values.length === 2) { 60 | total += values[0] * values[1]; 61 | } 62 | }); 63 | 64 | console.log("total", total); 65 | 66 | // console.log("input?", input); 67 | -------------------------------------------------------------------------------- /4/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | 3 | const parsed = input.map((line) => { 4 | const [_, sides] = line.split(": "); 5 | const [winningNumbers, myNumbers] = sides.split(" | "); 6 | 7 | const winningNumbersArray = winningNumbers 8 | .trim() 9 | .replaceAll(" ", " ") 10 | .split(" ") 11 | .map((num) => parseInt(num)); 12 | const myNumbersArray = myNumbers 13 | .trim() 14 | .replaceAll(" ", " ") 15 | .split(" ") 16 | .map((num) => parseInt(num)); 17 | 18 | console.log("winningNumbersArray?", winningNumbersArray); 19 | console.log("myNumbersArray?", myNumbersArray); 20 | // first match is 1 point, every additional match doubles points 21 | const points = winningNumbersArray.reduce((acc, num) => { 22 | if (myNumbersArray.includes(num)) { 23 | if (acc === 0) return 1; 24 | return acc * 2; 25 | } 26 | return acc; 27 | }, 0); 28 | 29 | console.log("points?", points); 30 | return points; 31 | }); 32 | 33 | const totalPoints = parsed.reduce((acc, num) => acc + num, 0); 34 | 35 | console.log("totalPoints?", totalPoints); 36 | -------------------------------------------------------------------------------- /4/b.ts: -------------------------------------------------------------------------------- 1 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 2 | const input = Deno.readTextFileSync("input.txt").split("\n"); 3 | 4 | // fill with 1's for length of input 5 | const cardCounts = new Array(input.length).fill(1); 6 | 7 | input.map((line, currentCard) => { 8 | const [_, sides] = line.split(": "); 9 | const [winningNumbers, myNumbers] = sides.split(" | "); 10 | 11 | const winningNumbersArray = winningNumbers 12 | .trim() 13 | .replaceAll(" ", " ") 14 | .split(" ") 15 | .map((num) => parseInt(num)); 16 | const myNumbersArray = myNumbers 17 | .trim() 18 | .replaceAll(" ", " ") 19 | .split(" ") 20 | .map((num) => parseInt(num)); 21 | 22 | // first match is 1 point, every additional match doubles points 23 | const points = winningNumbersArray.reduce((acc, num) => { 24 | if (myNumbersArray.includes(num)) { 25 | return acc + 1; 26 | } 27 | return acc; 28 | }, 0); 29 | 30 | const myCount = cardCounts[currentCard] || 1; 31 | 32 | for (let i = 1; i < points + 1; i++) { 33 | cardCounts[currentCard + i] = cardCounts[currentCard + i] || 1; 34 | cardCounts[currentCard + i] += myCount; 35 | } 36 | 37 | return points; 38 | }); 39 | 40 | const totalPoints = cardCounts.reduce((acc, num) => acc + num, 0); 41 | 42 | console.log("totalPoints?", totalPoints); 43 | -------------------------------------------------------------------------------- /4/example.txt: -------------------------------------------------------------------------------- 1 | Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 2 | Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 3 | Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 4 | Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 5 | Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 6 | Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 -------------------------------------------------------------------------------- /5/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n\n"); 3 | 4 | const [seedsIn, ...rest] = input; 5 | const [_, seedsStr] = seedsIn.split(": "); 6 | const seeds = seedsStr.split(" ").map(Number); 7 | 8 | console.log("seeds"); 9 | 10 | const transforms = rest.map((group) => { 11 | const [_, ...lines] = group.split("\n"); 12 | 13 | const rgs: [number, number, number][] = lines.map( 14 | (l) => l.split(" ").map(Number) as [number, number, number] 15 | ); 16 | console.log("lines", rgs); 17 | 18 | return rgs; 19 | }); 20 | 21 | let final = seeds.map((seed) => { 22 | console.log("Seed", seed); 23 | let current = seed; 24 | transforms.forEach((rangeGroup) => { 25 | const matchingRange = rangeGroup.find( 26 | ([mapping, start, delta]) => current >= start && current <= start + delta 27 | ); 28 | 29 | if (matchingRange) { 30 | console.log("MATCHED", current, matchingRange); 31 | const [mapping, start, delta] = matchingRange; 32 | current = mapping + (current - start); 33 | 34 | console.log("NEW VALUE", current); 35 | } 36 | }); 37 | 38 | console.log("Final value", current, "\n"); 39 | 40 | return current; 41 | }); 42 | 43 | // lowest 44 | console.log("lowest", Math.min(...final)); 45 | -------------------------------------------------------------------------------- /5/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n\n"); 2 | // const input = Deno.readTextFileSync("example.txt").split("\n\n"); 3 | 4 | const [seedsIn, ...rest] = input; 5 | const [_, seedsStr] = seedsIn.split(": "); 6 | const seeds = seedsStr.split(" ").map(Number); 7 | 8 | const seedPairs = seeds.reduce((acc, seed, i) => { 9 | if (i % 2 === 0) { 10 | acc.push([seed]); 11 | } else { 12 | acc[acc.length - 1].push(seed); 13 | } 14 | 15 | return acc; 16 | }, [] as number[][]); 17 | console.log("seedPairs", seedPairs); 18 | 19 | console.log("seeds"); 20 | 21 | const transforms = rest.map((group) => { 22 | const [_, ...lines] = group.split("\n"); 23 | 24 | const rgs: [number, number, number][] = lines.map( 25 | (l) => l.split(" ").map(Number) as [number, number, number] 26 | ); 27 | 28 | return rgs; 29 | }); 30 | 31 | let final = seedPairs.map((seed) => { 32 | console.log("on seed pair", seed); 33 | let currentLowest = 9999999999999; 34 | let checkingSeed = seed[0]; 35 | while (checkingSeed < seed[0] + seed[1] + 1) { 36 | let current = checkingSeed; 37 | transforms.forEach((rangeGroup) => { 38 | const matchingRange = rangeGroup.find( 39 | ([mapping, start, delta]) => current >= start && current < start + delta 40 | ); 41 | 42 | if (matchingRange) { 43 | // console.log("MATCHED", current, matchingRange); 44 | const [mapping, start, delta] = matchingRange; 45 | current = mapping + (current - start); 46 | 47 | // console.log("NEW VALUE", current); 48 | } 49 | }); 50 | if (current < currentLowest) { 51 | currentLowest = current; 52 | } 53 | checkingSeed++; 54 | } 55 | 56 | // console.log("Final value", current, "\n"); 57 | 58 | console.log("clow", currentLowest); 59 | return currentLowest; 60 | }); 61 | 62 | // lowest 63 | console.log("lowest", Math.min(...final)); 64 | -------------------------------------------------------------------------------- /5/example.txt: -------------------------------------------------------------------------------- 1 | seeds: 79 14 55 13 2 | 3 | seed-to-soil map: 4 | 50 98 2 5 | 52 50 48 6 | 7 | soil-to-fertilizer map: 8 | 0 15 37 9 | 37 52 2 10 | 39 0 15 11 | 12 | fertilizer-to-water map: 13 | 49 53 8 14 | 0 11 42 15 | 42 0 7 16 | 57 7 4 17 | 18 | water-to-light map: 19 | 88 18 7 20 | 18 25 70 21 | 22 | light-to-temperature map: 23 | 45 77 23 24 | 81 45 19 25 | 68 64 13 26 | 27 | temperature-to-humidity map: 28 | 0 69 1 29 | 1 0 69 30 | 31 | humidity-to-location map: 32 | 60 56 37 33 | 56 93 4 -------------------------------------------------------------------------------- /5/input.txt: -------------------------------------------------------------------------------- 1 | seeds: 3429320627 235304036 1147330745 114559245 1684000747 468955901 677937579 96599505 1436970021 26560102 3886049334 159534901 936845926 25265009 3247146679 95841652 3696363517 45808572 2319065313 125950148 2 | 3 | seed-to-soil map: 4 | 583826644 2288418886 120919689 5 | 2666741396 3172314277 160907737 6 | 416244021 605500997 167582623 7 | 779666561 2280573809 7845077 8 | 704746333 908146497 74920228 9 | 845411123 2565941729 61831565 10 | 1527751557 3025978089 146336188 11 | 2827649133 2012274036 268299773 12 | 259640867 2409338575 156603154 13 | 0 2766337222 259640867 14 | 787511638 983066725 57899485 15 | 907242688 1526828044 485445992 16 | 1674087745 237273108 368227889 17 | 2180879562 1040966210 485861834 18 | 1392688680 773083620 135062877 19 | 3095948906 0 237273108 20 | 2042315634 2627773294 138563928 21 | 22 | soil-to-fertilizer map: 23 | 3793729374 3825015981 63222599 24 | 1438266078 0 258943930 25 | 1292079166 1479426911 146186912 26 | 2816531945 2822520060 385496901 27 | 1078023340 1741334425 98335224 28 | 3856951973 3668871521 111838140 29 | 4180611137 3904426682 114356159 30 | 0 1958275780 804927654 31 | 3968790113 3380257222 80572704 32 | 843553208 2801828988 20691072 33 | 1724422279 286156201 594958638 34 | 3616894031 4018782841 39547646 35 | 1697210008 258943930 27212271 36 | 3700747997 3472761445 92981377 37 | 4101643138 3565742822 50848378 38 | 4152491516 3460829926 11931519 39 | 976862296 1378265867 101161044 40 | 2319380917 881114839 497151028 41 | 3380257222 4058330487 236636809 42 | 3656441677 3780709661 44306320 43 | 864244280 1845657764 112618016 44 | 1176358564 1625613823 115720602 45 | 4164423035 3888238580 16188102 46 | 3202028846 1839669649 5988115 47 | 804927654 2763203434 38625554 48 | 4049362817 3616591200 52280321 49 | 50 | fertilizer-to-water map: 51 | 3734704645 4081344261 116089008 52 | 474703780 198917265 194664963 53 | 1879970783 393582228 36617128 54 | 1197375949 1845422975 8989824 55 | 466658346 430199356 8045434 56 | 2310800010 2638298964 424967672 57 | 919557740 1398638397 135905600 58 | 3687134144 3790001806 1934146 59 | 3470663058 2339708475 216471086 60 | 1759740912 1126580170 64763562 61 | 896009775 1048686270 23547965 62 | 3348634097 3711378096 32073660 63 | 3091810489 2234799361 92321214 64 | 889058738 1119629133 6951037 65 | 2784472328 3743451756 46550050 66 | 2843610278 3063266636 231881310 67 | 1532834459 674183164 226906453 68 | 3273953517 2183514026 51285335 69 | 3075491588 4197433269 16318901 70 | 3325238852 3791935952 23395245 71 | 3689068290 3665741741 45636355 72 | 3384455721 3861402055 22006111 73 | 3406461832 3295147946 64201226 74 | 1412808810 438244790 32132927 75 | 3380707757 2556179561 3747964 76 | 3850793653 4001077593 80266668 77 | 1450046808 470377717 82787651 78 | 669368743 1626190154 219232821 79 | 1365871086 1072234235 46937724 80 | 3184131703 3969255894 11450375 81 | 1824504474 553165368 55466309 82 | 1206365773 1854412799 159505313 83 | 1055463340 906773661 141912609 84 | 3931060321 3359349172 306392569 85 | 2756139006 3883408166 28333322 86 | 193812194 608631677 65551487 87 | 2229584884 4213752170 81215126 88 | 3195582078 2559927525 78371439 89 | 259363681 1191343732 207294665 90 | 2183514026 3815331197 46070858 91 | 2735767682 3980706269 20371324 92 | 888601564 1119171959 457174 93 | 1916587911 901089617 5684044 94 | 1922271955 1534543997 91646157 95 | 4237452890 3911741488 57514406 96 | 2831022378 2327120575 12587900 97 | 1444941737 193812194 5105071 98 | 99 | water-to-light map: 100 | 3241790649 0 474458786 101 | 1987249042 1535533387 1254541607 102 | 289948525 715361304 527138528 103 | 3716249435 1242499832 58349573 104 | 1051771035 3080023519 694575489 105 | 817087053 1300849405 234683982 106 | 1746346524 474458786 240902518 107 | 0 2790074994 289948525 108 | 109 | light-to-temperature map: 110 | 2243197897 1858683458 54522139 111 | 694397455 637497541 323467072 112 | 3781060233 3489670799 513907063 113 | 2297720036 960964613 400594644 114 | 3448397921 3305645149 184025650 115 | 1096611912 137478840 356155107 116 | 2159128717 1774614278 84069180 117 | 1769470938 1913205597 389657779 118 | 1017864527 2302863376 78747385 119 | 3632423571 4003577862 148636662 120 | 281342434 1361559257 413055021 121 | 3393398302 4239967677 54999619 122 | 137478840 493633947 143863594 123 | 3305645149 4152214524 87753153 124 | 1452767019 2381610761 316703919 125 | 126 | temperature-to-humidity map: 127 | 36297311 0 6725362 128 | 2219701249 4240213747 25288799 129 | 3578106372 1498215295 38253390 130 | 1356053404 1610598521 173674950 131 | 446166190 530183876 120299205 132 | 813026177 2579337380 225593633 133 | 133147960 367690092 61449909 134 | 223651565 500781338 29402538 135 | 253054103 174578005 193112087 136 | 194597869 6725362 29053696 137 | 566465395 85143164 1372917 138 | 799049686 3045085309 13976491 139 | 1529728354 3595799720 487441441 140 | 2420467399 2406340018 172679747 141 | 2593147146 1784273471 622066547 142 | 2244990048 3198005099 143889028 143 | 3437740738 4233433470 6780277 144 | 43022673 650483081 18483950 145 | 2407809136 1485557032 12658263 146 | 3215213693 1060498533 222527045 147 | 580905107 86516081 88061924 148 | 2017169795 1283025578 202531454 149 | 3710504883 2579019765 317615 150 | 61506623 429140001 71641337 151 | 3716287969 769584936 114202886 152 | 1328506806 3066097836 27546598 153 | 3703468847 3059061800 7036036 154 | 769584936 4265502546 29464750 155 | 1292525403 883787822 35981403 156 | 3710822498 919769225 5465471 157 | 3830490855 4083241161 150192309 158 | 3616359762 925234696 87109085 159 | 2388879076 3093644434 18930060 160 | 3529951620 1012343781 48154752 161 | 4220837460 1536468685 74129836 162 | 3444521015 3112574494 85430605 163 | 567838312 35779058 13066795 164 | 1038619810 3341894127 253905593 165 | 3980683164 2804931013 240154296 166 | 0 48845853 36297311 167 | 168 | humidity-to-location map: 169 | 2609743610 4133079426 108193613 170 | 1608826026 1793129808 148682069 171 | 3749483646 1957417643 61460641 172 | 3216466252 4241273039 49689894 173 | 2717937223 1941811877 15605766 174 | 3810944287 1225630249 233181949 175 | 2124315534 3020458025 302014415 176 | 264620169 272336891 68907407 177 | 861861645 2458132363 209077985 178 | 4044126236 1458812198 250841060 179 | 3134115707 2375781818 82350545 180 | 1070939630 4290962933 4004363 181 | 2733542989 4089410242 43669184 182 | 1074943993 3479498485 533882033 183 | 2777212173 2018878284 356903534 184 | 2426329949 4013380518 76029724 185 | 333527576 0 7716722 186 | 3266156146 3346379827 130079823 187 | 2526267060 1709653258 83476550 188 | 1757508095 3476459650 3038835 189 | 0 7716722 264620169 190 | 1760546930 861861645 363768604 191 | 3396235969 2667210348 353247677 192 | 2502359673 3322472440 23907387 -------------------------------------------------------------------------------- /6/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | // formatted as 3 | // Time: 53 71 78 80 4 | // Distance: 275 1181 1215 1524 5 | // NOTE SPACE BETWEEN NUMBERS 6 | 7 | // reduce whitespaces to 1 whitespace 8 | input[0] = input[0].replace(/\s+/g, " "); 9 | input[1] = input[1].replace(/\s+/g, " "); 10 | 11 | const times = input[0].split(" ").map(Number); 12 | times.shift(); 13 | const distances = input[1].split(" ").map(Number); 14 | distances.shift(); 15 | 16 | console.log("input?", times, distances); 17 | 18 | let winsMulti = 1; 19 | 20 | distances.forEach((distance, i) => { 21 | const record = times[i]; 22 | let chargeTime = 1; 23 | let validWaits: number[] = []; 24 | while (chargeTime < record) { 25 | const traverseTime = distance / chargeTime; 26 | if (traverseTime + chargeTime <= record) { 27 | validWaits.push(chargeTime); 28 | } 29 | chargeTime++; 30 | } 31 | console.log("valid waits", validWaits); 32 | winsMulti *= validWaits.length; 33 | }); 34 | 35 | console.log("wins", winsMulti); 36 | -------------------------------------------------------------------------------- /6/b.ts: -------------------------------------------------------------------------------- 1 | // Yes I hardcoded, no I don't care 2 | const times = [53717880]; 3 | const distances = [275118112151524]; 4 | 5 | let winsMulti = 1; 6 | 7 | distances.forEach((distance, i) => { 8 | const record = times[i]; 9 | let chargeTime = 1; 10 | let validWaits: number[] = []; 11 | while (chargeTime < record) { 12 | const traverseTime = distance / chargeTime; 13 | if (traverseTime + chargeTime <= record) { 14 | validWaits.push(chargeTime); 15 | } 16 | chargeTime++; 17 | } 18 | console.log("valid waits", validWaits); 19 | winsMulti *= validWaits.length; 20 | }); 21 | 22 | console.log("wins", winsMulti); 23 | -------------------------------------------------------------------------------- /6/input.txt: -------------------------------------------------------------------------------- 1 | Time: 53 71 78 80 2 | Distance: 275 1181 1215 1524 -------------------------------------------------------------------------------- /7/a.ts: -------------------------------------------------------------------------------- 1 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 2 | const input = Deno.readTextFileSync("input.txt").split("\n"); 3 | 4 | const pairs = input.map((line) => line.split(" ")); 5 | 6 | const priority = [ 7 | "A", 8 | "K", 9 | "Q", 10 | "J", 11 | "T", 12 | "9", 13 | "8", 14 | "7", 15 | "6", 16 | "5", 17 | "4", 18 | "3", 19 | "2", 20 | ].reverse(); 21 | 22 | const checkForType = (hand: string[]) => { 23 | const counts = hand.reduce((acc, curr) => { 24 | if (acc[curr]) { 25 | acc[curr] += 1; 26 | } else { 27 | acc[curr] = 1; 28 | } 29 | return acc; 30 | }, {} as { [key: string]: number }); 31 | 32 | const countValues = Object.values(counts); 33 | 34 | const sorted = countValues.sort((a, b) => b - a); 35 | 36 | if (sorted[0] === 5) { 37 | return 5; 38 | } 39 | 40 | if (sorted[0] === 4) { 41 | return 4; 42 | } 43 | 44 | if (sorted[0] === 3 && sorted[1] === 2) { 45 | return 3; 46 | } 47 | 48 | if (sorted[0] === 3) { 49 | return 2; 50 | } 51 | 52 | if (sorted[0] === 2 && sorted[1] === 2) { 53 | return 1; 54 | } 55 | 56 | if (sorted[0] === 2) { 57 | return 0; 58 | } 59 | 60 | return -1; 61 | }; 62 | 63 | const compareHands = (hand1: string, hand2: string) => { 64 | const h1 = hand1.split(""); 65 | const h2 = hand2.split(""); 66 | 67 | const h1Type = checkForType(h1); 68 | const h2Type = checkForType(h2); 69 | 70 | if (h1Type > h2Type) { 71 | return 1; 72 | } 73 | 74 | if (h1Type < h2Type) { 75 | return -1; 76 | } 77 | 78 | let location = 0; 79 | let h1Index = priority.findIndex((p) => p === h1[location]); 80 | let h2Index = priority.findIndex((p) => p === h2[location]); 81 | 82 | while (h1Index === h2Index) { 83 | location += 1; 84 | h1Index = priority.findIndex((p) => p === h1[location]); 85 | h2Index = priority.findIndex((p) => p === h2[location]); 86 | } 87 | 88 | if (h1Index > h2Index) { 89 | return 1; 90 | } 91 | if (h1Index < h2Index) { 92 | return -1; 93 | } 94 | 95 | throw new Error("this should have returned"); 96 | }; 97 | 98 | const sortedHands = pairs.sort((a, b) => { 99 | const h1 = a[0]; 100 | const h2 = b[0]; 101 | 102 | return compareHands(h1, h2); 103 | }); 104 | 105 | const parsed = sortedHands.map((r, i) => { 106 | const num = Number(r[1]); 107 | return num * (i + 1); 108 | }); 109 | 110 | const sum = parsed.reduce((acc, curr) => acc + curr, 0); 111 | 112 | console.log("input?", sum); 113 | -------------------------------------------------------------------------------- /7/b.ts: -------------------------------------------------------------------------------- 1 | // const input = Deno.readTextFileSync("example.txt").split("\n"); 2 | const input = Deno.readTextFileSync("input.txt").split("\n"); 3 | 4 | const pairs = input.map((line) => line.split(" ")); 5 | 6 | const priority = [ 7 | "A", 8 | "K", 9 | "Q", 10 | "T", 11 | "9", 12 | "8", 13 | "7", 14 | "6", 15 | "5", 16 | "4", 17 | "3", 18 | "2", 19 | "J", 20 | ].reverse(); 21 | 22 | const createPermutations = (arr: string[]): string[][] => { 23 | const jIndex = arr.findIndex((a) => a === "J"); 24 | 25 | const permutations = []; 26 | 27 | for (let i = 1; i < 13; i++) { 28 | const copy = [...arr]; 29 | copy[jIndex] = priority[i]; 30 | permutations.push(copy); 31 | 32 | if (copy.includes("J")) { 33 | const newPermutations = createPermutations(copy); 34 | newPermutations.forEach((p) => permutations.push(p)); 35 | } 36 | } 37 | 38 | return permutations; 39 | }; 40 | 41 | const checkForType = (hand: string[]) => { 42 | let highest = -1; 43 | 44 | const permutations = createPermutations(hand); 45 | permutations.forEach((p) => { 46 | const it = checkForTypeInternal(p); 47 | if (it > highest) { 48 | highest = it; 49 | } 50 | }); 51 | return highest; 52 | }; 53 | const checkForTypeInternal = (hand: string[]) => { 54 | const counts = hand.reduce((acc, curr) => { 55 | if (acc[curr]) { 56 | acc[curr] += 1; 57 | } else { 58 | acc[curr] = 1; 59 | } 60 | return acc; 61 | }, {} as { [key: string]: number }); 62 | 63 | const countValues = Object.values(counts); 64 | 65 | const sorted = countValues.sort((a, b) => b - a); 66 | 67 | if (sorted[0] === 5) { 68 | return 5; 69 | } 70 | 71 | if (sorted[0] === 4) { 72 | return 4; 73 | } 74 | 75 | if (sorted[0] === 3 && sorted[1] === 2) { 76 | return 3; 77 | } 78 | 79 | if (sorted[0] === 3) { 80 | return 2; 81 | } 82 | 83 | if (sorted[0] === 2 && sorted[1] === 2) { 84 | return 1; 85 | } 86 | 87 | if (sorted[0] === 2) { 88 | return 0; 89 | } 90 | 91 | return -1; 92 | }; 93 | 94 | const compareHands = (hand1: string, hand2: string) => { 95 | const h1 = hand1.split(""); 96 | const h2 = hand2.split(""); 97 | 98 | const h1Type = checkForType(h1); 99 | const h2Type = checkForType(h2); 100 | 101 | if (h1Type > h2Type) { 102 | return 1; 103 | } 104 | 105 | if (h1Type < h2Type) { 106 | return -1; 107 | } 108 | 109 | let location = 0; 110 | let h1Index = priority.findIndex((p) => p === h1[location]); 111 | let h2Index = priority.findIndex((p) => p === h2[location]); 112 | 113 | while (h1Index === h2Index) { 114 | location += 1; 115 | h1Index = priority.findIndex((p) => p === h1[location]); 116 | h2Index = priority.findIndex((p) => p === h2[location]); 117 | } 118 | 119 | if (h1Index > h2Index) { 120 | return 1; 121 | } 122 | if (h1Index < h2Index) { 123 | return -1; 124 | } 125 | throw new Error("this should have returned"); 126 | }; 127 | 128 | const sortedHands = pairs.sort((a, b) => { 129 | const h1 = a[0]; 130 | const h2 = b[0]; 131 | 132 | return compareHands(h1, h2); 133 | }); 134 | 135 | const parsed = sortedHands.map((r, i) => { 136 | const num = Number(r[1]); 137 | return num * (i + 1); 138 | }); 139 | 140 | const sum = parsed.reduce((acc, curr) => acc + curr, 0); 141 | 142 | console.log("input?", sum); 143 | -------------------------------------------------------------------------------- /7/example.txt: -------------------------------------------------------------------------------- 1 | 32T3K 765 2 | T55J5 684 3 | KK677 28 4 | KTJJT 220 5 | QQQJA 483 -------------------------------------------------------------------------------- /7/input.txt: -------------------------------------------------------------------------------- 1 | T6782 898 2 | 26T7A 345 3 | 56856 92 4 | 88J88 379 5 | 8QQJ8 792 6 | QQQT8 607 7 | 98998 912 8 | 888T7 491 9 | 7A6Q9 220 10 | 6QJ23 746 11 | T5297 133 12 | 44874 357 13 | 84854 864 14 | 8JQQ2 383 15 | J2KT2 649 16 | 84488 234 17 | JQ4QT 534 18 | JJAAA 855 19 | 8J49Q 458 20 | 5QK4A 474 21 | 5535T 504 22 | T3785 237 23 | 28J88 315 24 | 4544A 680 25 | 7T773 731 26 | KJKKK 190 27 | 5Q5QK 249 28 | 6664T 747 29 | QTQQT 164 30 | ATTAA 290 31 | 95752 486 32 | J3JAA 324 33 | K9K9J 204 34 | 99959 867 35 | K4KKK 980 36 | A937J 37 37 | 654A9 700 38 | 7553K 352 39 | 8333K 361 40 | ATJT8 771 41 | 26226 940 42 | TTJ7Q 834 43 | QQ33J 117 44 | 62J57 890 45 | J3A4A 124 46 | T4JT4 677 47 | 93528 31 48 | TJA2J 509 49 | Q222A 126 50 | 52T67 177 51 | 3J9TT 629 52 | 33QQ3 471 53 | 22232 9 54 | 82279 283 55 | 3A3AJ 583 56 | 7343T 829 57 | 93338 836 58 | T588Q 70 59 | 88K85 593 60 | 55353 926 61 | Q3749 295 62 | T6JAK 586 63 | 9AA3J 183 64 | 55565 342 65 | 8K4Q8 910 66 | AA4A4 907 67 | 78T2A 112 68 | 4J66K 263 69 | TKJTT 386 70 | 66Q6Q 131 71 | 26266 187 72 | 23AQ3 600 73 | 95K3Q 279 74 | 32522 684 75 | 8Q8Q7 62 76 | KKAKK 579 77 | QJ885 899 78 | 66J2K 396 79 | 555J5 592 80 | 88TJ6 767 81 | 352K2 94 82 | J6488 634 83 | 5A32J 943 84 | AAAKA 673 85 | J8AAA 667 86 | 2K5JK 768 87 | Q4578 294 88 | 4447K 227 89 | QQQQ7 808 90 | JJ333 176 91 | 49586 515 92 | 622T7 622 93 | 94359 140 94 | 8QJ2A 239 95 | Q69JT 939 96 | A75T9 425 97 | JKA93 887 98 | AA7AA 157 99 | TTTJ5 122 100 | J2J3J 118 101 | 3J333 681 102 | 3769A 429 103 | A2K92 123 104 | 53Q8K 257 105 | A83K4 905 106 | 2935K 543 107 | 66466 421 108 | 34394 963 109 | QQ433 520 110 | KTKKK 83 111 | 66677 346 112 | Q83JQ 334 113 | 6AT54 79 114 | K4949 442 115 | 37374 627 116 | 73777 571 117 | JQKKJ 648 118 | 42242 226 119 | KK888 319 120 | 5K6Q2 971 121 | AA3JA 51 122 | 4AK87 78 123 | 3J343 840 124 | K3333 25 125 | 33484 401 126 | 9J866 565 127 | Q399Q 116 128 | 2K597 742 129 | 66A53 793 130 | AQQAQ 779 131 | Q3QJJ 470 132 | 75496 4 133 | 8JJT3 775 134 | 99JKJ 437 135 | 22J9J 60 136 | 39AAT 424 137 | 3J43J 507 138 | 33TJ9 414 139 | 99395 209 140 | A984Q 821 141 | A88J8 757 142 | T3A68 432 143 | 36666 646 144 | KKKAA 175 145 | K9TTK 392 146 | 33KK5 308 147 | KK4K4 675 148 | 64443 370 149 | TQJ9Q 645 150 | QT999 669 151 | J5T88 789 152 | 89TJ4 245 153 | T436T 605 154 | 6T464 36 155 | JQQ3Q 11 156 | 68666 423 157 | KKJKT 785 158 | T4K3A 847 159 | 6T6JT 915 160 | 8Q756 163 161 | 9AAA2 343 162 | 9AJK8 556 163 | 3JJ69 154 164 | 7K7K3 316 165 | 6737Q 641 166 | 88J7J 975 167 | 5J445 270 168 | KATJT 659 169 | 6J866 717 170 | 989T9 529 171 | 2897K 321 172 | 4A2T5 984 173 | 7AA99 485 174 | JK222 397 175 | 75468 282 176 | QT3J3 91 177 | 3K777 532 178 | 6Q566 460 179 | 2KK75 339 180 | 55258 766 181 | 88558 46 182 | 34J34 419 183 | T42A8 624 184 | 6JA9K 950 185 | A8646 135 186 | 66696 66 187 | 37Q7Q 612 188 | KJAK6 753 189 | 94999 306 190 | 2JJJJ 765 191 | 6JQ3A 459 192 | K8693 871 193 | 477K7 26 194 | 4T6T8 544 195 | 44JK4 720 196 | 5K5K9 372 197 | KQ66Q 590 198 | 8A294 57 199 | JJJJJ 440 200 | 88878 18 201 | J9649 389 202 | 77677 698 203 | 9K69J 145 204 | 2QT2K 75 205 | 77577 22 206 | AQ4KA 422 207 | 97477 332 208 | 33933 882 209 | 63646 293 210 | 53A3A 763 211 | 4K93K 928 212 | KKK37 994 213 | TA259 173 214 | K896A 93 215 | 6Q666 438 216 | J8477 674 217 | AJAQQ 531 218 | 2JJ2J 726 219 | 5KJT5 672 220 | A58A2 481 221 | JJAJT 754 222 | 96444 179 223 | 687A5 528 224 | TA48J 618 225 | 7Q7Q7 537 226 | T4A44 23 227 | 473Q6 988 228 | KQ467 64 229 | 5T555 938 230 | 67T33 444 231 | KAK99 591 232 | A6K78 160 233 | 23Q7A 878 234 | TA5AT 292 235 | 2T6Q5 559 236 | 77979 222 237 | 9AAJA 284 238 | TK47T 166 239 | 694T2 679 240 | AAA23 838 241 | 88KJK 170 242 | QJQ2Q 777 243 | 84486 178 244 | 535JQ 411 245 | J547T 595 246 | 37773 602 247 | 777JQ 188 248 | 48989 825 249 | 4944K 492 250 | J8959 375 251 | 72Q5A 908 252 | Q2AAT 280 253 | Q3666 119 254 | 48J24 238 255 | 999JA 865 256 | KK9KK 831 257 | 6Q3JT 909 258 | 3A773 50 259 | 38466 461 260 | 37A25 300 261 | 95555 307 262 | 7Q228 557 263 | KQ66K 525 264 | 8744K 727 265 | J9JQ9 475 266 | A5AKA 148 267 | A7KJT 309 268 | TT794 539 269 | 53339 762 270 | Q9999 6 271 | A4AT4 993 272 | 888AA 790 273 | 6666A 480 274 | 88Q63 274 275 | 99J92 869 276 | J8988 884 277 | 8K68J 839 278 | 7QA72 498 279 | 84697 581 280 | 3QK3J 289 281 | 59J8A 692 282 | Q5J5Q 761 283 | J777K 930 284 | T552K 251 285 | TAT26 715 286 | 6J32T 380 287 | 74K28 523 288 | 22279 104 289 | 8TKT2 393 290 | 68J67 391 291 | 55458 340 292 | 5TK47 395 293 | 822J8 893 294 | T9388 902 295 | 8TQ3Q 252 296 | 3T549 811 297 | 88883 702 298 | 55J2K 81 299 | 4QTT4 138 300 | 69669 272 301 | KTKTK 576 302 | T6668 822 303 | 7J777 736 304 | 9ATJT 892 305 | Q5QQQ 125 306 | 66T9T 519 307 | 4T244 589 308 | 77747 174 309 | 3J698 837 310 | 39K28 665 311 | QA459 456 312 | 22342 545 313 | J8478 489 314 | Q2962 468 315 | QAAAA 958 316 | K8T87 260 317 | J4KK7 706 318 | J5J95 695 319 | 47445 724 320 | K268T 967 321 | 33299 652 322 | KKKK2 664 323 | K9JKA 711 324 | 85926 435 325 | J7K6J 511 326 | 3667J 791 327 | 229QA 633 328 | 998K7 642 329 | 8QQ77 774 330 | 6347A 497 331 | 46526 327 332 | QK327 750 333 | KAQ25 927 334 | 27T34 134 335 | T633T 208 336 | KKQK7 810 337 | 223J2 900 338 | 5KKJ5 842 339 | 99533 521 340 | A5Q85 553 341 | 54455 570 342 | JA946 582 343 | 69Q66 690 344 | 99977 701 345 | 282Q8 428 346 | 4AA42 10 347 | 75977 328 348 | 99T99 948 349 | J5353 546 350 | QT95K 285 351 | KKK3K 896 352 | 9696J 264 353 | T8275 436 354 | 45J55 80 355 | 69AAA 430 356 | 27J4J 202 357 | 6A888 404 358 | TQ5K8 819 359 | 55858 113 360 | T828T 933 361 | T8888 12 362 | 3KKKT 703 363 | 657J6 291 364 | 8699J 172 365 | 9J99T 705 366 | A22A2 229 367 | 32263 314 368 | 8QQQQ 101 369 | 2J222 354 370 | 73373 107 371 | 99398 946 372 | 2AA2J 885 373 | T66J6 184 374 | 3K8K8 903 375 | KJJKK 611 376 | 22226 781 377 | 9A2J9 191 378 | AK26J 964 379 | 8KK2Q 317 380 | 82898 883 381 | T9TTT 195 382 | 584JT 743 383 | 4AA45 61 384 | 93J79 100 385 | 3QJAK 241 386 | T74AQ 304 387 | 4Q2QQ 548 388 | KKJ27 330 389 | A9TKK 39 390 | 6J447 303 391 | 592A6 449 392 | K9928 65 393 | 9A94K 193 394 | 8T646 431 395 | Q46K3 20 396 | K5777 833 397 | Q9756 30 398 | 33838 638 399 | 65686 298 400 | A9JAJ 599 401 | 85555 784 402 | 6TAA4 286 403 | 3QQ89 446 404 | 3JT37 463 405 | 8AK5Q 230 406 | 7JAAQ 580 407 | 754TQ 74 408 | 9AQQ4 729 409 | 2933J 678 410 | 62757 575 411 | 29929 619 412 | A3AAA 216 413 | Q557Q 691 414 | A7Q8T 983 415 | 3TJQT 668 416 | A3KJA 503 417 | 7AA77 881 418 | 88288 995 419 | 7QJ3J 770 420 | 5KKJK 265 421 | 444J4 998 422 | 82J87 89 423 | T3T3J 63 424 | 2QQ76 510 425 | 5QQ25 132 426 | KKKT5 441 427 | Q822Q 954 428 | 84858 788 429 | 37627 873 430 | 22959 426 431 | K6KKJ 454 432 | 4J844 359 433 | 67JQ7 266 434 | TQ7T2 206 435 | 5QT2J 854 436 | KK985 42 437 | 3562T 877 438 | 44343 999 439 | 5J595 859 440 | 37888 657 441 | J65AK 801 442 | 77276 382 443 | 22A22 207 444 | QQ4K3 253 445 | 9K2K4 161 446 | 888Q8 863 447 | 75J77 518 448 | K2K2K 150 449 | 2JT62 398 450 | J3993 719 451 | AA88A 813 452 | 9499T 211 453 | A568Q 98 454 | 6KQ6J 962 455 | QAKA8 367 456 | 998A9 561 457 | J2357 196 458 | A797T 663 459 | 6J9J6 505 460 | 2T5T2 759 461 | K6464 381 462 | 76677 373 463 | 4K92J 33 464 | 5A8JK 447 465 | 8QQ88 660 466 | 3298A 325 467 | 37333 802 468 | JTQQT 7 469 | QQQ3A 820 470 | J5935 506 471 | K4334 2 472 | KA749 40 473 | 94QQ9 415 474 | 537KK 225 475 | 25255 913 476 | 835J9 601 477 | 55TTT 647 478 | 92J92 710 479 | 66A6A 312 480 | A8TT8 914 481 | 4KJKK 271 482 | T3242 835 483 | 3K636 623 484 | 93T5A 365 485 | J4739 816 486 | 244A5 465 487 | A9TT5 560 488 | 2JAA9 224 489 | TTT7T 356 490 | AQQAA 656 491 | QT5Q5 879 492 | 7AA7J 632 493 | 36344 127 494 | K5T89 243 495 | 797A9 562 496 | 66363 52 497 | 68585 598 498 | KQ8A9 608 499 | 999K2 21 500 | 52253 151 501 | A5595 262 502 | KTTTT 366 503 | 2922T 1000 504 | 25328 815 505 | 3T7T7 806 506 | Q2Q39 895 507 | 3J432 786 508 | JA228 782 509 | AJJ99 621 510 | 8AAQQ 809 511 | 97QAT 143 512 | 456J8 15 513 | AAJ2A 165 514 | J55J5 281 515 | K6945 322 516 | 22A2J 799 517 | 77AAA 666 518 | Q6J66 168 519 | 7QTJ5 363 520 | Q38T2 709 521 | AKT86 936 522 | QQQQK 585 523 | JA4J4 130 524 | AJA73 796 525 | 88QQQ 828 526 | QQ2Q2 390 527 | KK77K 301 528 | A5TQ9 805 529 | 96677 477 530 | J7495 628 531 | 24222 807 532 | 8QQ83 992 533 | 222K6 861 534 | 949J5 473 535 | 59873 555 536 | 9K584 564 537 | AAQ7Q 989 538 | 62J2K 445 539 | 4732A 420 540 | 2JT9K 136 541 | TT989 277 542 | JJ999 549 543 | Q9T6K 513 544 | 36J6A 97 545 | A3J32 986 546 | 8A7TJ 682 547 | T2784 59 548 | KJAAK 110 549 | 8KJ88 919 550 | AKK77 256 551 | 2J876 713 552 | K3TQ7 115 553 | 8Q6AT 973 554 | 45666 19 555 | 33335 400 556 | J43K4 851 557 | A22A9 974 558 | 8Q867 574 559 | 993KA 185 560 | 9K8Q4 464 561 | 5AAAA 949 562 | 27JJ5 686 563 | 3TTT3 606 564 | T4444 533 565 | K8838 830 566 | 75682 960 567 | J89JT 129 568 | 45A5A 886 569 | KKK6T 416 570 | AJA6A 626 571 | AAJKA 182 572 | AA2A8 73 573 | 7JK88 640 574 | JJ222 462 575 | 4A455 49 576 | 7JAKQ 812 577 | AAAA9 387 578 | 777T7 769 579 | 37K2A 348 580 | QTJ77 355 581 | KQQKA 500 582 | QQQ9Q 350 583 | 65666 111 584 | T7TT7 407 585 | 333TJ 214 586 | 78876 8 587 | 8Q478 409 588 | 8K3AT 934 589 | 6A583 814 590 | JTJAA 826 591 | 3A373 278 592 | J4J44 171 593 | 9AAA3 374 594 | 32J32 199 595 | 76TTA 858 596 | 27222 305 597 | 862K6 369 598 | QJKAA 568 599 | JK94J 524 600 | Q6QQ6 852 601 | 2TQ22 987 602 | J6AJ7 385 603 | 73A6T 106 604 | QAKQT 925 605 | 2424T 737 606 | T7ATA 620 607 | T8A47 613 608 | J2858 636 609 | K7373 484 610 | 7QK65 716 611 | K8QKK 981 612 | 52454 443 613 | AAAAJ 738 614 | 99J99 69 615 | 6AQJ8 439 616 | 774J9 798 617 | 66JJ6 210 618 | TTQTQ 35 619 | 7QJ97 694 620 | QJQQJ 918 621 | 9K999 573 622 | Q7TT7 68 623 | 46887 704 624 | T6379 661 625 | 34888 326 626 | 9A999 916 627 | 6466J 849 628 | 666J6 479 629 | QKKKK 247 630 | 46K48 336 631 | J6729 467 632 | A22A6 269 633 | 6KQKK 584 634 | 68J86 961 635 | 8KK87 670 636 | 52656 542 637 | Q4AJ3 394 638 | 79KJK 77 639 | Q8965 139 640 | 44474 240 641 | QJQQQ 434 642 | AQ449 921 643 | 57A9J 996 644 | J5835 817 645 | QQKK3 818 646 | 3943J 13 647 | 4T7A5 956 648 | 44464 517 649 | 5A55J 48 650 | 2J254 722 651 | 9JAT5 487 652 | Q4757 856 653 | 5Q55A 749 654 | ATKJ5 82 655 | J8588 142 656 | 646TQ 783 657 | 38J39 922 658 | 26J77 823 659 | 2TT4T 162 660 | 6666K 137 661 | QQQ83 758 662 | 32KJT 733 663 | 4J9K8 353 664 | KQJT7 501 665 | 6T6TK 982 666 | Q42K9 147 667 | 8734Q 538 668 | KKA67 794 669 | JQKKA 804 670 | QQ555 596 671 | 4JJ45 32 672 | 28383 904 673 | T5Q45 38 674 | 5T5TJ 221 675 | Q3K9A 29 676 | 99649 1 677 | 94247 146 678 | 4Q444 362 679 | 5637T 734 680 | 577TT 735 681 | TT244 364 682 | 56QQQ 149 683 | K2AQ3 144 684 | 9J959 493 685 | 66Q44 405 686 | 888K8 654 687 | 6J624 635 688 | 9QJKA 569 689 | K8K5K 120 690 | 24443 344 691 | 6666T 197 692 | 6T747 740 693 | 54523 935 694 | A96Q2 302 695 | AJJJA 697 696 | 2T476 90 697 | 55444 403 698 | QJ22Q 85 699 | KK9KJ 254 700 | 4938T 156 701 | 5JT8J 741 702 | Q55K3 527 703 | 627JK 894 704 | T6245 917 705 | 44864 410 706 | 77QJ3 587 707 | 823A4 457 708 | 32323 259 709 | 9T94T 609 710 | 33J8K 158 711 | 7AK4K 201 712 | 44774 957 713 | 4Q45T 180 714 | JA82K 978 715 | 333J5 872 716 | J8948 267 717 | 99933 433 718 | 4T7JJ 563 719 | 85534 862 720 | K7K8K 24 721 | JTTKK 824 722 | TQ8TT 803 723 | 62677 797 724 | QQATT 965 725 | QQ668 870 726 | 88724 551 727 | T3T43 17 728 | 99749 275 729 | 7T6J2 977 730 | 67J77 203 731 | 6T789 167 732 | 22J28 639 733 | 26744 850 734 | QQQ6Q 47 735 | QA72T 554 736 | 3AT9T 897 737 | QJTQ2 261 738 | 696JQ 631 739 | 9KKQJ 490 740 | 469T8 72 741 | QAT42 951 742 | AJ2AK 413 743 | 8AQ2T 297 744 | AJ482 255 745 | QQQKK 931 746 | AJA7A 874 747 | 34532 368 748 | 74A44 945 749 | 88989 418 750 | A2AAA 219 751 | 39999 857 752 | J7774 687 753 | Q9925 630 754 | 9JQ9Q 578 755 | 8AA38 689 756 | 8QA2A 427 757 | Q6Q99 800 758 | TTTTJ 399 759 | AA822 614 760 | ATT47 676 761 | K2AAA 514 762 | 7J696 338 763 | J3J87 88 764 | 55547 728 765 | 5A338 86 766 | 838T6 250 767 | 87QAK 970 768 | 795K7 723 769 | 7QTJ6 152 770 | 5A9KQ 494 771 | KA4TK 650 772 | Q2222 604 773 | K5953 452 774 | K2282 552 775 | 4K586 760 776 | K4444 868 777 | 724AA 516 778 | 52224 55 779 | 35Q33 58 780 | 46644 331 781 | T8325 888 782 | 9K229 388 783 | 779TT 920 784 | 97279 95 785 | JJ374 450 786 | 8JJJJ 610 787 | 84497 217 788 | 8QK4J 233 789 | KQ6T6 360 790 | 6637Q 53 791 | KK7QJ 683 792 | 4828A 215 793 | 5TT55 990 794 | J3768 536 795 | ATKTK 846 796 | 5T9K4 780 797 | 2T8AT 502 798 | 7T776 712 799 | KQ93Q 114 800 | 2474J 483 801 | QQQ46 408 802 | J5T82 718 803 | 834A9 688 804 | JT977 615 805 | 69663 296 806 | 4A638 880 807 | QQQA7 27 808 | 2K22K 377 809 | 29379 972 810 | 244J4 242 811 | K8KKK 56 812 | KTQKJ 891 813 | 87K5J 730 814 | 887AA 699 815 | 9QJQA 725 816 | 6J655 929 817 | 8692A 844 818 | 2QQQQ 194 819 | TJ79Q 969 820 | JATA9 128 821 | 8448J 103 822 | 9399J 953 823 | 98J77 371 824 | TT3J5 192 825 | J3655 924 826 | 6993K 616 827 | J8788 979 828 | K9KK3 756 829 | 57AQ4 671 830 | 88KQ7 955 831 | 6AAA6 843 832 | 9494J 105 833 | 6A2QQ 942 834 | T222T 87 835 | J9JA5 244 836 | AKA4A 198 837 | Q4635 558 838 | 2332T 889 839 | AKQQ5 827 840 | 97QQQ 337 841 | JT575 603 842 | 36336 478 843 | 4A43T 653 844 | 5QQ38 349 845 | 97777 776 846 | TQ6TT 541 847 | 57775 258 848 | 68KKK 469 849 | 92224 121 850 | 4853Q 476 851 | 2Q695 273 852 | 2J626 732 853 | 6A328 246 854 | 5QT27 959 855 | KJJ77 658 856 | 4K6KK 310 857 | JAK66 28 858 | QQK4K 16 859 | K4923 752 860 | 57555 482 861 | 46T5T 550 862 | 333Q3 496 863 | 2Q93J 755 864 | 778J3 751 865 | K77KJ 276 866 | 76A96 947 867 | QTT7T 335 868 | 4T9K6 997 869 | 26926 512 870 | 66464 522 871 | 59997 787 872 | K462A 508 873 | K4K7K 333 874 | Q3Q3Q 707 875 | A3TKK 772 876 | 7T7J7 44 877 | TAK54 455 878 | 44JKQ 287 879 | TQK49 748 880 | 37335 577 881 | Q743J 200 882 | Q4A45 236 883 | KJ62K 288 884 | 544K5 76 885 | TTTJJ 693 886 | 89999 96 887 | K8JKK 351 888 | 5JAT8 778 889 | TAAJT 67 890 | 39339 911 891 | 997K6 329 892 | 5JK88 876 893 | 338QQ 530 894 | 88889 937 895 | 884T8 526 896 | 382QA 320 897 | 86Q35 764 898 | KQ38A 412 899 | AA7A8 358 900 | 22Q2K 637 901 | A22JK 248 902 | 59855 906 903 | 33AJ3 347 904 | 42T2Q 108 905 | AQ2T6 99 906 | 8KATJ 651 907 | 9JQTT 832 908 | 84847 451 909 | 52K8K 453 910 | K6553 54 911 | 87778 499 912 | TAAJA 223 913 | 38298 643 914 | 5557Q 841 915 | 9K6K9 448 916 | 77J73 617 917 | 555K5 976 918 | A38T4 968 919 | 3333A 472 920 | 5KJ74 866 921 | 7JJ8K 708 922 | J55Q5 714 923 | 58KA4 795 924 | AAAA4 488 925 | Q8QQ7 45 926 | 58A55 311 927 | 27T7T 3 928 | 2J4KA 43 929 | TT3T9 159 930 | 475K6 109 931 | 48844 323 932 | 4T2T2 186 933 | Q7A7J 218 934 | JTJA6 744 935 | J96J4 721 936 | 8TT88 41 937 | Q5T96 417 938 | QTA6T 213 939 | 68A33 169 940 | J3TT8 34 941 | 44JK8 14 942 | 29983 540 943 | 3666J 845 944 | 436J2 685 945 | 88A88 597 946 | 889J9 313 947 | 77754 848 948 | 2TA99 406 949 | 5KK5K 535 950 | 3KJ75 547 951 | 67666 662 952 | 9T634 231 953 | QTQQQ 299 954 | J993T 745 955 | 87Q98 155 956 | AAAKQ 376 957 | 36Q43 696 958 | 67K67 952 959 | 25Q47 739 960 | 44424 228 961 | K22JQ 941 962 | 5434Q 232 963 | 8AA6Q 5 964 | 58J55 625 965 | 37535 153 966 | 66868 572 967 | 87788 384 968 | J5993 860 969 | K42K4 402 970 | 59Q7T 944 971 | J2475 495 972 | KKKK7 773 973 | 9K5Q2 341 974 | 9AQAQ 594 975 | T5974 181 976 | 42442 901 977 | T6TTT 932 978 | 25895 268 979 | 44484 212 980 | 88J63 588 981 | 22777 102 982 | Q7K77 991 983 | QK9K9 235 984 | J4544 205 985 | 7K523 985 986 | T4246 566 987 | 9TQ3A 466 988 | 884JT 644 989 | 59995 84 990 | 7772J 853 991 | JJ882 318 992 | 25522 923 993 | TTT9J 189 994 | 23333 378 995 | 58J85 141 996 | 7K45K 567 997 | JJ777 71 998 | 74A47 875 999 | 2J848 655 1000 | 93K65 966 -------------------------------------------------------------------------------- /8/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt"); 2 | 3 | const [ins, rest] = input.split("\n\n"); 4 | 5 | const pairings = rest.split("\n"); 6 | 7 | const mappings: Record = {}; 8 | 9 | let current = "AAA"; 10 | 11 | pairings.forEach((p) => { 12 | const [k, v] = p.split(" = ("); 13 | 14 | console.log(v); 15 | const [L, R] = v.replace(")", "").split(", "); 16 | 17 | mappings[k] = { L, R }; 18 | }); 19 | 20 | console.log(mappings); 21 | 22 | let i = 0; 23 | while (current !== "ZZZ") { 24 | console.log(current, mappings[current]); 25 | current = mappings[current][ins[i % ins.length]]; 26 | i++; 27 | } 28 | 29 | console.log("input?", i); 30 | -------------------------------------------------------------------------------- /8/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt"); 2 | 3 | const [ins, rest] = input.split("\n\n"); 4 | 5 | const pairings = rest.split("\n"); 6 | 7 | const mappings: Record = {}; 8 | 9 | let starting: string[] = []; 10 | 11 | pairings.forEach((p) => { 12 | const [k, v] = p.split(" = ("); 13 | 14 | if (k[2] === "A") starting.push(k); 15 | 16 | console.log(v); 17 | const [L, R] = v.replace(")", "").split(", "); 18 | 19 | mappings[k] = { L, R }; 20 | }); 21 | 22 | const allZs = () => { 23 | return starting.every((c) => c[2] === "Z"); 24 | }; 25 | 26 | console.log(mappings); 27 | 28 | // let i = 0; 29 | // while (!allZs()) { 30 | // current = current.map((c) => mappings[c]![ins[i % ins.length]]); 31 | // i++; 32 | // } 33 | 34 | const earliest = starting.map((c) => { 35 | let current = c; 36 | 37 | let i = 0; 38 | while (current[2] !== "Z") { 39 | console.log(current, mappings[current]); 40 | current = mappings[current][ins[i % ins.length]]; 41 | i++; 42 | } 43 | 44 | return i; 45 | }); 46 | 47 | // I ran this output through an LCM calculator online lol 48 | console.log("input?", earliest); 49 | -------------------------------------------------------------------------------- /8/example.txt: -------------------------------------------------------------------------------- 1 | LLR 2 | 3 | AAA = (BBB, BBB) 4 | BBB = (AAA, ZZZ) 5 | ZZZ = (ZZZ, ZZZ) -------------------------------------------------------------------------------- /8/input.txt: -------------------------------------------------------------------------------- 1 | LRRLLRRLLRRRLRLRRLRLRLRRLRLRLRLLLRRRLRLRRLLRLRRRLRRRLRLRLRRRLLRRLLRLRLRRRLRLLRRRLRLLRLRRRLRLRRRLRRRLLRRRLLRRRLRRLRRRLLRRRLRRLRRLRRLLRLRRLRRLRRRLRLRLRLRLRLRRRLLRLRRLRLRRLLRRLLRLRRLRRRLRLRLRLRRRLRRLRRLRRLRRLRRLRLRRRLRRRLRRRLRLRLLRRLRRRLRRLRLRRRLRRLRRRLRRLLRRLLLRRRR 2 | 3 | GSC = (CLG, RPF) 4 | NTQ = (RMN, HLB) 5 | LTX = (XFB, CGP) 6 | RHK = (KRS, TPX) 7 | KPK = (PRP, MKG) 8 | NKV = (BHD, DQJ) 9 | JNK = (RXN, BQX) 10 | JXJ = (JFK, CCS) 11 | LDC = (JBF, PHQ) 12 | QRS = (VPM, FDD) 13 | XRL = (SQT, VGH) 14 | VQN = (BRP, VCF) 15 | NBP = (GKC, HKC) 16 | FCH = (KLN, RQV) 17 | BQT = (KKX, RNZ) 18 | SVN = (JGN, FSL) 19 | FPL = (SDB, VQV) 20 | RMQ = (CCV, JST) 21 | DRB = (MSM, VHX) 22 | DDF = (GHC, PSX) 23 | GLR = (LFR, THG) 24 | DGL = (JGQ, DHD) 25 | RFQ = (BXJ, SRQ) 26 | XTG = (XBB, TQJ) 27 | PCL = (DDK, GNC) 28 | FVG = (JKL, CRC) 29 | GXQ = (CBS, RJS) 30 | SDR = (LFR, THG) 31 | KBM = (PCV, DBP) 32 | XPJ = (GCS, GJD) 33 | XRG = (LNK, KQL) 34 | FPQ = (TPG, MQQ) 35 | MSM = (LQG, KRF) 36 | LFR = (THX, GFC) 37 | KQK = (FQH, FCH) 38 | HPH = (HHJ, VKM) 39 | DHC = (QGV, FNH) 40 | PQQ = (KKX, KKX) 41 | TNQ = (LXD, KNG) 42 | QNB = (TLX, VLF) 43 | VKX = (BJL, GQB) 44 | DTM = (KRQ, CLV) 45 | BHS = (LFH, TVV) 46 | MCJ = (BFJ, FCS) 47 | CGQ = (MRH, SBD) 48 | FBM = (RXQ, CFR) 49 | NLQ = (QSD, LFZ) 50 | VSK = (DGR, DFT) 51 | HJG = (TFV, XJL) 52 | XFB = (NKP, FBF) 53 | JGL = (RGS, KTD) 54 | MHS = (BNM, KSK) 55 | RMG = (QNB, MHL) 56 | XSX = (XBG, GVD) 57 | FMV = (LVV, CQR) 58 | CRK = (TRN, KKG) 59 | VQV = (BPB, RFL) 60 | THN = (QVH, DVT) 61 | GNT = (RGS, KTD) 62 | DCH = (GJD, GCS) 63 | KTD = (LSF, MJC) 64 | BDC = (FDH, MSK) 65 | PRQ = (JGL, GNT) 66 | PSR = (DHF, FPL) 67 | XBB = (FRR, GSC) 68 | SFB = (HGX, DFS) 69 | VTJ = (HFH, KXN) 70 | KJV = (TKP, THL) 71 | BFF = (PLM, DGC) 72 | VBV = (XDK, LLS) 73 | KMV = (XDS, VQT) 74 | JPD = (BHL, QJF) 75 | DGR = (MTT, JCG) 76 | PGK = (VCX, NLQ) 77 | BFJ = (FHX, QFR) 78 | VSF = (VKX, CTP) 79 | PFJ = (BRP, VCF) 80 | XVN = (VCX, VCX) 81 | JQG = (SKM, THM) 82 | CXS = (CRC, JKL) 83 | RFL = (NNT, DMH) 84 | RBH = (KHM, PLR) 85 | PNT = (JCQ, XSR) 86 | XHK = (GJK, BLQ) 87 | CFR = (FHC, CTD) 88 | JPP = (JFD, FPB) 89 | RRT = (VVM, NFB) 90 | RPF = (TKG, KVK) 91 | JTF = (FBT, DLL) 92 | PSX = (PDS, JPD) 93 | TCH = (TDN, FRB) 94 | RHT = (VNR, NHB) 95 | TQJ = (GSC, FRR) 96 | MCK = (NJD, XDX) 97 | NPH = (XQF, NSL) 98 | LQQ = (LCM, PHH) 99 | VSV = (SFT, MVL) 100 | KRS = (TGR, TGR) 101 | DRR = (JXT, TSF) 102 | QRQ = (NTG, MTL) 103 | PJB = (RMN, HLB) 104 | VFC = (KPH, PKM) 105 | FHC = (CJM, FTQ) 106 | DRC = (RBC, THN) 107 | TRB = (JHX, LSC) 108 | GCS = (TRB, MDB) 109 | RCG = (MFT, FXM) 110 | HCB = (LHB, JGH) 111 | BFN = (RMG, KJH) 112 | TPG = (NGM, XHQ) 113 | JCS = (VGS, NSN) 114 | SGT = (LHX, MPF) 115 | NXM = (VPH, KGV) 116 | XNC = (LTX, PHJ) 117 | DNT = (KLS, RNC) 118 | JGN = (TNN, BXD) 119 | QJX = (XPJ, DCH) 120 | LQP = (FRK, NFS) 121 | HCL = (GBS, PGB) 122 | FDD = (XQJ, XTS) 123 | XTS = (TJL, LGJ) 124 | HLR = (TBR, FPG) 125 | DLL = (VJV, MJN) 126 | LFH = (VBM, MHT) 127 | LMD = (VGG, RHK) 128 | JKL = (CMQ, QCN) 129 | DDP = (GTH, HKM) 130 | VNL = (VVL, CFP) 131 | SGB = (MKL, DVQ) 132 | KBJ = (BDF, SXQ) 133 | DVT = (NMB, LCB) 134 | XQJ = (TJL, LGJ) 135 | HLB = (XHH, XNC) 136 | VPT = (BRF, JPP) 137 | PDS = (QJF, BHL) 138 | CGG = (PLS, SNM) 139 | SDB = (RFL, BPB) 140 | DVQ = (XSX, KXQ) 141 | XQS = (BPF, XLV) 142 | CDG = (XKV, HMT) 143 | JCG = (CFK, RPR) 144 | RBC = (DVT, QVH) 145 | BJB = (MVC, KXL) 146 | LFZ = (HTT, QTF) 147 | FTQ = (RLM, LMQ) 148 | TCT = (FPH, FCC) 149 | QXL = (BPF, XLV) 150 | MXX = (BHX, QNX) 151 | LSR = (FFJ, DMT) 152 | RTD = (KBS, GDV) 153 | TXH = (QBQ, NSF) 154 | CSB = (CBP, QDQ) 155 | GBS = (BRN, GXP) 156 | GMX = (LHX, MPF) 157 | JQV = (GMX, SGT) 158 | GML = (GLR, SDR) 159 | GCG = (RHT, KTF) 160 | RPR = (XTG, JGT) 161 | NDG = (QFD, HTD) 162 | KBK = (VFP, BSC) 163 | FVB = (RFQ, LLH) 164 | CGP = (NKP, FBF) 165 | RXQ = (FHC, CTD) 166 | KQD = (CJN, DRR) 167 | QTF = (FVH, TRV) 168 | QDQ = (FBM, SLV) 169 | NMT = (JST, CCV) 170 | BHC = (RJM, SVN) 171 | GMR = (LNT, XFP) 172 | MSK = (VQN, PFJ) 173 | CBV = (CGB, PGV) 174 | MHT = (GMC, RSH) 175 | BRN = (KQK, FXV) 176 | XXM = (JGL, GNT) 177 | VLF = (VNN, RRV) 178 | FDH = (VQN, PFJ) 179 | NFD = (MGN, GLL) 180 | THM = (PLL, VTJ) 181 | MPF = (JVN, DFC) 182 | BNG = (RNC, KLS) 183 | LGJ = (QHV, XBR) 184 | QTJ = (TVT, NBP) 185 | KRQ = (MDF, RLN) 186 | PCK = (CCS, JFK) 187 | DQV = (FLD, CSB) 188 | HDD = (FGX, XRG) 189 | TFL = (DQV, CJQ) 190 | BNM = (KMV, CVX) 191 | MLC = (CFP, VVL) 192 | SBD = (MKD, DKP) 193 | PSK = (DBV, BSF) 194 | FRB = (BBD, TPB) 195 | RKL = (HVK, DRN) 196 | HMZ = (DRR, CJN) 197 | LJK = (LBN, DDG) 198 | LSC = (MXX, VFX) 199 | TDN = (TPB, BBD) 200 | RNX = (FBT, DLL) 201 | QGJ = (KTS, RBF) 202 | RFB = (BCF, MHS) 203 | VGN = (TJP, VSF) 204 | HFH = (FPQ, PGF) 205 | HXX = (QFD, HTD) 206 | RJS = (PCK, JXJ) 207 | TRQ = (GCG, GQF) 208 | KXN = (FPQ, PGF) 209 | FMS = (XJL, TFV) 210 | NMB = (QRQ, DGD) 211 | BPF = (VMX, GXQ) 212 | HCX = (XSR, JCQ) 213 | RJR = (BNG, DNT) 214 | BQX = (GQC, VLX) 215 | DHD = (RLC, GVS) 216 | DQJ = (HJG, FMS) 217 | QFD = (TNQ, HSF) 218 | HMT = (HSG, MHM) 219 | BHD = (FMS, HJG) 220 | NDF = (PLK, RTX) 221 | GMC = (PNT, HCX) 222 | GQX = (CPB, VNP) 223 | BXD = (VNL, MLC) 224 | DTD = (XLK, BVR) 225 | KQT = (MRH, SBD) 226 | QJH = (QMD, KBJ) 227 | NFJ = (MVL, SFT) 228 | JMH = (FVB, BMP) 229 | BVF = (SFB, KSS) 230 | RBF = (JCD, NDT) 231 | QBX = (KJV, LBX) 232 | NTG = (DPX, CBV) 233 | DRL = (XXM, PRQ) 234 | QNX = (SHD, LXG) 235 | PNN = (KQD, HMZ) 236 | CCS = (TQQ, DDP) 237 | QSD = (QTF, HTT) 238 | BVN = (JNK, TRT) 239 | HSF = (KNG, LXD) 240 | BHL = (DSB, SGB) 241 | VFX = (BHX, QNX) 242 | JFH = (TCH, DCB) 243 | DBV = (SDL, CDG) 244 | TRT = (RXN, BQX) 245 | VLC = (MHS, BCF) 246 | BBM = (HCB, FMB) 247 | THG = (THX, GFC) 248 | XKV = (HSG, MHM) 249 | DSB = (MKL, DVQ) 250 | XSC = (HVK, DRN) 251 | SKM = (VTJ, PLL) 252 | QFR = (KXP, QNS) 253 | BMP = (RFQ, LLH) 254 | MLM = (KRQ, CLV) 255 | XNH = (JJJ, DHC) 256 | KPM = (RBC, THN) 257 | FGX = (LNK, KQL) 258 | TSF = (BDD, KFL) 259 | LXG = (XCG, TRP) 260 | TBR = (HFK, LMB) 261 | JFK = (TQQ, DDP) 262 | TQH = (KJG, MQD) 263 | RKT = (FGX, XRG) 264 | DJF = (DJJ, LNQ) 265 | FPM = (LRR, HJP) 266 | PCJ = (XDX, NJD) 267 | HFK = (NQN, LQQ) 268 | SHB = (RMG, KJH) 269 | KPJ = (XVN, PGK) 270 | XSH = (LNH, VPT) 271 | SQX = (BVR, XLK) 272 | KTB = (QRS, KPF) 273 | RKK = (GLM, JQG) 274 | HTT = (TRV, FVH) 275 | SDL = (XKV, HMT) 276 | HCK = (FCK, QBJ) 277 | SJF = (JQV, JLB) 278 | QMT = (FPG, TBR) 279 | HGX = (QLS, XLB) 280 | VKM = (QFF, NLD) 281 | FNH = (KQV, RFD) 282 | HPM = (TRQ, QJS) 283 | PMS = (LHM, CJL) 284 | JTK = (XPG, XPG) 285 | VMN = (SJB, JCS) 286 | LNT = (SHM, NKV) 287 | KFL = (RCB, BVF) 288 | ZZZ = (NBP, TVT) 289 | QPX = (BFF, KNR) 290 | HSG = (LBC, RCN) 291 | SLV = (CFR, RXQ) 292 | KJH = (MHL, QNB) 293 | FCK = (DSS, DSS) 294 | RLL = (GBS, PGB) 295 | VKJ = (RFB, VLC) 296 | VSJ = (CGQ, KQT) 297 | XDX = (HPH, VFJ) 298 | LCB = (DGD, QRQ) 299 | PLL = (HFH, KXN) 300 | DMH = (BSR, FQV) 301 | PPQ = (XFP, LNT) 302 | PGB = (BRN, GXP) 303 | JMN = (DFT, DGR) 304 | RVT = (KTL, SFV) 305 | JCH = (SJB, JCS) 306 | KKG = (QPX, MLL) 307 | KNB = (CPB, VNP) 308 | HKM = (VFC, BXC) 309 | QBT = (CJL, LHM) 310 | GJM = (PQQ, BQT) 311 | RLN = (LDG, JJH) 312 | RJM = (JGN, FSL) 313 | LHL = (HSC, LBV) 314 | CVX = (VQT, XDS) 315 | LVV = (MGX, DGL) 316 | NSN = (JBX, GKM) 317 | MTL = (DPX, CBV) 318 | LBN = (NDG, HXX) 319 | KLG = (DBP, PCV) 320 | DGD = (MTL, NTG) 321 | LDG = (JTK, JTK) 322 | HCR = (GMR, PPQ) 323 | DMB = (SQT, VGH) 324 | LGK = (DBV, BSF) 325 | FLG = (FCK, FCK) 326 | KXL = (TXH, LQB) 327 | MQD = (JNF, LSR) 328 | RNC = (SMQ, FPM) 329 | QFF = (NTD, VCM) 330 | QLS = (DTK, CSG) 331 | JGH = (LJQ, NSJ) 332 | FSL = (BXD, TNN) 333 | KLC = (TBT, CVN) 334 | BDF = (KBK, NDR) 335 | QMD = (SXQ, BDF) 336 | VQT = (VBL, XHK) 337 | CSC = (NLG, FQP) 338 | SJB = (VGS, NSN) 339 | NFS = (DDR, LTK) 340 | DRA = (CJN, DRR) 341 | LBX = (THL, TKP) 342 | DJJ = (PLF, PLF) 343 | MJN = (TBX, DRB) 344 | TJP = (VKX, CTP) 345 | DDR = (RLL, HCL) 346 | LQB = (QBQ, NSF) 347 | BKV = (PSR, NKS) 348 | NKP = (XCH, XNH) 349 | VCX = (QSD, QSD) 350 | FQV = (HKH, VRD) 351 | VPH = (DDF, PLQ) 352 | HVS = (VPH, KGV) 353 | BHX = (LXG, SHD) 354 | RQV = (PHB, FDQ) 355 | NSL = (MCJ, DBM) 356 | GVD = (JBT, HKN) 357 | TRN = (QPX, MLL) 358 | XCG = (CXS, FVG) 359 | KBF = (XVR, TFT) 360 | CTD = (CJM, FTQ) 361 | PRH = (FVB, BMP) 362 | TLR = (NSL, XQF) 363 | BLS = (VVM, NFB) 364 | VVL = (MRB, NTX) 365 | QGV = (RFD, KQV) 366 | SRK = (GLM, JQG) 367 | VHX = (LQG, KRF) 368 | NHB = (PNG, NQL) 369 | LLK = (XDK, LLS) 370 | GQD = (TSX, KBF) 371 | LHV = (QRS, KPF) 372 | VNR = (PNG, NQL) 373 | LBP = (PCJ, MCK) 374 | TNN = (MLC, VNL) 375 | KNR = (PLM, DGC) 376 | BMD = (SJF, GTJ) 377 | FPG = (HFK, LMB) 378 | XFP = (SHM, NKV) 379 | RSN = (LFH, TVV) 380 | FGN = (DVR, GLV) 381 | JHX = (VFX, MXX) 382 | DDG = (NDG, HXX) 383 | NQS = (NFJ, VSV) 384 | MKD = (DTM, MLM) 385 | CQQ = (KTL, SFV) 386 | DGK = (FMB, HCB) 387 | NSJ = (NKK, DRL) 388 | JTS = (GTF, KBP) 389 | VDG = (MCK, PCJ) 390 | MGN = (PVK, KLC) 391 | LBC = (SRK, RKK) 392 | CJQ = (FLD, CSB) 393 | MKG = (MHB, QPK) 394 | XVR = (PCL, QDH) 395 | QBQ = (LRB, VSJ) 396 | FXM = (LGK, PSK) 397 | LMQ = (TLR, NPH) 398 | PKM = (VBC, XXR) 399 | VJV = (TBX, DRB) 400 | CCV = (JFH, QNK) 401 | DMT = (RHS, JNG) 402 | XHQ = (PGD, TCT) 403 | DFC = (VMN, JCH) 404 | JJJ = (FNH, QGV) 405 | JNG = (KBM, KLG) 406 | THX = (RSN, BHS) 407 | TKG = (CQQ, RVT) 408 | HPN = (PDH, KPJ) 409 | BGS = (PSP, CMD) 410 | BLH = (QJX, SGJ) 411 | PRP = (QPK, MHB) 412 | PMV = (HDD, RKT) 413 | TRV = (TFL, MDD) 414 | CJL = (FMV, FJQ) 415 | JCQ = (KXF, HGT) 416 | GRS = (RBR, QNR) 417 | SGJ = (DCH, XPJ) 418 | RTX = (RJR, JJF) 419 | AAA = (TVT, NBP) 420 | XDK = (SPG, BMD) 421 | FBF = (XCH, XNH) 422 | LHM = (FMV, FJQ) 423 | SQT = (FVT, MDT) 424 | XPG = (JTF, RNX) 425 | MGX = (JGQ, DHD) 426 | PHH = (QBT, PMS) 427 | VJL = (MKG, PRP) 428 | DCB = (FRB, TDN) 429 | PRM = (BHC, QJV) 430 | FRR = (RPF, CLG) 431 | PGF = (MQQ, TPG) 432 | NQL = (MGL, SCP) 433 | CSG = (RRT, BLS) 434 | NMK = (PSR, NKS) 435 | MRH = (MKD, DKP) 436 | SFV = (HCH, FGN) 437 | BDD = (BVF, RCB) 438 | MDD = (CJQ, DQV) 439 | TGR = (PQQ, PQQ) 440 | MDT = (VBV, LLK) 441 | XXR = (MLF, TCX) 442 | DVR = (CQD, NQS) 443 | SXQ = (NDR, KBK) 444 | KBP = (QTJ, ZZZ) 445 | VRD = (TJN, FGM) 446 | VNP = (GQD, MBH) 447 | KHM = (TMM, QGJ) 448 | JCD = (KPK, VJL) 449 | BXJ = (FVP, PMV) 450 | DFT = (MTT, JCG) 451 | JRL = (VPT, LNH) 452 | HCH = (DVR, GLV) 453 | FPB = (JXF, DNF) 454 | NDR = (VFP, BSC) 455 | MQQ = (NGM, XHQ) 456 | XBM = (GLR, SDR) 457 | KQL = (RVJ, VGN) 458 | FPH = (CRK, FSD) 459 | GDV = (TQH, VRC) 460 | LCM = (PMS, QBT) 461 | NTX = (HPM, PNJ) 462 | FDQ = (NXM, HVS) 463 | KTF = (VNR, NHB) 464 | GTJ = (JQV, JLB) 465 | XHH = (LTX, PHJ) 466 | QVX = (KBS, GDV) 467 | VGG = (KRS, TPX) 468 | PFM = (GTF, GTF) 469 | KSK = (KMV, CVX) 470 | RVL = (QMD, KBJ) 471 | KXF = (NFD, HBL) 472 | VCM = (QVX, RTD) 473 | MBH = (KBF, TSX) 474 | LNK = (VGN, RVJ) 475 | TVV = (MHT, VBM) 476 | FXF = (MSK, FDH) 477 | VKB = (NMK, BKV) 478 | VGH = (MDT, FVT) 479 | NLG = (LJK, MFN) 480 | DSS = (KQD, KQD) 481 | VRG = (PFM, PFM) 482 | TQQ = (GTH, HKM) 483 | RSH = (HCX, PNT) 484 | TKP = (KJP, GGM) 485 | VRC = (MQD, KJG) 486 | HJP = (KGF, SRS) 487 | PSP = (QRF, HFJ) 488 | NKK = (XXM, PRQ) 489 | JJF = (DNT, BNG) 490 | PLF = (RBR, RBR) 491 | NJD = (HPH, VFJ) 492 | RRV = (KNB, GQX) 493 | GLV = (CQD, NQS) 494 | XBR = (DMB, XRL) 495 | SPG = (SJF, GTJ) 496 | DKX = (FXF, BDC) 497 | FQH = (RQV, KLN) 498 | QBJ = (DSS, PNN) 499 | VVM = (MNG, CSC) 500 | KXQ = (XBG, GVD) 501 | CFK = (JGT, XTG) 502 | CMA = (LQP, XBV) 503 | FCS = (QFR, FHX) 504 | FFJ = (JNG, RHS) 505 | LMB = (NQN, LQQ) 506 | TMM = (RBF, KTS) 507 | JXH = (VRG, BRX) 508 | FBT = (VJV, MJN) 509 | QCN = (HPN, MKH) 510 | XDS = (XHK, VBL) 511 | QNK = (TCH, DCB) 512 | MKL = (KXQ, XSX) 513 | MLF = (SJL, JTQ) 514 | MGL = (TMX, DKX) 515 | MTT = (CFK, RPR) 516 | KRF = (QMT, HLR) 517 | BSR = (VRD, HKH) 518 | TJL = (QHV, XBR) 519 | PCV = (NMT, RMQ) 520 | FVP = (RKT, HDD) 521 | SHM = (DQJ, BHD) 522 | PNG = (SCP, MGL) 523 | PGD = (FCC, FPH) 524 | QJS = (GCG, GQF) 525 | CFP = (MRB, NTX) 526 | QGS = (RTX, PLK) 527 | SJL = (XSC, RKL) 528 | JST = (JFH, QNK) 529 | TBX = (VHX, MSM) 530 | DDZ = (PHQ, JBF) 531 | KXP = (XBM, GML) 532 | HKC = (NDF, QGS) 533 | DHF = (VQV, SDB) 534 | JXT = (BDD, KFL) 535 | LQG = (QMT, HLR) 536 | LXD = (RBH, CKT) 537 | LXM = (XPG, XKZ) 538 | XLV = (GXQ, VMX) 539 | GLL = (PVK, KLC) 540 | TSX = (XVR, TFT) 541 | QRF = (DJF, KJM) 542 | KJG = (JNF, LSR) 543 | GQB = (XSH, JRL) 544 | GKR = (LMD, KVB) 545 | GVS = (QJH, RVL) 546 | VPM = (XQJ, XTS) 547 | QNR = (LDC, DDZ) 548 | PVK = (TBT, CVN) 549 | JCX = (SNM, PLS) 550 | HHJ = (QFF, NLD) 551 | TLX = (VNN, RRV) 552 | GTF = (QTJ, QTJ) 553 | LNQ = (PLF, GRS) 554 | VBL = (GJK, BLQ) 555 | DGC = (DGK, BBM) 556 | NDT = (VJL, KPK) 557 | KBS = (VRC, TQH) 558 | RVJ = (TJP, VSF) 559 | RBR = (LDC, LDC) 560 | PDH = (XVN, XVN) 561 | JBF = (VSK, JMN) 562 | BBD = (MQR, JXH) 563 | FVT = (VBV, LLK) 564 | VBC = (MLF, TCX) 565 | XKZ = (RNX, JTF) 566 | MNA = (JTF, RNX) 567 | VFJ = (HHJ, VKM) 568 | GLM = (SKM, THM) 569 | JNF = (FFJ, DMT) 570 | MNG = (FQP, NLG) 571 | MVL = (PRM, KLH) 572 | RHS = (KBM, KLG) 573 | CRC = (CMQ, QCN) 574 | BPB = (DMH, NNT) 575 | NLD = (VCM, NTD) 576 | XCH = (JJJ, DHC) 577 | CKT = (PLR, KHM) 578 | NNT = (BSR, FQV) 579 | GQC = (XQS, QXL) 580 | GKM = (QTH, KHG) 581 | GJD = (TRB, MDB) 582 | CGB = (VXJ, VCG) 583 | SMQ = (HJP, LRR) 584 | RNP = (BLH, KHP) 585 | MMP = (NCM, XPK) 586 | VLX = (XQS, QXL) 587 | XJL = (BVN, KGN) 588 | LRB = (CGQ, KQT) 589 | NGM = (TCT, PGD) 590 | TBT = (KTB, LHV) 591 | JLB = (SGT, GMX) 592 | HFJ = (DJF, KJM) 593 | RCN = (RKK, SRK) 594 | KJM = (DJJ, LNQ) 595 | CVN = (KTB, LHV) 596 | PHB = (NXM, HVS) 597 | KJP = (HCR, QPM) 598 | SHD = (XCG, TRP) 599 | KKX = (LQP, XBV) 600 | FHX = (KXP, QNS) 601 | CLV = (MDF, RLN) 602 | FXV = (FQH, FCH) 603 | HTD = (TNQ, HSF) 604 | CJM = (LMQ, RLM) 605 | BSF = (CDG, SDL) 606 | JVN = (VMN, JCH) 607 | KDK = (XSG, LHL) 608 | FGM = (PJB, NTQ) 609 | MRB = (PNJ, HPM) 610 | JTQ = (XSC, RKL) 611 | CJN = (TSF, JXT) 612 | RLC = (QJH, RVL) 613 | XLK = (CBK, JBG) 614 | KLN = (FDQ, PHB) 615 | JJH = (JTK, LXM) 616 | TVT = (GKC, HKC) 617 | QHV = (DMB, XRL) 618 | TCX = (SJL, JTQ) 619 | JBX = (KHG, QTH) 620 | CQD = (NFJ, VSV) 621 | KPF = (VPM, FDD) 622 | KHG = (HCF, RNP) 623 | BSC = (QBX, JVB) 624 | KVK = (CQQ, RVT) 625 | CPB = (GQD, MBH) 626 | LTK = (RLL, HCL) 627 | HVK = (XMR, BJB) 628 | TFT = (QDH, PCL) 629 | MHB = (TDF, RCG) 630 | SRQ = (PMV, FVP) 631 | NJA = (QTF, HTT) 632 | RMN = (XHH, XNC) 633 | VCG = (VDG, LBP) 634 | LSF = (JMH, PRH) 635 | THL = (GGM, KJP) 636 | PLK = (RJR, JJF) 637 | DKP = (DTM, MLM) 638 | NQN = (LCM, PHH) 639 | KNG = (RBH, CKT) 640 | GKC = (NDF, QGS) 641 | BRF = (FPB, JFD) 642 | HKH = (FGM, TJN) 643 | KTL = (HCH, FGN) 644 | HKN = (MMP, BFV) 645 | JVB = (KJV, LBX) 646 | QVH = (LCB, NMB) 647 | HHF = (XQC, GSF) 648 | VGS = (JBX, GKM) 649 | BXC = (KPH, PKM) 650 | DBM = (FCS, BFJ) 651 | QPK = (TDF, RCG) 652 | VXJ = (LBP, VDG) 653 | GGM = (HCR, QPM) 654 | LHB = (LJQ, NSJ) 655 | LJQ = (NKK, DRL) 656 | JXF = (FLG, HCK) 657 | PHJ = (XFB, CGP) 658 | MKH = (PDH, KPJ) 659 | MFT = (PSK, LGK) 660 | CBS = (PCK, JXJ) 661 | FRK = (LTK, DDR) 662 | CMQ = (HPN, MKH) 663 | QJV = (RJM, SVN) 664 | KHP = (SGJ, QJX) 665 | CQR = (MGX, DGL) 666 | FJQ = (CQR, LVV) 667 | HCF = (KHP, BLH) 668 | LFC = (LMD, KVB) 669 | DPX = (CGB, PGV) 670 | DFS = (XLB, QLS) 671 | DDK = (GKR, LFC) 672 | KLS = (FPM, SMQ) 673 | JGQ = (RLC, GVS) 674 | LBV = (HHF, STJ) 675 | JGT = (TQJ, XBB) 676 | QRN = (LHL, XSG) 677 | RFD = (QRN, KDK) 678 | HSC = (STJ, HHF) 679 | LNH = (BRF, JPP) 680 | FSD = (TRN, KKG) 681 | NSF = (VSJ, LRB) 682 | QJF = (DSB, SGB) 683 | MQR = (VRG, BRX) 684 | XMR = (MVC, KXL) 685 | VNN = (KNB, GQX) 686 | NCM = (XLP, VKJ) 687 | KTS = (JCD, NDT) 688 | MDF = (LDG, LDG) 689 | PLS = (BGS, VVD) 690 | TPX = (TGR, GJM) 691 | GJK = (SQX, DTD) 692 | CTP = (BJL, GQB) 693 | GXP = (FXV, KQK) 694 | DRN = (BJB, XMR) 695 | QDH = (GNC, DDK) 696 | FMB = (JGH, LHB) 697 | STJ = (GSF, XQC) 698 | DNF = (FLG, HCK) 699 | XSR = (KXF, HGT) 700 | RNZ = (XBV, LQP) 701 | RGS = (MJC, LSF) 702 | GFC = (BHS, RSN) 703 | GTH = (BXC, VFC) 704 | PLM = (DGK, BBM) 705 | KSS = (HGX, DFS) 706 | SCP = (TMX, DKX) 707 | RXN = (GQC, VLX) 708 | PLR = (TMM, QGJ) 709 | QTH = (HCF, RNP) 710 | BRP = (CGG, JCX) 711 | BVR = (JBG, CBK) 712 | DTK = (BLS, RRT) 713 | TPB = (MQR, JXH) 714 | MJC = (PRH, JMH) 715 | GSF = (KPM, DRC) 716 | RVA = (JBF, PHQ) 717 | BLQ = (DTD, SQX) 718 | CBK = (BFN, SHB) 719 | VBM = (GMC, RSH) 720 | NFB = (CSC, MNG) 721 | NKS = (FPL, DHF) 722 | CLG = (KVK, TKG) 723 | KLH = (QJV, BHC) 724 | XQF = (DBM, MCJ) 725 | BCF = (KSK, BNM) 726 | XLP = (RFB, VLC) 727 | MVC = (TXH, LQB) 728 | LLS = (BMD, SPG) 729 | TJN = (PJB, NTQ) 730 | FQP = (LJK, MFN) 731 | PHQ = (VSK, JMN) 732 | XLB = (DTK, CSG) 733 | MHM = (RCN, LBC) 734 | LLH = (SRQ, BXJ) 735 | FVH = (MDD, TFL) 736 | RLM = (TLR, NPH) 737 | MLL = (BFF, KNR) 738 | CBP = (FBM, SLV) 739 | MHL = (TLX, VLF) 740 | MDB = (LSC, JHX) 741 | KQV = (QRN, KDK) 742 | SNM = (BGS, VVD) 743 | KGV = (PLQ, DDF) 744 | FCC = (FSD, CRK) 745 | JFD = (JXF, DNF) 746 | NTD = (RTD, QVX) 747 | TDF = (FXM, MFT) 748 | TMX = (BDC, FXF) 749 | MFN = (LBN, DDG) 750 | KGN = (TRT, JNK) 751 | XPK = (VKJ, XLP) 752 | JBT = (MMP, BFV) 753 | PLQ = (PSX, GHC) 754 | TRP = (CXS, FVG) 755 | QPM = (GMR, PPQ) 756 | VMX = (CBS, RJS) 757 | BFV = (XPK, NCM) 758 | LRR = (KGF, SRS) 759 | KGF = (MRL, VKB) 760 | PGV = (VCG, VXJ) 761 | LHX = (JVN, DFC) 762 | KPH = (VBC, XXR) 763 | GQF = (RHT, KTF) 764 | XQC = (KPM, DRC) 765 | TFV = (BVN, KGN) 766 | VVD = (CMD, PSP) 767 | HGT = (NFD, HBL) 768 | HBL = (MGN, GLL) 769 | XBG = (JBT, HKN) 770 | XSG = (LBV, HSC) 771 | SRS = (MRL, VKB) 772 | XBV = (NFS, FRK) 773 | PNJ = (TRQ, QJS) 774 | BRX = (PFM, JTS) 775 | GHC = (JPD, PDS) 776 | RCB = (KSS, SFB) 777 | QNS = (GML, XBM) 778 | GNC = (LFC, GKR) 779 | MRL = (BKV, NMK) 780 | KVB = (VGG, RHK) 781 | VCF = (JCX, CGG) 782 | VFP = (QBX, JVB) 783 | FLD = (QDQ, CBP) 784 | JBG = (SHB, BFN) 785 | BJL = (JRL, XSH) 786 | DBP = (RMQ, NMT) 787 | SFT = (PRM, KLH) 788 | CMD = (HFJ, QRF) -------------------------------------------------------------------------------- /9/a.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | 3 | const nms = input.map((r) => r.split(" ").map(Number)); 4 | 5 | const resultArr = nms.map((numbers) => { 6 | const childSteps = [numbers]; 7 | const getCurrent = () => childSteps[childSteps.length - 1]!; 8 | while (!getCurrent().every((n) => n === getCurrent()[0])) { 9 | const current = getCurrent(); 10 | let last = current[0]; 11 | const newArr: number[] = []; 12 | 13 | for (let i = 1; i < current.length; i++) { 14 | const n = current[i]; 15 | newArr.push(n - last); 16 | last = n; 17 | } 18 | 19 | childSteps.push(newArr); 20 | } 21 | 22 | return childSteps.reduce((acc, c) => { 23 | return acc + c[c.length - 1]; 24 | }, 0); 25 | }); 26 | 27 | const sum = resultArr.reduce((acc, c) => { 28 | return acc + c; 29 | }); 30 | console.log("sum", sum); 31 | -------------------------------------------------------------------------------- /9/b.ts: -------------------------------------------------------------------------------- 1 | const input = Deno.readTextFileSync("input.txt").split("\n"); 2 | 3 | const nms = input.map((r) => r.split(" ").map(Number).reverse()); 4 | 5 | const resultArr = nms.map((numbers) => { 6 | const childSteps = [numbers]; 7 | const getCurrent = () => childSteps[childSteps.length - 1]!; 8 | while (!getCurrent().every((n) => n === getCurrent()[0])) { 9 | const current = getCurrent(); 10 | let last = current[0]; 11 | const newArr: number[] = []; 12 | 13 | for (let i = 1; i < current.length; i++) { 14 | const n = current[i]; 15 | newArr.push(n - last); 16 | last = n; 17 | } 18 | 19 | childSteps.push(newArr); 20 | } 21 | 22 | return childSteps.reduce((acc, c) => { 23 | return acc + c[c.length - 1]; 24 | }, 0); 25 | }); 26 | 27 | const sum = resultArr.reduce((acc, c) => { 28 | return acc + c; 29 | }); 30 | console.log("sum", sum); 31 | -------------------------------------------------------------------------------- /9/example.txt: -------------------------------------------------------------------------------- 1 | 0 3 6 9 12 15 2 | 1 3 6 10 15 21 3 | 10 13 16 21 30 45 -------------------------------------------------------------------------------- /deno.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "dev": "deno run --watch main.ts" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /template/a.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | console.log("input?", input); 5 | -------------------------------------------------------------------------------- /template/b.ts: -------------------------------------------------------------------------------- 1 | const input: string[] = (await Bun.file("input.txt").text()).split("\n"); 2 | // const input: string[] = (await Bun.file("example.txt").text()).split("\n"); 3 | 4 | console.log("input?", input); 5 | -------------------------------------------------------------------------------- /template/example.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t3dotgg/aoc-2023/ee21b3be018aa3dfa4c6945e68e98153f906eec2/template/example.txt -------------------------------------------------------------------------------- /template/input.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t3dotgg/aoc-2023/ee21b3be018aa3dfa4c6945e68e98153f906eec2/template/input.txt --------------------------------------------------------------------------------