diff --git a/2025/day09/input b/2025/day09/input new file mode 100644 index 0000000..ea7a2f6 --- /dev/null +++ b/2025/day09/input @@ -0,0 +1,496 @@ +97975,50252 +97975,51453 +97479,51453 +97479,52662 +97539,52662 +97539,53901 +97902,53901 +97902,55126 +97907,55126 +97907,56376 +98042,56376 +98042,57475 +97138,57475 +97138,58798 +97645,58798 +97645,59877 +96811,59877 +96811,61156 +96953,61156 +96953,62151 +95934,62151 +95934,63481 +96194,63481 +96194,64558 +95558,64558 +95558,65632 +94958,65632 +94958,67049 +95301,67049 +95301,67863 +94045,67863 +94045,69238 +94186,69238 +94186,70063 +93066,70063 +93066,71249 +92749,71249 +92749,72575 +92669,72575 +92669,73439 +91709,73439 +91709,74808 +91639,74808 +91639,75785 +90887,75785 +90887,76610 +89917,76610 +89917,77468 +89024,77468 +89024,78462 +88335,78462 +88335,79839 +88132,79839 +88132,80218 +86664,80218 +86664,81153 +85904,81153 +85904,82413 +85498,82413 +85498,83317 +84682,83317 +84682,83990 +83634,83990 +83634,84884 +82812,84884 +82812,85907 +82098,85907 +82098,86499 +81001,86499 +81001,87113 +79938,87113 +79938,88054 +79136,88054 +79136,88830 +78199,88830 +78199,89918 +77473,89918 +77473,90237 +76216,90237 +76216,90863 +75172,90863 +75172,91514 +74144,91514 +74144,91724 +72872,91724 +72872,92467 +71899,92467 +71899,93244 +70930,93244 +70930,93375 +69653,93375 +69653,94504 +68821,94504 +68821,94830 +67634,94830 +67634,95408 +66545,95408 +66545,95277 +65210,95277 +65210,95980 +64160,95980 +64160,96603 +63069,96603 +63069,96514 +61782,96514 +61782,97296 +60713,97296 +60713,97306 +59462,97306 +59462,97639 +58279,97639 +58279,97915 +57082,97915 +57082,97198 +55758,97198 +55758,98216 +54646,98216 +54646,97474 +53363,97474 +53363,97470 +52156,97470 +52156,98184 +50967,98184 +50967,97836 +49748,97836 +49748,98311 +48521,98311 +48521,98044 +47309,98044 +47309,97631 +46120,97631 +46120,97560 +44910,97560 +44910,98013 +43627,98013 +43627,97613 +42448,97613 +42448,97341 +41257,97341 +41257,96770 +40131,96770 +40131,96290 +39000,96290 +39000,96362 +37734,96362 +37734,96365 +36468,96365 +36468,96168 +35246,96168 +35246,95017 +34347,95017 +34347,94960 +33078,94960 +33078,94141 +32097,94141 +32097,94398 +30669,94398 +30669,93912 +29542,93912 +29542,93272 +28490,93272 +28490,92285 +27627,92285 +27627,92198 +26286,92198 +26286,90904 +25629,90904 +25629,90972 +24161,90972 +24161,89590 +23607,89590 +23607,89460 +22225,89460 +22225,88680 +21281,88680 +21281,87418 +20719,87418 +20719,87308 +19250,87308 +19250,86140 +18642,86140 +18642,85119 +17933,85119 +17933,84676 +16688,84676 +16688,83628 +16014,83628 +16014,82584 +15357,82584 +15357,81967 +14239,81967 +14239,81352 +13086,81352 +13086,80449 +12252,80449 +12252,78919 +12230,78919 +12230,78293 +11040,78293 +11040,77383 +10211,77383 +10211,76320 +9601,76320 +9601,75283 +8956,75283 +8956,74307 +8205,74307 +8205,73286 +7520,73286 +7520,72048 +7243,72048 +7243,70756 +7114,70756 +7114,69608 +6724,69608 +6724,68707 +5765,68707 +5765,67462 +5605,67462 +5605,66301 +5261,66301 +5261,65196 +4763,65196 +4763,64245 +3744,64245 +3744,62832 +4241,62832 +4241,61686 +3864,61686 +3864,60560 +3375,60560 +3375,59461 +2695,59461 +2695,58165 +3014,58165 +3014,57080 +2096,57080 +2096,55764 +2757,55764 +2757,54562 +2657,54562 +2657,53421 +1718,53421 +1718,52198 +1610,52198 +1610,50958 +2235,50958 +2235,50236 +94851,50236 +94851,48543 +2411,48543 +2411,47289 +1596,47289 +1596,46090 +2006,46090 +2006,44880 +2161,44880 +2161,43661 +2238,43661 +2238,42492 +2662,42492 +2662,41205 +2380,41205 +2380,40173 +3427,40173 +3427,38915 +3350,38915 +3350,37726 +3605,37726 +3605,36417 +3458,36417 +3458,35493 +4603,35493 +4603,34366 +5037,34366 +5037,32938 +4667,32938 +4667,31795 +5114,31795 +5114,30668 +5600,30668 +5600,29844 +6734,29844 +6734,28729 +7207,28729 +7207,27456 +7392,27456 +7392,26408 +8019,26408 +8019,25188 +8354,25188 +8354,24485 +9541,24485 +9541,23546 +10318,23546 +10318,22529 +10972,22529 +10972,21425 +11513,21425 +11513,20700 +12557,20700 +12557,19461 +12947,19461 +12947,18679 +13902,18679 +13902,17868 +14809,17868 +14809,16883 +15527,16883 +15527,15849 +16207,15849 +16207,15014 +17093,15014 +17093,14095 +17903,14095 +17903,13455 +18960,13455 +18960,12395 +19665,12395 +19665,12096 +20978,12096 +20978,11398 +21965,11398 +21965,10257 +22647,10257 +22647,9721 +23757,9721 +23757,8872 +24664,8872 +24664,8596 +25919,8596 +25919,7824 +26880,7824 +26880,7671 +28172,7671 +28172,7103 +29237,7103 +29237,5921 +30027,5921 +30027,6089 +31429,6089 +31429,5521 +32504,5521 +32504,4554 +33440,4554 +33440,4529 +34724,4529 +34724,3811 +35774,3811 +35774,3455 +36946,3455 +36946,3188 +38142,3188 +38142,2905 +39332,2905 +39332,3075 +40614,3075 +40614,3113 +41851,3113 +41851,2445 +42971,2445 +42971,2120 +44158,2120 +44158,2569 +45429,2569 +45429,1852 +46588,1852 +46588,1943 +47816,1943 +47816,2254 +49041,2254 +49041,1803 +50253,1803 +50253,2228 +51462,2228 +51462,1909 +52692,1909 +52692,2119 +53900,2119 +53900,1826 +55155,1826 +55155,2730 +56273,2730 +56273,2449 +57540,2449 +57540,2339 +58801,2339 +58801,2901 +59937,2901 +59937,3035 +61159,3035 +61159,3459 +62312,3459 +62312,3791 +63485,3791 +63485,4174 +64643,4174 +64643,4536 +65807,4536 +65807,5066 +66911,5066 +66911,5915 +67879,5915 +67879,5928 +69188,5928 +69188,6764 +70141,6764 +70141,7203 +71273,7203 +71273,7294 +72594,7294 +72594,7751 +73741,7751 +73741,8749 +74576,8749 +74576,9047 +75826,9047 +75826,10217 +76520,10217 +76520,10745 +77629,10745 +77629,11725 +78417,11725 +78417,12212 +79569,12212 +79569,12742 +80707,12742 +80707,13918 +81306,13918 +81306,14507 +82407,14507 +82407,15516 +83127,15516 +83127,16462 +83892,16462 +83892,16920 +85168,16920 +85168,18095 +85689,18095 +85689,18999 +86499,18999 +86499,19958 +87241,19958 +87241,20793 +88145,20793 +88145,21697 +88970,21697 +88970,22535 +89906,22535 +89906,23729 +90321,23729 +90321,24836 +90848,24836 +90848,25720 +91745,25720 +91745,26940 +92065,26940 +92065,28028 +92606,28028 +92606,29038 +93307,29038 +93307,30315 +93443,30315 +93443,31116 +94650,31116 +94650,32401 +94739,32401 +94739,33654 +94859,33654 +94859,34617 +95791,34617 +95791,35849 +95946,35849 +95946,36924 +96624,36924 +96624,38269 +96308,38269 +96308,39322 +97138,39322 +97138,40541 +97288,40541 +97288,41855 +96860,41855 +96860,42997 +97372,42997 +97372,44221 +97358,44221 +97358,45361 +98131,45361 +98131,46582 +98238,46582 +98238,47836 +97623,47836 +97623,49040 +97819,49040 +97819,50252 diff --git a/2025/day09/main.go b/2025/day09/main.go new file mode 100644 index 0000000..45b97db --- /dev/null +++ b/2025/day09/main.go @@ -0,0 +1,109 @@ +package main + +import ( + "fmt" + "sort" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + fmt.Println() + part2(inp) +} + +func part1(inp []string) { + c := parse(inp) + var largest int + for i := range c { + for j := range c[i:] { + a := c[i].AreaTo(c[j]) + if a > largest { + largest = a + } + } + } + fmt.Println("# Part 1") + fmt.Println(largest) +} + +func part2(inp []string) { + c := parse(inp) + var areas []Area + for i := range c { + for j := i + 1; j < len(c); j++ { + areas = append(areas, Area{p1: c[i], p2: c[j], area: c[i].AreaTo(c[j])}) + } + } + sort.Slice(areas, func(a, b int) bool { return areas[a].area > areas[b].area }) + + var edges []h.Coordinate + for i := range c { + var t, n h.Coordinate + t = c[i] + if i < len(c)-1 { + n = c[i+1] + } else if i == len(c)-1 { + n = c[0] + } + edges = append(edges, getEdges(t, n)...) + } + + var j int + h.PrintProgress(j, len(areas)) + for j = 0; j < len(areas); j++ { + h.ClearProgress() + h.PrintProgress(j, len(areas)) + var nope bool + for _, e := range edges { + if pointIn(e, areas[j]) { + nope = true + break + } + } + if nope { + continue + } + break + } + fmt.Println("# Part 2") + fmt.Println(areas[j].area) +} + +func getEdges(c1, c2 h.Coordinate) []h.Coordinate { + var ret []h.Coordinate + if c1.X == c2.X { + for y := h.Min(c1.Y, c2.Y); y <= h.Max(c1.Y, c2.Y); y++ { + ret = append(ret, h.Coordinate{X: c1.X, Y: y}) + } + return ret + } + for x := h.Min(c1.X, c2.X); x <= h.Max(c1.X, c2.X); x++ { + ret = append(ret, h.Coordinate{X: x, Y: c1.Y}) + } + return ret +} + +func parse(inp []string) []h.Coordinate { + var allCoords []h.Coordinate + for i := range inp { + c := h.Coordinate{} + fmt.Sscanf(inp[i], "%d,%d", &c.X, &c.Y) + allCoords = append(allCoords, c) + } + return allCoords +} + +type Area struct { + p1, p2 h.Coordinate + area int +} + +// pointIn returns true if 't' is within the rectangle made +// by Area +func pointIn(t h.Coordinate, a Area) bool { + return t.X < h.Max(a.p1.X, a.p2.X) && t.X > h.Min(a.p1.X, a.p2.X) && + t.Y < h.Max(a.p1.Y, a.p2.Y) && t.Y > h.Min(a.p1.Y, a.p2.Y) +} diff --git a/2025/day09/problem b/2025/day09/problem new file mode 100644 index 0000000..546895a --- /dev/null +++ b/2025/day09/problem @@ -0,0 +1,145 @@ + [1]Advent of Code + + • [2][About] + • [3][Events] + • [4][Shop] + • [5][Settings] + • [6][Log Out] + + br0xen [7](AoC++) 16* + +    0x0000|[8]2025 + + • [9][Calendar] + • [10][AoC++] + • [11][Sponsors] + • [12][Leaderboards] + • [13][Stats] + + Our [14]sponsors help make Advent of Code possible: + [15]TNG Technology Consulting - We solve hard IT problems – all year + round! + +--- Day 9: Movie Theater --- + + You slide down the [16]firepole in the corner of the playground and land + in the North Pole base movie theater! + + The movie theater has a big tile floor with an interesting pattern. Elves + here are redecorating the theater by switching out some of the square + tiles in the big grid they form. Some of the tiles are red; the Elves + would like to find the largest rectangle that uses red tiles for two of + its opposite corners. They even have a list of where the red tiles are + located in the grid (your puzzle input). + + For example: + + 7,1 + 11,1 + 11,7 + 9,7 + 9,5 + 2,5 + 2,3 + 7,3 + + Showing red tiles as # and other tiles as ., the above arrangement of red + tiles would look like this: + + .............. + .......#...#.. + .............. + ..#....#...... + .............. + ..#......#.... + .............. + .........#.#.. + .............. + + You can choose any two red tiles as the opposite corners of your + rectangle; your goal is to find the largest rectangle possible. + + For example, you could make a rectangle (shown as O) with an area of 24 + between 2,5 and 9,7: + + .............. + .......#...#.. + .............. + ..#....#...... + .............. + ..OOOOOOOO.... + ..OOOOOOOO.... + ..OOOOOOOO.#.. + .............. + + Or, you could make a rectangle with area 35 between 7,1 and 11,7: + + .............. + .......OOOOO.. + .......OOOOO.. + ..#....OOOOO.. + .......OOOOO.. + ..#....OOOOO.. + .......OOOOO.. + .......OOOOO.. + .............. + + You could even make a thin rectangle with an area of only 6 between 7,3 + and 2,3: + + .............. + .......#...#.. + .............. + ..OOOOOO...... + .............. + ..#......#.... + .............. + .........#.#.. + .............. + + Ultimately, the largest rectangle you can make in this example has area + 50. One way to do this is between 2,5 and 11,1: + + .............. + ..OOOOOOOOOO.. + ..OOOOOOOOOO.. + ..OOOOOOOOOO.. + ..OOOOOOOOOO.. + ..OOOOOOOOOO.. + .............. + .........#.#.. + .............. + + Using two red tiles as opposite corners, what is the largest area of any + rectangle you can make? + + To begin, [17]get your puzzle input. + + Answer: [18]_____________________ [19][ [Submit] ] + + You can also [Shareon [20]Bluesky [21]Twitter [22]Mastodon] this puzzle. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2025/about + 3. https://adventofcode.com/2025/events + 4. https://adventofcode.com/2025/shop + 5. https://adventofcode.com/2025/settings + 6. https://adventofcode.com/2025/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2025/support + 8. https://adventofcode.com/2025 + 9. https://adventofcode.com/2025 + 10. https://adventofcode.com/2025/support + 11. https://adventofcode.com/2025/sponsors + 12. https://adventofcode.com/2025/leaderboard/private + 13. https://adventofcode.com/2025/stats + 14. https://adventofcode.com/2025/sponsors + 15. https://adventofcode.com/2025/sponsors/redirect?url=https%3A%2F%2Fwww%2Etngtech%2Ecom%2Fen%2F + 16. https://en.wikipedia.org/wiki/Fireman%27s_pole + 17. https://adventofcode.com/2025/day/9/input + 20. https://bsky.app/intent/compose?text=%22Movie+Theater%22+%2D+Day+9+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F9 + 21. https://twitter.com/intent/tweet?text=%22Movie+Theater%22+%2D+Day+9+%2D+Advent+of+Code+2025&url=https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode + 22. javascript:void(0); diff --git a/2025/day09/testinput b/2025/day09/testinput new file mode 100644 index 0000000..c8563ea --- /dev/null +++ b/2025/day09/testinput @@ -0,0 +1,8 @@ +7,1 +11,1 +11,7 +9,7 +9,5 +2,5 +2,3 +7,3 diff --git a/helpers/coordinate.go b/helpers/coordinate.go index 36adac1..cdfd4d4 100644 --- a/helpers/coordinate.go +++ b/helpers/coordinate.go @@ -42,6 +42,18 @@ func (c *Coordinate) MoveNW() { c.Y-- } +func (c Coordinate) AreaTo(o Coordinate) int { + x1, x2 := c.X, o.X + y1, y2 := c.Y, o.Y + if x1 < x2 { + x1, x2 = x2, x1 + } + if y1 < y2 { + y1, y2 = y2, y1 + } + return ((x1 - x2) + 1) * ((y1 - y2) + 1) +} + func (c Coordinate) Sub(o Coordinate) Coordinate { return Coordinate{ X: c.X - o.X, diff --git a/helpers/helpers.go b/helpers/helpers.go index 03869df..4eb052c 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -404,6 +404,20 @@ func SliceMin(sl []int) int { } } +func SetDec(v1, v2 int) (int, int) { + if v1 < v2 { + return v2, v1 + } + return v1, v2 +} + +func SetInc(v1, v2 int) (int, int) { + if v1 > v2 { + return v2, v1 + } + return v1, v2 +} + func Min(v1, v2 int, vrest ...int) int { min := v2 if v1 < v2 { diff --git a/mkday.sh b/mkday.sh index f960324..b84e064 100755 --- a/mkday.sh +++ b/mkday.sh @@ -1,5 +1,11 @@ #!/bin/bash +if [ -z $1 ]; then + cp -R dayTemplate $(aoc today) + cd $(aoc today) + exit 0 +fi + YR=$1 DY=$2