diff --git a/2024/cmd/root.go b/2024/cmd/root.go index 2bef42a..eadf85f 100644 --- a/2024/cmd/root.go +++ b/2024/cmd/root.go @@ -26,6 +26,7 @@ import ( "cpatino.com/advent-of-code/2024/day15" "cpatino.com/advent-of-code/2024/day16" "cpatino.com/advent-of-code/2024/day17" + "cpatino.com/advent-of-code/2024/day18" ) var days = map[int]func(string) (interface{}, interface{}){ @@ -46,6 +47,7 @@ var days = map[int]func(string) (interface{}, interface{}){ 15: day15.Run, 16: day16.Run, 17: day17.Run, + 18: day18.Run, } var rootCmd = &cobra.Command{ diff --git a/2024/day18/day18.go b/2024/day18/day18.go new file mode 100755 index 0000000..4cc7fc7 --- /dev/null +++ b/2024/day18/day18.go @@ -0,0 +1,163 @@ +package day18 + +import ( + "bufio" + "container/heap" + "fmt" + "image" + "math" + "os" + "strconv" + "strings" +) + +type Direction int + +const ( + NORTH Direction = iota + EAST + SOUTH + WEST +) + +var transformations = map[Direction]image.Point{ + NORTH: image.Point{X: 0, Y: -1}, EAST: image.Point{X: 1, Y: 0}, + SOUTH: image.Point{X: 0, Y: 1}, WEST: image.Point{X: -1, Y: 0}, +} + +type PriorityQueue struct { + Items []image.Point + Scores map[image.Point]int + Heuristics map[image.Point]int +} + +func (pq PriorityQueue) Len() int { return len(pq.Items) } +func (pq PriorityQueue) Less(i, j int) bool { + return pq.Heuristics[pq.Items[i]] < pq.Heuristics[pq.Items[j]] +} +func (pq PriorityQueue) Swap(i, j int) { pq.Items[i], pq.Items[j] = pq.Items[j], pq.Items[i] } +func (pq *PriorityQueue) Push(x interface{}) { pq.Items = append(pq.Items, x.(image.Point)) } +func (pq *PriorityQueue) Pop() interface{} { + n := len(pq.Items) + item := pq.Items[n-1] + pq.Items = pq.Items[:n-1] + return item +} + +func (pq *PriorityQueue) Add(point image.Point) { heap.Push(pq, point) } +func (pq *PriorityQueue) Remove() image.Point { return heap.Pop(pq).(image.Point) } + +func manhattanDistance(a, b image.Point) int { + return int(math.Abs(float64(a.X-b.X)) + math.Abs(float64(a.Y-b.Y))) +} + +func aStar(grid map[image.Point]bool, initial, end image.Point, rows, cols int) map[image.Point]int { + bounds := image.Rect(0, 0, cols+1, rows+1) + pq := &PriorityQueue{[]image.Point{}, map[image.Point]int{}, map[image.Point]int{}} + heap.Init(pq) + + visited := make(map[image.Point]bool) + + pq.Scores[initial] = 0 + pq.Heuristics[initial] = 0 + manhattanDistance(initial, end) + pq.Push(initial) + + for pq.Len() > 0 { + current := pq.Remove() + + visited[current] = true + + if current == end { + return pq.Scores + } + + for _, direction := range []Direction{NORTH, EAST, SOUTH, WEST} { + next := current.Add(transformations[direction]) + if !next.In(bounds) || grid[next] { + continue + } + + newScore := pq.Scores[current] + 1 + if existingScore, exists := pq.Scores[next]; !exists || newScore < existingScore { + pq.Scores[next] = newScore + pq.Heuristics[next] = newScore + manhattanDistance(next, end) + heap.Push(pq, next) + } + } + } + + return pq.Scores +} + +func Part1(bytes []image.Point, rows, cols, steps int) int { + initial := image.Point{X: 0, Y: 0} + target := image.Point{X: cols, Y: rows} + + grid := make(map[image.Point]bool) + for _, point := range bytes[:steps] { + grid[point] = true + } + + results := aStar(grid, initial, target, rows, cols) + + return results[target] +} + +func Part2(bytes []image.Point, rows, cols int) string { + left, right := 0, len(bytes)-1 + for left < right { + middle := (left + right + 1) / 2 + if Part1(bytes, rows, cols, middle) != 0 { + left = middle + } else { + right = middle - 1 + } + } + + return fmt.Sprintf("%d,%d", bytes[left].X, bytes[left].Y) +} + +func Run(filename string) (interface{}, interface{}) { + file, err := os.Open(filename) + if err != nil { + panic(err) + } + defer file.Close() + + var bytes []image.Point + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + if line == "" { + scanner.Scan() + break + } + + parts := strings.Split(line, ",") + + xStr, yStr := parts[0], parts[1] + x, _ := strconv.Atoi(xStr) + y, _ := strconv.Atoi(yStr) + + bytes = append(bytes, image.Point{X: x, Y: y}) + } + + var params []int + line := scanner.Text() + for _, partStr := range strings.Split(line, ",") { + part, _ := strconv.Atoi(partStr) + params = append(params, part) + } + + rows, cols, steps := params[0], params[1], params[2] + + if err := scanner.Err(); err != nil { + panic(err) + } + + part1 := Part1(bytes, rows, cols, steps) + part2 := Part2(bytes, rows, cols) + + return part1, part2 +} diff --git a/2024/day18/day18_test.go b/2024/day18/day18_test.go new file mode 100755 index 0000000..cf8d988 --- /dev/null +++ b/2024/day18/day18_test.go @@ -0,0 +1,34 @@ +package day18 + +import ( + "os" + "testing" +) + +type TestCase struct { + FileName string + Part1 interface{} + Part2 interface{} +} + +func TestDay18(t *testing.T) { + tests := []TestCase{ + {"test.txt", 22, "6,1"}, + {"input.txt", 252, "5,60"}, + } + + for _, test := range tests { + if _, err := os.Stat(test.FileName); os.IsNotExist(err) { + t.Fatalf("test file does not exist: %v", test.FileName) + } + + part1, part2 := Run(test.FileName) + if test.Part1 != nil && part1 != test.Part1 { + t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1) + } + + if test.Part2 != nil && part2 != test.Part2 { + t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2) + } + } +} diff --git a/2024/day18/input.txt b/2024/day18/input.txt new file mode 100755 index 0000000..8035ebe --- /dev/null +++ b/2024/day18/input.txt @@ -0,0 +1,3452 @@ +24,5 +59,53 +35,12 +27,11 +8,1 +13,41 +63,39 +25,10 +17,43 +25,23 +38,9 +49,34 +3,7 +8,35 +12,33 +10,1 +5,1 +13,23 +55,61 +3,24 +5,41 +9,11 +9,12 +59,44 +7,3 +20,25 +35,17 +13,5 +17,44 +13,19 +17,33 +3,6 +11,45 +37,25 +8,17 +17,3 +62,67 +6,23 +17,5 +45,43 +19,4 +51,38 +67,38 +61,61 +35,13 +43,23 +50,39 +3,16 +65,45 +35,9 +43,34 +35,20 +68,69 +29,17 +19,5 +3,27 +5,43 +58,33 +53,34 +37,8 +63,57 +58,53 +43,21 +15,46 +65,53 +43,45 +51,33 +5,3 +10,33 +1,47 +54,49 +3,37 +32,3 +63,50 +41,41 +3,30 +21,5 +35,1 +50,41 +19,21 +12,23 +25,35 +45,52 +30,3 +49,47 +23,9 +63,49 +9,21 +53,49 +43,43 +25,9 +55,59 +10,37 +43,55 +51,36 +17,19 +44,43 +11,25 +39,6 +69,39 +19,6 +41,22 +5,10 +17,23 +2,15 +45,22 +7,13 +1,41 +6,33 +35,11 +43,42 +58,51 +39,48 +34,5 +43,9 +61,35 +13,24 +1,15 +13,0 +62,33 +37,23 +9,37 +1,31 +34,1 +15,45 +9,17 +17,13 +9,9 +69,68 +23,16 +11,33 +5,34 +68,65 +36,17 +0,23 +11,9 +55,53 +31,13 +57,39 +39,7 +62,65 +11,41 +22,25 +0,37 +67,61 +20,17 +0,9 +61,51 +17,48 +2,33 +0,31 +56,39 +3,19 +3,8 +13,50 +61,38 +34,21 +55,60 +57,60 +8,43 +18,7 +49,50 +67,49 +65,51 +48,53 +7,47 +23,21 +41,23 +15,33 +37,3 +68,51 +13,45 +21,35 +5,37 +3,21 +22,33 +17,29 +5,35 +43,53 +21,16 +42,43 +65,54 +65,46 +50,33 +5,15 +48,43 +44,19 +29,10 +11,36 +27,2 +61,39 +59,63 +59,54 +10,25 +47,49 +43,35 +21,11 +57,65 +15,35 +1,38 +61,62 +38,19 +63,58 +57,61 +35,7 +35,8 +13,34 +17,1 +5,45 +41,43 +21,19 +12,45 +67,58 +40,3 +65,55 +13,1 +45,19 +33,1 +18,3 +66,59 +51,35 +14,3 +17,11 +35,19 +55,40 +42,39 +40,47 +3,45 +5,9 +45,36 +1,4 +65,47 +9,45 +12,39 +35,14 +21,6 +5,11 +19,17 +11,40 +44,51 +6,37 +67,51 +45,34 +15,29 +12,3 +49,36 +51,67 +23,4 +5,23 +45,25 +28,11 +53,40 +63,47 +64,57 +3,1 +3,38 +41,54 +65,44 +16,15 +20,13 +19,15 +30,11 +67,67 +69,36 +57,64 +39,12 +53,54 +59,62 +1,22 +65,56 +1,43 +5,19 +63,38 +19,2 +53,38 +60,39 +5,47 +17,27 +11,22 +12,27 +14,13 +59,66 +46,53 +14,17 +44,53 +13,7 +0,41 +43,50 +69,43 +39,11 +15,8 +19,29 +9,39 +15,11 +53,51 +2,41 +63,30 +67,54 +26,3 +61,56 +62,53 +7,35 +35,23 +45,51 +63,69 +64,67 +16,37 +47,50 +8,23 +55,69 +9,8 +63,41 +19,14 +63,60 +25,14 +9,42 +66,47 +15,5 +69,40 +38,13 +63,52 +7,23 +57,58 +1,11 +7,6 +28,7 +1,27 +50,47 +1,17 +45,9 +17,21 +2,11 +45,41 +55,70 +31,7 +45,35 +29,23 +5,7 +1,14 +53,67 +3,10 +51,39 +2,25 +49,39 +1,21 +6,5 +3,39 +3,18 +66,69 +63,37 +18,17 +20,19 +48,19 +25,13 +14,33 +6,31 +3,36 +29,9 +53,52 +11,1 +47,19 +31,1 +3,11 +55,51 +19,9 +1,18 +2,3 +67,60 +70,63 +17,7 +13,30 +17,47 +26,7 +44,33 +3,29 +31,3 +41,47 +7,46 +59,59 +63,59 +37,17 +56,43 +7,15 +53,39 +29,2 +55,55 +1,39 +21,0 +5,25 +61,69 +53,53 +7,9 +41,8 +55,46 +37,5 +36,21 +63,67 +7,8 +59,57 +42,3 +13,38 +8,5 +53,47 +22,13 +3,31 +46,41 +46,45 +8,37 +23,22 +46,37 +69,51 +59,55 +45,21 +43,36 +58,49 +26,33 +38,17 +59,61 +70,53 +43,47 +45,17 +6,35 +61,49 +14,47 +45,33 +67,59 +62,47 +8,27 +35,4 +39,1 +11,42 +52,53 +5,20 +52,49 +7,20 +41,9 +11,31 +23,2 +35,2 +41,39 +37,12 +69,47 +9,43 +18,21 +57,48 +51,62 +49,42 +13,11 +12,21 +2,5 +3,9 +45,53 +39,4 +12,47 +9,4 +7,37 +65,62 +3,3 +7,33 +9,24 +59,60 +1,8 +5,33 +1,35 +13,47 +37,47 +64,65 +43,19 +7,17 +21,12 +11,18 +67,45 +21,13 +67,62 +59,39 +27,31 +67,34 +11,13 +37,2 +52,37 +67,66 +4,29 +16,13 +69,41 +67,35 +49,52 +5,21 +4,37 +6,3 +47,39 +11,49 +25,25 +45,2 +21,23 +67,55 +51,48 +15,17 +12,9 +11,43 +14,41 +63,43 +23,14 +63,55 +15,47 +10,21 +37,13 +35,21 +63,65 +38,23 +63,51 +59,51 +39,43 +2,27 +6,1 +16,9 +32,7 +9,41 +69,45 +23,20 +19,10 +49,68 +48,47 +70,41 +41,16 +37,10 +59,33 +69,56 +61,54 +37,7 +12,5 +47,45 +7,21 +57,66 +57,43 +34,7 +19,11 +9,16 +30,7 +29,4 +46,69 +9,23 +1,12 +6,27 +27,17 +51,69 +15,18 +67,48 +9,7 +17,9 +44,21 +62,41 +35,3 +61,67 +3,13 +43,46 +43,48 +17,10 +22,19 +67,57 +53,35 +60,47 +69,69 +41,45 +56,67 +59,47 +51,55 +16,21 +46,49 +8,25 +66,49 +9,44 +1,25 +59,65 +45,47 +58,57 +7,38 +69,60 +3,28 +15,7 +58,69 +47,47 +23,5 +49,37 +47,53 +17,2 +69,37 +6,11 +53,68 +51,63 +19,35 +13,48 +7,43 +5,17 +57,55 +13,33 +5,2 +15,25 +9,10 +56,51 +57,49 +64,51 +19,23 +59,37 +65,35 +41,12 +60,59 +15,3 +55,35 +1,37 +43,67 +59,48 +23,7 +35,5 +60,57 +65,63 +47,21 +41,50 +47,33 +37,11 +49,53 +6,45 +19,8 +14,9 +21,10 +56,49 +38,3 +16,5 +54,57 +29,1 +27,5 +47,54 +59,41 +42,21 +37,1 +47,55 +43,3 +3,17 +4,43 +47,25 +65,60 +20,3 +18,25 +2,35 +14,11 +7,18 +3,35 +3,33 +47,51 +21,15 +42,35 +66,55 +69,49 +25,11 +4,45 +11,35 +7,12 +2,21 +23,1 +17,15 +15,4 +9,1 +60,67 +17,37 +7,45 +66,41 +59,68 +13,49 +41,17 +69,63 +33,5 +69,58 +66,67 +64,63 +43,49 +55,64 +51,50 +41,5 +39,5 +13,37 +7,31 +52,45 +22,7 +40,45 +43,40 +4,33 +19,13 +67,37 +16,31 +29,3 +3,12 +62,61 +41,46 +1,33 +17,35 +19,25 +15,43 +6,43 +21,7 +4,23 +69,48 +40,15 +61,47 +51,37 +15,21 +47,46 +5,16 +67,52 +47,22 +15,44 +11,39 +10,45 +68,39 +7,7 +47,18 +47,38 +4,39 +1,1 +10,7 +13,17 +7,40 +42,19 +15,1 +62,27 +15,6 +49,35 +64,39 +69,59 +7,28 +26,5 +68,55 +39,14 +11,37 +27,7 +37,15 +57,51 +16,1 +60,45 +37,9 +1,3 +61,36 +7,1 +49,17 +55,58 +27,4 +20,37 +56,55 +3,41 +63,40 +3,5 +8,41 +15,9 +63,45 +67,43 +67,63 +51,53 +15,40 +19,3 +1,23 +47,17 +65,42 +26,9 +27,8 +67,65 +24,25 +12,15 +5,14 +51,51 +4,3 +59,42 +57,59 +1,45 +11,15 +51,68 +49,51 +62,49 +27,1 +1,20 +50,53 +39,17 +9,34 +65,67 +11,11 +8,47 +55,36 +65,59 +65,49 +25,0 +7,41 +14,21 +57,69 +58,41 +37,19 +13,20 +40,19 +40,41 +61,55 +63,61 +61,63 +37,16 +34,9 +48,39 +5,13 +57,63 +3,42 +6,15 +12,13 +68,45 +69,61 +39,45 +64,47 +69,67 +25,32 +17,46 +48,17 +13,43 +5,22 +65,57 +70,45 +70,67 +61,57 +69,55 +47,43 +32,1 +59,64 +1,30 +41,53 +4,41 +12,49 +47,41 +45,42 +9,33 +69,46 +5,8 +22,3 +29,6 +67,42 +67,47 +64,31 +35,15 +21,17 +20,21 +11,17 +25,15 +21,8 +63,63 +31,0 +39,13 +7,25 +45,40 +3,46 +37,6 +61,42 +41,10 +15,16 +14,1 +13,35 +19,1 +23,3 +42,17 +7,29 +10,15 +19,43 +32,5 +37,22 +23,13 +15,27 +46,23 +1,5 +10,13 +13,39 +23,10 +53,56 +23,15 +43,38 +1,44 +57,46 +39,20 +11,10 +49,49 +32,11 +24,11 +68,43 +45,49 +45,39 +31,17 +13,25 +11,6 +25,5 +62,43 +41,19 +21,3 +29,16 +47,44 +9,35 +13,3 +65,39 +7,19 +5,39 +43,33 +66,65 +13,14 +13,9 +3,23 +10,39 +33,7 +18,13 +1,26 +67,69 +3,32 +31,5 +59,49 +13,13 +43,51 +11,2 +43,17 +3,0 +49,57 +33,11 +67,36 +35,53 +10,47 +63,56 +65,41 +9,47 +47,20 +19,37 +21,1 +59,40 +54,51 +25,19 +48,35 +69,57 +43,39 +43,41 +45,23 +1,13 +21,9 +9,13 +8,21 +37,48 +15,12 +41,1 +65,69 +57,42 +15,23 +63,68 +53,69 +8,11 +57,38 +68,63 +19,40 +47,48 +61,70 +25,12 +61,64 +55,68 +24,17 +57,62 +44,47 +9,29 +59,69 +39,15 +7,11 +61,50 +1,9 +41,44 +1,2 +16,49 +7,39 +47,37 +67,41 +60,51 +67,50 +45,37 +11,47 +33,3 +24,7 +57,67 +61,53 +69,65 +39,18 +36,15 +46,25 +67,39 +36,5 +43,37 +65,65 +66,39 +15,49 +49,55 +39,23 +1,19 +1,29 +45,45 +29,5 +51,16 +61,43 +27,13 +49,41 +61,45 +53,37 +12,43 +67,53 +63,53 +13,36 +17,40 +20,45 +65,61 +35,10 +1,7 +57,35 +25,7 +44,17 +59,43 +55,49 +4,13 +69,35 +37,21 +65,43 +4,19 +14,43 +41,3 +13,26 +69,53 +25,43 +15,30 +19,41 +68,21 +69,16 +6,57 +14,65 +19,65 +19,53 +53,19 +61,13 +64,5 +55,17 +63,33 +21,43 +32,33 +25,63 +33,54 +34,69 +5,57 +25,40 +27,12 +27,29 +30,39 +47,65 +51,42 +31,31 +45,15 +21,42 +45,61 +23,53 +33,43 +27,39 +23,30 +67,29 +49,33 +35,25 +30,27 +60,19 +51,19 +65,16 +65,22 +46,9 +21,30 +19,52 +57,25 +11,61 +61,7 +11,65 +15,24 +61,15 +15,58 +43,26 +42,65 +55,19 +21,69 +57,57 +47,27 +33,21 +67,8 +56,13 +67,22 +48,3 +36,45 +43,10 +21,41 +25,66 +67,1 +51,9 +27,42 +45,16 +58,17 +21,36 +47,67 +7,30 +35,59 +34,59 +44,31 +7,59 +50,19 +31,9 +63,20 +46,33 +31,11 +0,61 +20,65 +49,25 +68,1 +33,31 +52,61 +52,15 +20,33 +50,61 +57,21 +47,35 +31,57 +54,35 +63,22 +11,27 +51,27 +33,22 +36,25 +54,31 +49,19 +17,45 +41,65 +61,26 +38,37 +32,29 +5,5 +50,5 +59,56 +35,29 +23,38 +23,57 +41,21 +37,69 +47,11 +46,57 +69,29 +3,15 +27,14 +3,50 +35,57 +45,57 +19,42 +54,11 +61,59 +21,37 +29,26 +20,55 +63,19 +29,39 +36,67 +51,11 +15,59 +56,25 +66,19 +27,30 +43,6 +17,62 +30,63 +13,59 +55,15 +15,15 +67,24 +11,30 +40,69 +7,53 +45,60 +31,51 +27,47 +1,69 +41,35 +59,27 +52,5 +33,19 +14,39 +31,18 +56,7 +69,9 +19,7 +27,20 +65,9 +45,31 +49,2 +36,53 +39,31 +67,9 +47,1 +28,31 +17,67 +13,60 +7,67 +11,29 +39,42 +5,69 +29,11 +15,61 +26,17 +55,47 +67,23 +49,13 +13,15 +61,5 +32,31 +53,55 +37,33 +32,63 +62,11 +47,5 +67,2 +5,64 +50,17 +25,60 +47,59 +49,59 +29,31 +47,0 +37,49 +62,7 +34,41 +9,56 +68,5 +4,65 +23,43 +63,2 +37,29 +39,63 +21,68 +27,63 +59,45 +19,68 +51,58 +1,65 +27,64 +11,52 +16,61 +42,55 +53,3 +44,69 +53,45 +29,61 +48,61 +34,37 +57,20 +51,22 +38,25 +67,7 +63,1 +49,29 +37,28 +35,69 +39,34 +10,19 +55,33 +63,25 +5,51 +17,54 +31,29 +56,53 +55,7 +3,53 +14,69 +2,57 +54,7 +29,38 +9,49 +24,53 +54,43 +27,21 +30,53 +32,37 +36,43 +41,55 +38,49 +54,9 +41,51 +3,51 +47,62 +34,25 +16,53 +19,33 +51,49 +53,9 +13,55 +35,66 +9,54 +39,33 +47,29 +37,43 +43,15 +54,63 +60,7 +44,9 +25,3 +52,9 +59,7 +29,15 +54,25 +42,49 +7,69 +25,65 +38,61 +11,58 +58,25 +64,35 +23,27 +47,8 +39,47 +49,7 +21,31 +29,27 +45,67 +63,3 +27,58 +48,59 +51,43 +11,63 +40,39 +67,25 +33,41 +22,43 +60,1 +48,29 +20,23 +43,1 +31,61 +46,15 +18,65 +13,21 +14,61 +5,48 +43,69 +32,55 +49,31 +35,24 +65,14 +3,60 +59,5 +50,13 +29,35 +31,15 +15,63 +7,49 +1,56 +17,57 +55,37 +41,57 +5,49 +43,59 +32,25 +40,23 +33,61 +55,57 +17,22 +16,51 +19,49 +29,33 +47,13 +7,65 +57,9 +39,67 +12,65 +31,41 +35,27 +43,13 +49,10 +32,13 +29,67 +55,11 +27,41 +19,19 +3,55 +3,62 +35,52 +54,65 +56,17 +55,5 +17,42 +15,36 +29,50 +23,45 +60,25 +59,15 +11,23 +1,54 +19,59 +69,27 +47,63 +57,29 +61,6 +11,3 +29,19 +69,11 +21,54 +41,29 +29,40 +33,33 +59,21 +23,64 +31,66 +13,27 +5,58 +53,42 +50,27 +27,59 +13,68 +25,55 +58,7 +26,23 +38,67 +35,37 +45,66 +2,51 +68,9 +39,39 +41,64 +24,45 +57,10 +16,59 +53,65 +37,67 +39,30 +35,49 +33,53 +21,49 +39,62 +29,57 +47,9 +28,15 +46,5 +37,55 +23,41 +33,65 +18,27 +45,1 +12,59 +35,51 +9,59 +29,34 +69,21 +49,46 +26,69 +63,23 +59,9 +13,54 +29,51 +67,31 +25,21 +21,60 +32,41 +33,14 +23,55 +36,59 +35,58 +25,47 +13,63 +12,67 +28,23 +15,57 +33,15 +8,69 +65,23 +39,9 +51,70 +39,68 +42,61 +41,37 +33,59 +50,65 +37,59 +25,17 +60,29 +67,13 +19,67 +25,1 +38,57 +61,1 +17,31 +67,32 +68,29 +42,67 +22,69 +43,63 +25,30 +65,17 +1,61 +48,25 +57,7 +3,69 +33,37 +27,33 +34,47 +35,67 +65,36 +29,25 +56,3 +64,11 +51,41 +29,29 +55,39 +55,21 +49,3 +57,11 +37,39 +69,6 +65,5 +45,3 +53,27 +21,33 +32,9 +39,35 +17,63 +63,27 +21,65 +7,5 +35,43 +18,35 +51,1 +9,30 +68,19 +23,49 +19,27 +42,15 +25,33 +30,15 +11,62 +19,36 +28,53 +65,8 +52,31 +11,54 +40,35 +15,66 +25,27 +39,27 +1,49 +27,15 +57,1 +23,69 +63,11 +29,20 +53,22 +55,32 +23,33 +52,67 +24,61 +23,29 +47,3 +49,12 +28,49 +59,19 +49,27 +57,32 +30,19 +49,21 +27,55 +27,45 +33,12 +51,10 +3,49 +43,11 +59,17 +53,31 +18,63 +61,9 +29,37 +48,15 +54,15 +63,36 +61,37 +10,3 +33,57 +26,67 +8,67 +49,11 +59,31 +28,69 +63,13 +45,29 +61,11 +41,32 +64,23 +61,3 +22,47 +59,23 +59,22 +3,61 +59,29 +29,7 +1,66 +4,55 +0,49 +18,67 +43,4 +63,15 +43,12 +13,62 +33,35 +19,58 +59,35 +43,61 +63,35 +3,70 +37,56 +54,13 +3,59 +13,51 +58,19 +2,45 +1,59 +25,53 +38,31 +69,4 +3,47 +21,59 +21,64 +17,17 +65,0 +25,49 +49,15 +45,63 +61,27 +27,65 +34,29 +32,47 +15,69 +19,69 +16,33 +69,19 +4,63 +49,65 +28,27 +38,33 +41,25 +69,31 +25,37 +31,40 +29,47 +17,25 +30,31 +53,23 +55,56 +11,69 +7,63 +62,17 +37,36 +38,41 +38,55 +43,29 +22,39 +38,59 +61,14 +47,31 +38,45 +35,61 +60,35 +20,53 +57,37 +43,68 +33,17 +57,53 +45,28 +27,67 +8,31 +26,27 +31,24 +31,37 +18,31 +67,15 +56,11 +21,28 +55,45 +10,69 +59,25 +53,0 +13,31 +23,11 +60,11 +67,18 +51,3 +7,57 +45,55 +15,13 +64,29 +31,22 +63,9 +52,33 +63,17 +65,2 +15,51 +55,16 +53,29 +31,36 +32,69 +41,27 +30,45 +48,67 +51,25 +53,20 +6,59 +51,17 +18,49 +69,32 +31,21 +21,57 +31,58 +68,27 +53,1 +37,37 +51,7 +15,56 +53,2 +27,54 +9,19 +28,47 +39,25 +47,69 +37,60 +37,35 +67,27 +67,11 +67,19 +55,31 +47,57 +66,27 +33,66 +21,32 +21,61 +45,26 +11,55 +51,21 +24,33 +53,63 +9,64 +21,39 +13,29 +21,50 +65,34 +18,33 +51,47 +46,11 +30,49 +57,45 +65,32 +49,14 +15,55 +25,51 +46,3 +59,4 +36,27 +65,15 +37,65 +67,14 +61,19 +31,63 +53,13 +21,67 +30,69 +38,27 +62,19 +8,59 +21,47 +9,50 +37,44 +17,49 +24,69 +58,27 +27,28 +52,65 +49,67 +27,57 +11,68 +29,43 +23,25 +41,63 +25,58 +9,63 +9,5 +61,33 +26,49 +31,42 +20,47 +40,65 +17,20 +59,16 +9,69 +69,33 +61,65 +65,12 +35,30 +49,43 +45,65 +19,60 +22,55 +29,32 +5,61 +55,23 +3,65 +31,19 +51,23 +17,39 +19,31 +37,50 +27,23 +23,39 +5,56 +37,27 +28,41 +33,50 +29,36 +40,9 +41,15 +31,52 +16,17 +55,44 +23,51 +5,53 +62,45 +39,69 +30,23 +26,35 +21,45 +33,26 +15,31 +15,53 +43,7 +26,47 +7,55 +36,37 +8,61 +37,51 +5,29 +45,4 +46,63 +39,53 +58,9 +27,56 +19,70 +14,57 +6,49 +59,67 +23,67 +67,5 +43,27 +23,19 +31,39 +41,28 +15,28 +14,51 +37,61 +6,61 +5,68 +21,62 +65,31 +69,30 +55,1 +69,23 +51,57 +21,53 +41,11 +65,10 +57,3 +20,27 +45,11 +45,59 +11,56 +54,5 +51,59 +15,39 +42,31 +59,34 +10,61 +9,15 +31,33 +13,69 +51,24 +59,24 +32,19 +33,44 +35,31 +45,69 +49,23 +40,55 +65,29 +63,7 +67,17 +9,53 +60,21 +41,69 +51,61 +67,33 +10,51 +31,59 +27,25 +55,63 +23,17 +8,55 +8,49 +53,46 +29,64 +52,11 +35,45 +57,23 +7,64 +23,61 +26,53 +11,32 +61,29 +69,13 +7,66 +39,65 +30,67 +38,65 +23,37 +67,16 +35,56 +59,13 +54,61 +17,59 +51,31 +49,32 +39,59 +51,65 +53,33 +39,55 +7,51 +25,56 +69,7 +11,59 +43,57 +69,14 +5,66 +41,60 +11,53 +25,67 +68,11 +9,25 +52,19 +35,39 +17,65 +27,62 +33,18 +26,51 +55,34 +48,55 +34,63 +56,23 +33,60 +57,5 +49,1 +11,51 +29,49 +41,59 +25,26 +26,39 +44,1 +53,7 +55,38 +37,31 +40,51 +57,28 +45,27 +61,41 +21,29 +4,53 +61,21 +29,46 +28,67 +33,64 +1,63 +37,38 +40,37 +57,47 +29,59 +9,31 +28,61 +29,44 +35,41 +27,19 +21,25 +9,27 +41,67 +31,65 +26,19 +55,67 +29,21 +39,41 +6,53 +49,45 +29,66 +39,52 +20,49 +49,61 +11,57 +49,22 +49,5 +5,31 +66,3 +27,35 +60,15 +17,69 +59,11 +45,5 +35,62 +47,28 +51,28 +22,57 +29,65 +27,61 +53,11 +41,61 +27,9 +56,29 +31,67 +51,8 +22,51 +25,31 +37,52 +21,66 +47,61 +11,7 +63,31 +9,3 +53,17 +39,21 +33,38 +55,65 +33,9 +44,27 +41,58 +28,55 +65,27 +34,33 +21,55 +31,35 +39,51 +11,21 +39,54 +33,51 +35,35 +54,29 +31,69 +58,37 +53,24 +33,67 +45,58 +23,62 +1,60 +61,4 +30,55 +59,2 +23,35 +49,26 +67,3 +18,45 +49,9 +51,56 +36,63 +25,41 +48,31 +19,38 +48,7 +67,21 +23,47 +50,1 +53,61 +13,65 +33,25 +51,44 +61,22 +1,55 +9,67 +27,53 +61,23 +70,23 +62,25 +24,47 +40,31 +5,59 +23,52 +17,51 +18,51 +53,59 +31,43 +33,47 +17,38 +20,59 +24,35 +9,65 +19,57 +39,19 +51,13 +37,53 +29,45 +1,51 +17,24 +46,31 +33,23 +6,51 +25,44 +43,58 +65,1 +57,14 +31,47 +43,5 +33,16 +33,20 +18,57 +15,19 +5,55 +15,37 +25,42 +22,59 +51,29 +41,62 +31,53 +23,23 +3,25 +52,27 +27,43 +63,28 +1,67 +24,49 +19,55 +1,48 +3,63 +27,51 +33,29 +49,8 +53,25 +6,69 +39,49 +59,12 +33,27 +33,68 +53,15 +55,18 +21,27 +3,48 +30,29 +65,37 +23,26 +67,12 +51,45 +49,63 +15,64 +37,45 +59,1 +33,13 +13,57 +49,64 +44,63 +69,3 +7,61 +61,17 +50,59 +47,15 +47,23 +27,37 +17,64 +16,67 +55,43 +63,16 +51,6 +17,28 +33,45 +45,6 +27,24 +10,27 +19,18 +47,7 +24,57 +42,1 +39,37 +11,19 +25,61 +37,57 +32,57 +65,20 +23,46 +68,25 +52,13 +15,65 +7,27 +37,30 +57,36 +57,13 +45,56 +25,45 +21,51 +60,33 +55,3 +35,32 +35,47 +55,9 +55,26 +65,7 +24,51 +31,45 +63,29 +0,69 +37,63 +47,64 +13,53 +57,30 +17,55 +49,24 +21,34 +25,59 +55,29 +29,69 +2,67 +39,61 +2,63 +48,5 +27,27 +23,42 +24,67 +61,25 +3,43 +40,5 +49,66 +35,50 +66,29 +40,27 +27,3 +31,49 +23,28 +35,55 +59,30 +62,31 +19,63 +11,5 +62,9 +70,9 +4,59 +2,53 +41,31 +57,22 +40,59 +19,30 +41,7 +64,15 +65,24 +33,69 +37,64 +52,59 +66,5 +69,34 +29,58 +58,1 +3,67 +35,42 +63,6 +64,9 +23,63 +24,23 +13,8 +5,26 +33,63 +14,55 +7,54 +37,40 +29,41 +17,61 +44,65 +41,13 +23,31 +34,35 +33,48 +5,65 +69,17 +55,27 +55,2 +67,6 +43,65 +69,1 +7,62 +36,35 +9,55 +23,36 +28,35 +27,36 +55,25 +59,3 +31,27 +33,52 +47,66 +43,56 +12,17 +58,13 +41,70 +1,57 +9,51 +39,29 +53,41 +33,39 +63,5 +70,25 +70,17 +39,57 +23,59 +24,21 +29,60 +35,54 +55,13 +49,30 +48,57 +21,44 +41,26 +65,11 +59,28 +13,61 +43,8 +29,63 +31,55 +55,20 +17,41 +45,13 +33,28 +53,57 +16,25 +25,39 +33,46 +9,66 +35,63 +25,29 +35,33 +25,18 +40,1 +29,55 +17,53 +31,44 +19,45 +31,48 +33,55 +51,5 +57,27 +35,40 +3,57 +31,60 +57,4 +65,26 +43,25 +69,15 +13,67 +57,33 +1,53 +3,68 +62,13 +11,64 +13,52 +37,68 +51,2 +21,21 +5,27 +10,59 +41,24 +15,41 +25,69 +27,69 +41,33 +46,13 +25,64 +65,3 +61,18 +21,63 +65,33 +55,4 +63,21 +62,3 +29,13 +47,12 +13,28 +31,34 +30,57 +49,69 +44,13 +21,40 +33,49 +59,8 +53,21 +9,57 +25,38 +39,3 +57,31 +51,15 +19,61 +17,56 +19,39 +15,67 +43,31 +9,61 +57,19 +57,15 +64,45 +19,47 +50,21 +30,13 +4,51 +37,41 +28,21 +44,61 +53,5 +41,49 +36,33 +55,41 +53,43 +22,23 +31,25 +25,57 +27,44 +19,51 +57,41 +17,68 +69,25 +45,68 +31,23 +14,31 +50,57 +23,65 +53,18 +1,58 +65,21 +5,63 +27,49 +65,13 +29,53 +69,5 +11,67 +52,29 +57,17 +35,65 +45,7 +26,61 +24,55 +57,0 +65,25 +65,19 +5,67 +61,31 +8,51 +43,30 +43,24 +56,37 +10,48 +0,55 +17,26 +28,51 +42,34 +52,24 +22,24 +58,55 +50,24 +24,40 +45,38 +52,4 +16,30 +34,46 +43,28 +5,30 +4,48 +70,47 +2,13 +19,24 +24,56 +20,63 +35,38 +17,34 +10,31 +34,45 +10,0 +48,38 +55,6 +11,48 +50,38 +10,50 +58,11 +14,24 +68,26 +29,56 +60,27 +67,68 +18,59 +66,48 +6,2 +59,14 +13,10 +48,13 +50,69 +65,64 +42,32 +42,26 +47,26 +22,32 +60,65 +56,10 +58,43 +22,49 +56,47 +32,36 +20,62 +69,20 +41,0 +36,28 +18,23 +49,54 +18,26 +18,2 +2,70 +18,29 +48,27 +56,8 +34,56 +65,38 +38,0 +68,20 +50,18 +54,17 +18,68 +60,54 +68,66 +10,63 +58,4 +18,50 +12,18 +34,4 +34,30 +22,36 +36,0 +60,37 +4,8 +56,45 +43,2 +6,12 +52,18 +60,55 +32,48 +60,61 +51,30 +26,14 +23,8 +43,32 +50,35 +62,46 +62,44 +26,57 +14,34 +26,2 +62,40 +44,26 +39,22 +22,63 +68,42 +20,7 +38,48 +57,52 +57,6 +68,32 +22,1 +24,2 +38,16 +24,46 +18,37 +16,55 +56,65 +44,41 +60,13 +28,1 +48,21 +54,8 +26,25 +32,6 +60,3 +8,3 +36,41 +13,2 +60,8 +58,0 +16,42 +68,0 +50,20 +24,58 +39,26 +13,32 +44,30 +34,28 +36,3 +70,31 +62,5 +36,44 +54,48 +36,60 +0,30 +68,31 +24,15 +22,5 +23,54 +46,29 +30,18 +57,34 +49,38 +50,58 +68,18 +20,28 +10,17 +16,0 +14,0 +25,6 +47,16 +42,37 +16,54 +56,32 +0,8 +52,36 +55,62 +31,10 +38,21 +66,36 +56,24 +6,18 +55,54 +36,22 +7,48 +28,50 +11,8 +55,12 +42,50 +40,60 +44,36 +24,22 +5,18 +8,20 +6,22 +26,20 +24,26 +22,27 +24,13 +46,4 +30,46 +8,18 +0,53 +26,37 +10,12 +20,31 +52,23 +59,0 +40,4 +28,52 +52,35 +23,40 +23,32 +70,7 +36,26 +32,51 +60,34 +70,62 +19,46 +8,22 +46,6 +34,61 +36,42 +24,65 +44,52 +57,40 +61,60 +32,4 +59,52 +18,69 +36,49 +48,28 +12,11 +48,65 +18,12 +36,9 +54,46 +32,15 +68,10 +26,40 +44,23 +37,62 +22,20 +25,54 +9,48 +32,8 +70,64 +64,34 +32,35 +20,41 +49,70 +69,2 +54,45 +16,7 +69,24 +8,33 +36,12 +22,65 +36,1 +34,15 +20,50 +70,56 +9,26 +64,22 +39,0 +12,50 +5,46 +20,11 +35,18 +28,10 +38,69 +38,11 +38,47 +52,62 +28,9 +50,10 +42,8 +58,24 +3,64 +64,56 +31,46 +8,6 +61,46 +38,32 +50,31 +51,0 +67,10 +18,22 +28,6 +70,24 +28,36 +20,39 +70,37 +41,36 +42,13 +40,36 +67,28 +34,50 +17,14 +16,58 +60,66 +62,35 +64,0 +28,12 +35,6 +4,5 +7,4 +2,14 +10,28 +20,29 +32,28 +59,32 +22,31 +64,40 +42,54 +50,2 +42,7 +44,40 +39,60 +14,15 +58,32 +38,56 +39,46 +60,12 +64,28 +52,66 +59,6 +68,24 +25,4 +68,2 +53,14 +22,54 +56,38 +61,52 +44,68 +30,38 +56,26 +26,52 +56,34 +30,34 +51,46 +40,14 +43,52 +48,63 +8,19 +22,60 +57,2 +20,42 +40,25 +8,28 +54,70 +24,41 +30,43 +46,22 +2,68 +6,9 +64,55 +18,19 +33,10 +35,28 +38,5 +62,34 +70,49 +2,40 +51,4 +8,63 +69,38 +30,21 +70,34 +23,34 +22,14 +54,3 +58,22 +30,5 +4,28 +66,43 +27,40 +64,10 +14,32 +27,10 +42,38 +20,10 +50,22 +58,14 +40,10 +32,10 +55,22 +43,22 +44,37 +68,44 +13,6 +70,57 +56,63 +0,48 +25,16 +24,52 +8,13 +14,26 +34,51 +58,30 +63,14 +52,20 +27,0 +26,26 +19,0 +39,56 +30,50 +65,48 +66,26 +68,14 +70,42 +56,60 +51,32 +70,59 +58,3 +20,4 +26,8 +37,4 +17,18 +69,12 +22,8 +65,4 +38,12 +5,42 +64,37 +70,0 +54,10 +22,22 +54,22 +65,40 +36,30 +31,4 +66,21 +58,34 +22,12 +56,33 +40,21 +5,32 +44,3 +38,22 +20,40 +15,20 +42,12 +46,44 +2,69 +1,68 +48,62 +6,24 +30,37 +20,8 +21,4 +39,38 +70,4 +62,38 +53,70 +20,61 +34,12 +16,41 +29,42 +56,57 +58,10 +17,16 +28,25 +20,35 +24,31 +49,20 +47,34 +38,63 +33,42 +52,68 +20,64 +42,23 +14,49 +60,44 +28,44 +12,6 +38,7 +69,52 +46,21 +12,4 +32,60 +8,24 +60,42 +36,13 +63,26 +22,38 +28,32 +26,68 +50,45 +60,23 +12,54 +55,0 +68,33 +51,20 +1,36 +12,55 +12,53 +34,54 +25,68 +28,56 +32,34 +58,46 +70,18 +32,27 +22,44 +40,2 +18,41 +37,14 +69,28 +30,35 +66,57 +16,18 +41,30 +63,10 +64,43 +2,38 +5,24 +58,44 +50,6 +16,20 +33,36 +58,28 +7,14 +24,10 +30,51 +60,16 +40,28 +41,18 +30,41 +16,29 +38,30 +30,65 +67,44 +52,34 +32,66 +46,36 +68,36 +22,52 +68,15 +62,28 +56,56 +26,28 +42,52 +43,66 +29,0 +63,18 +64,21 +34,22 +30,40 +48,42 +28,34 +12,58 +4,30 +50,46 +8,65 +9,32 +52,3 +32,38 +64,41 +13,56 +36,4 +33,32 +13,4 +18,18 +20,60 +62,0 +6,6 +66,44 +8,14 +32,46 +31,54 +7,16 +22,4 +27,32 +29,8 +30,58 +20,26 +26,56 +21,56 +63,62 +64,12 +55,10 +68,49 +26,29 +31,12 +61,28 +36,6 +6,50 +70,5 +5,60 +34,49 +41,14 +46,52 +8,10 +10,22 +20,52 +57,70 +38,8 +1,46 +36,24 +10,43 +33,70 +58,2 +44,7 +18,28 +44,22 +46,39 +38,36 +13,44 +42,14 +58,5 +46,67 +20,46 +52,40 +68,35 +23,12 +20,68 +62,20 +4,57 +8,66 +4,50 +68,38 +62,14 +52,6 +16,26 +32,53 +18,36 +4,22 +44,8 +28,39 +31,50 +22,29 +27,22 +0,1 +15,26 +6,7 +47,60 +30,20 +46,27 +12,25 +4,14 +52,8 +39,50 +13,66 +20,70 +68,34 +62,62 +37,32 +41,4 +64,8 +68,68 +5,4 +45,12 +24,54 +29,48 +22,9 +68,54 +50,7 +54,42 +24,37 +68,67 +16,44 +0,62 +56,48 +10,14 +16,11 +58,58 +58,45 +24,42 +36,14 +8,0 +20,16 +32,68 +26,42 +0,40 +23,70 +41,68 +53,36 +30,32 +19,54 +32,12 +40,64 +54,58 +43,64 +28,0 +69,50 +10,23 +2,0 +11,34 +66,33 +45,20 +12,36 +31,30 +40,13 +42,63 +50,70 +38,62 +30,42 +38,50 +5,0 +31,2 +66,28 +19,44 +8,53 +70,51 +7,50 +48,70 +36,58 +8,62 +6,60 +44,59 +37,58 +2,64 +9,70 +10,9 +4,17 +36,47 +14,45 +60,24 +48,12 +40,70 +8,40 +69,10 +27,34 +53,12 +36,66 +57,18 +70,69 +54,34 +12,48 +7,42 +16,28 +3,20 +50,15 +64,33 +66,13 +24,9 +12,57 +16,68 +64,32 +58,64 +64,7 +48,32 +60,26 +40,6 +8,36 +2,24 +58,8 +12,26 +24,68 +58,39 +18,32 +64,42 +48,9 +68,41 +22,2 +16,32 +6,64 +2,26 +26,44 +9,52 +6,52 +70,1 +44,28 +24,14 +34,44 +40,20 +40,11 +20,20 +60,31 +19,32 +23,0 +45,54 +66,2 +66,30 +34,53 +6,16 +13,16 +19,26 +8,64 +48,60 +14,50 +26,70 +28,30 +12,69 +61,20 +59,26 +12,29 +12,56 +12,30 +63,46 +70,60 +66,42 +6,29 +15,38 +50,51 +60,14 +40,40 +68,60 +36,57 +60,56 +22,35 +43,54 +46,42 +30,30 +22,50 +28,64 +6,20 +1,62 +23,44 +45,30 +70,15 +24,59 +58,68 +26,30 +28,57 +48,30 +62,22 +34,68 +48,54 +18,54 +26,59 +36,20 +28,68 +27,66 +50,64 +40,8 +62,2 +2,22 +58,16 +12,1 +3,26 +16,66 +36,64 +40,52 +66,15 +66,7 +4,61 +46,50 +32,45 +34,20 +44,62 +4,67 +31,64 +42,36 +70,29 +27,38 +15,2 +50,68 +16,19 +18,9 +42,2 +36,69 +67,20 +62,64 +62,4 +70,58 +0,26 +70,33 +14,52 +7,44 +62,51 +54,36 +42,66 +14,29 +18,15 +34,32 +46,59 +6,19 +40,32 +66,6 +22,41 +17,50 +4,47 +14,63 +11,0 +9,40 +47,42 +12,64 +56,66 +14,23 +2,30 +0,28 +31,38 +40,57 +10,58 +48,66 +56,46 +36,8 +66,0 +56,16 +0,70 +40,43 +28,28 +12,42 +32,65 +52,50 +15,14 +42,40 +70,48 +30,16 +64,14 +43,60 +8,38 +23,56 +24,60 +2,1 +64,19 +48,64 +34,23 +31,70 +26,1 +4,54 +50,56 +10,55 +70,61 +54,4 +14,44 +13,70 +3,56 +59,38 +28,46 +27,26 +30,47 +42,4 +30,60 +52,46 +58,38 +15,34 +68,7 +6,0 +26,13 +66,1 +26,62 +17,70 +42,0 +18,64 +53,26 +1,16 +58,15 +28,29 +32,14 +11,14 +35,34 +28,66 +46,51 +60,70 +56,6 +6,8 +44,18 +36,23 +14,42 +25,8 +36,19 +20,69 +56,14 +6,41 +67,70 +26,34 +4,69 +42,25 +53,16 +59,70 +2,20 +2,34 +17,32 +18,5 +12,38 +10,36 +58,31 +64,69 +39,64 +12,41 +8,56 +14,37 +56,36 +68,59 +28,4 +55,28 +59,10 +24,38 +46,60 +1,70 +68,4 +48,68 +5,28 +49,40 +42,24 +26,15 +64,48 +24,3 +70,32 +62,16 +50,66 +41,40 +52,2 +20,30 +50,9 +9,14 +20,32 +66,51 +46,56 +58,6 +30,12 +70,44 + +70,70,1024 diff --git a/2024/day18/test.txt b/2024/day18/test.txt new file mode 100755 index 0000000..05020a2 --- /dev/null +++ b/2024/day18/test.txt @@ -0,0 +1,27 @@ +5,4 +4,2 +4,5 +3,0 +2,1 +6,3 +2,4 +1,5 +0,6 +3,3 +2,6 +5,1 +1,2 +5,5 +2,5 +6,5 +1,4 +0,4 +6,4 +1,1 +6,1 +1,0 +0,5 +1,6 +2,0 + +6,6,12