diff --git a/day09.py b/day09.py new file mode 100644 index 0000000..7a9743e --- /dev/null +++ b/day09.py @@ -0,0 +1,85 @@ +from itertools import combinations +from tools.aoc import AOCDay +from tools.coordinate import Polygon, Coordinate, Line +from typing import Any + + + +class Day(AOCDay): + inputs = [ + [ + (50, "input9_test"), + (4745816424, "input9_dennis"), + (4737096935, "input9"), + ], + [ + (24, "input9_test"), + (1351617690, "input9_dennis"), + (1644094530, "input9"), + ] + ] + + def part1(self) -> Any: + tiles = [tuple(map(int, line.split(","))) for line in self.getInput()] + + ans = 0 + for pair in combinations(tiles, 2): + area = (abs(pair[0][0] - pair[1][0]) + 1) * (abs(pair[0][1] - pair[1][1]) + 1) + if area > ans: + ans = area + + return ans + + def part2(self) -> Any: + tiles: list[Coordinate] = [Coordinate(*map(int, line.split(","))) for line in self.getInput()] + p = Polygon(tiles) + + ans = 0 + decomposed = list(p.decompose()) + for pair in combinations(tiles, 2): + found_tile_inside = False + for x in tiles: + if min(pair[0][0], pair[1][0]) < x[0] < max(pair[0][0], pair[1][0]) and min(pair[0][1], pair[1][1]) < x[1] < max(pair[0][1], pair[1][1]): + #print("IGNORE", other_corner, last_tile, tile, "=>", x) + found_tile_inside = True + break + + if found_tile_inside: + continue + + + found_tile_outside = False + for c in [Coordinate(pair[0][0], pair[0][1]), Coordinate(pair[1][0], pair[1][1]), Coordinate(pair[0][0], pair[1][1]), Coordinate(pair[1][0], pair[0][1])]: + found_tile_inside = False + for r in decomposed: + if c in r: + found_tile_inside = True + + if not found_tile_inside: + found_tile_outside = True + if found_tile_outside: + continue + + + found_intersection = False + p_line = Line(pair[0], pair[1]) + for l in p.lines: + if l.start in pair or l.end in pair: + continue + if l.intersects(p_line): + found_intersection = True + break + + if found_intersection: + continue + + area = (abs(pair[0][0] - pair[1][0]) + 1) * (abs(pair[0][1] - pair[1][1]) + 1) + if area > ans: + ans = area + + return ans + + +if __name__ == '__main__': + day = Day(2025, 9) + day.run(verbose=True) diff --git a/inputs/input9 b/inputs/input9 new file mode 100644 index 0000000..8bfa406 --- /dev/null +++ b/inputs/input9 @@ -0,0 +1,496 @@ +97579,50266 +97579,51480 +97846,51480 +97846,52706 +98052,52706 +98052,53936 +98137,53936 +98137,55152 +97997,55152 +97997,56381 +97963,56381 +97963,57477 +97049,57477 +97049,58747 +97282,58747 +97282,59822 +96478,59822 +96478,61106 +96671,61106 +96671,62191 +96023,62191 +96023,63337 +95644,63337 +95644,64707 +95972,64707 +95972,65699 +95104,65699 +95104,66797 +94586,66797 +94586,68211 +94861,68211 +94861,69116 +93866,69116 +93866,70156 +93229,70156 +93229,71410 +93036,71410 +93036,72281 +92079,72281 +92079,73403 +91614,73403 +91614,74739 +91494,74739 +91494,75404 +90254,75404 +90254,76881 +90295,76881 +90295,77673 +89289,77673 +89289,78482 +88336,78482 +88336,79349 +87481,79349 +87481,80291 +86727,80291 +86727,81699 +86510,81699 +86510,82235 +85280,82235 +85280,83220 +84558,83220 +84558,84018 +83640,84018 +83640,84692 +82609,84692 +82609,86114 +82262,86114 +82262,86410 +80905,86410 +80905,87231 +80012,87231 +80012,88400 +79382,88400 +79382,88576 +77995,88576 +77995,89838 +77399,89838 +77399,90455 +76339,90455 +76339,91070 +75281,91070 +75281,91344 +74027,91344 +74027,91996 +73003,91996 +73003,92501 +71899,92501 +71899,93002 +70796,93002 +70796,93733 +69798,93733 +69798,94130 +68646,94130 +68646,94277 +67400,94277 +67400,94745 +66287,94745 +66287,95898 +65402,95898 +65402,96077 +64174,96077 +64174,96361 +62985,96361 +62985,96350 +61724,96350 +61724,96813 +60587,96813 +60587,97412 +59467,97412 +59467,97010 +58154,97010 +58154,97335 +56980,97335 +56980,97200 +55743,97200 +55743,98273 +54636,98273 +54636,97934 +53380,97934 +53380,98294 +52178,98294 +52178,97494 +50937,97494 +50937,97700 +49733,97700 +49733,97488 +48530,97488 +48530,97888 +47302,97888 +47302,98177 +46059,98177 +46059,97703 +44879,97703 +44879,97874 +43630,97874 +43630,97749 +42411,97749 +42411,97257 +41256,97257 +41256,97013 +40063,97013 +40063,96407 +38956,96407 +38956,96030 +37806,96030 +37806,95851 +36602,95851 +36602,96150 +35236,96150 +35236,94954 +34352,94954 +34352,95323 +32924,95323 +32924,94055 +32115,94055 +32115,94269 +30708,94269 +30708,93208 +29853,93208 +29853,92698 +28758,92698 +28758,92112 +27701,92112 +27701,92044 +26354,92044 +26354,91135 +25474,91135 +25474,90761 +24275,90761 +24275,90036 +23291,90036 +23291,89649 +22072,89649 +22072,88140 +21662,88140 +21662,87422 +20696,87422 +20696,86865 +19595,86865 +19595,86175 +18590,86175 +18590,85744 +17340,85744 +17340,84539 +16797,84539 +16797,83894 +15723,83894 +15723,82636 +15279,82636 +15279,81721 +14491,81721 +14491,81227 +13210,81227 +13210,80084 +12680,80084 +12680,78999 +12099,78999 +12099,77908 +11544,77908 +11544,77342 +10242,77342 +10242,76053 +9982,76053 +9982,75289 +8916,75289 +8916,74172 +8405,74172 +8405,72917 +8159,72917 +8159,72055 +7195,72055 +7195,70820 +6946,70820 +6946,69988 +5847,69988 +5847,68743 +5639,68743 +5639,67528 +5394,67528 +5394,66576 +4462,66576 +4462,65253 +4544,65253 +4544,64136 +4046,64136 +4046,62837 +4165,62837 +4165,61863 +3101,61863 +3101,60674 +2802,60674 +2802,59318 +3333,59318 +3333,58159 +2962,58159 +2962,56941 +2928,56941 +2928,55820 +2160,55820 +2160,54586 +2245,54586 +2245,53392 +1891,53392 +1891,52167 +1941,52167 +1941,50938 +2448,50938 +2448,50249 +94532,50249 +94532,48504 +1681,48504 +1681,47275 +1624,47275 +1624,46125 +2619,46125 +2619,44916 +2641,44916 +2641,43701 +2658,43701 +2658,42480 +2685,42480 +2685,41291 +2931,41291 +2931,39994 +2659,39994 +2659,38860 +3187,38860 +3187,37702 +3576,37702 +3576,36617 +4199,36617 +4199,35414 +4408,35414 +4408,34093 +4300,34093 +4300,33186 +5369,33186 +5369,31975 +5598,31975 +5598,30988 +6373,30988 +6373,29761 +6594,29761 +6594,28444 +6671,28444 +6671,27493 +7495,27493 +7495,26289 +7839,26289 +7839,25648 +9157,25648 +9157,24641 +9818,24641 +9818,23474 +10238,23474 +10238,22250 +10603,22250 +10603,21290 +11357,21290 +11357,20255 +12014,20255 +12014,19623 +13168,19623 +13168,18647 +13889,18647 +13889,17708 +14657,17708 +14657,16804 +15467,16804 +15467,15737 +16118,15737 +16118,14941 +17045,14941 +17045,14192 +18011,14192 +18011,13400 +18934,13400 +18934,12282 +19595,12282 +19595,11487 +20532,11487 +20532,11402 +21988,11402 +21988,10734 +22995,10734 +22995,9652 +23731,9652 +23731,9449 +25038,9449 +25038,8202 +25709,8202 +25709,7640 +26797,7640 +26797,7094 +27892,7094 +27892,7082 +29245,7082 +29245,6291 +30212,6291 +30212,5725 +31293,5725 +31293,5621 +32560,5621 +32560,4577 +33465,4577 +33465,4208 +34633,4208 +34633,3834 +35798,3834 +35798,3895 +37086,3895 +37086,3782 +38308,3782 +38308,3191 +39413,3191 +39413,3106 +40636,3106 +40636,2677 +41791,2677 +41791,2835 +43044,2835 +43044,2490 +44219,2490 +44219,1980 +45388,1980 +45388,1885 +46606,1885 +46606,1646 +47818,1646 +47818,2319 +49058,2319 +49058,1769 +50269,1769 +50269,1914 +51487,1914 +51487,1757 +52717,1757 +52717,1702 +53949,1702 +53949,2630 +55085,2630 +55085,2202 +56359,2202 +56359,2958 +57476,2958 +57476,2534 +58781,2534 +58781,3160 +59899,3160 +59899,2866 +61215,2866 +61215,3346 +62358,3346 +62358,4241 +63370,4241 +63370,4286 +64624,4286 +64624,5077 +65636,5077 +65636,5167 +66890,5167 +66890,5700 +67983,5700 +67983,5679 +69313,5679 +69313,6191 +70426,6191 +70426,6991 +71396,6991 +71396,7525 +72490,7525 +72490,8378 +73407,8378 +73407,8727 +74607,8727 +74607,9811 +75363,9811 +75363,9772 +76835,9772 +76835,10589 +77759,10589 +77759,11238 +78798,11238 +78798,12479 +79380,12479 +79380,13122 +80414,13122 +80414,13493 +81696,13493 +81696,14508 +82428,14508 +82428,15349 +83308,15349 +83308,16540 +83836,16540 +83836,16792 +85328,16792 +85328,17978 +85844,17978 +85844,19249 +86227,19249 +86227,19814 +87445,19814 +87445,20785 +88181,20785 +88181,21742 +88936,21742 +88936,22872 +89443,22872 +89443,23549 +90627,23549 +90627,24629 +91214,24629 +91214,25751 +91724,25751 +91724,27149 +91717,27149 +91717,28050 +92599,28050 +92599,29010 +93402,29010 +93402,30154 +93837,30154 +93837,31262 +94346,31262 +94346,32317 +94995,32317 +94995,33591 +95077,33591 +95077,34656 +95723,34656 +95723,35874 +95920,35874 +95920,37029 +96309,37029 +96309,38307 +96224,38307 +96224,39411 +96818,39411 +96818,40696 +96591,40696 +96591,41811 +97206,41811 +97206,42935 +97906,42935 +97906,44141 +98144,44141 +98144,45449 +97381,45449 +97381,46606 +98117,46606 +98117,47835 +97977,47835 +97977,49047 +98248,49047 +98248,50266 diff --git a/inputs/input9_dennis b/inputs/input9_dennis new file mode 100644 index 0000000..53648d5 --- /dev/null +++ b/inputs/input9_dennis @@ -0,0 +1,496 @@ +97498,50350 +97498,51566 +97867,51566 +97867,52766 +97596,52766 +97596,54006 +97931,54006 +97931,55187 +97518,55187 +97518,56443 +97775,56443 +97775,57590 +97213,57590 +97213,58740 +96775,58740 +96775,59963 +96730,59963 +96730,61160 +96532,61160 +96532,62325 +96194,62325 +96194,63579 +96166,63579 +96166,64747 +95816,64747 +95816,65738 +94956,65738 +94956,67084 +95104,67084 +95104,68213 +94636,68213 +94636,69347 +94180,69347 +94180,70566 +93903,70566 +93903,71538 +93101,71538 +93101,72410 +92141,72410 +92141,73522 +91652,73522 +91652,74426 +90802,74426 +90802,75931 +90925,75931 +90925,76888 +90149,76888 +90149,77721 +89208,77721 +89208,78796 +88613,78796 +88613,79505 +87542,79505 +87542,80795 +87203,80795 +87203,81587 +86249,81587 +86249,82183 +85097,82183 +85097,83627 +84856,83627 +84856,84032 +83532,84032 +83532,85000 +82781,85000 +82781,86124 +82155,86124 +82155,86868 +81180,86868 +81180,87385 +80026,87385 +80026,88111 +79052,88111 +79052,89185 +78331,89185 +78331,89404 +76996,89404 +76996,90513 +76273,90513 +76273,90778 +75000,90778 +75000,91335 +73923,91335 +73923,92144 +72986,92144 +72986,93037 +72077,93037 +72077,93454 +70918,93454 +70918,93837 +69751,93837 +69751,93869 +68443,93869 +68443,95153 +67650,95153 +67650,94770 +66205,94770 +66205,95477 +65170,95477 +65170,95992 +64057,95992 +64057,96695 +62988,96695 +62988,96706 +61725,96706 +61725,96512 +60431,96512 +60431,97116 +59320,97116 +59320,97218 +58103,97218 +58103,97945 +56982,97945 +56982,97922 +55743,97922 +55743,97873 +54511,97873 +54511,98133 +53308,98133 +53308,97855 +52072,97855 +52072,97610 +50854,97610 +50854,98150 +49644,98150 +49644,98064 +48426,98064 +48426,98149 +47201,98149 +47201,98244 +45967,98244 +45967,97506 +44814,97506 +44814,97672 +43570,97672 +43570,97093 +42429,97093 +42429,96987 +41219,96987 +41219,97272 +39920,97272 +39920,96805 +38773,96805 +38773,96712 +37536,96712 +37536,96394 +36353,96394 +36353,95313 +35414,95313 +35414,95271 +34151,95271 +34151,95006 +32952,95006 +32952,94585 +31807,94585 +31807,93846 +30799,93846 +30799,93745 +29507,93745 +29507,92722 +28650,92722 +28650,92795 +27241,92795 +27241,91741 +26426,91741 +26426,91584 +25105,91584 +25105,90135 +24570,90135 +24570,89768 +23367,89768 +23367,89548 +22037,89548 +22037,88608 +21208,88608 +21208,87649 +20410,87649 +20410,87008 +19365,87008 +19365,85965 +18659,85965 +18659,85572 +17380,85572 +17380,84461 +16753,84461 +16753,83571 +15928,83571 +15928,82940 +14830,82940 +14830,82203 +13821,82203 +13821,80876 +13491,80876 +13491,80002 +12645,80002 +12645,78910 +12075,78910 +12075,78273 +10894,78273 +10894,77284 +10175,77284 +10175,75994 +9916,75994 +9916,75057 +9129,75057 +9129,74085 +8384,74085 +8384,73189 +7483,73189 +7483,71754 +7592,71754 +7592,70817 +6755,70817 +6755,69770 +6120,69770 +6120,68731 +5444,68731 +5444,67415 +5449,67415 +5449,66413 +4655,66413 +4655,65238 +4318,65238 +4318,64163 +3660,64163 +3660,62750 +4160,62750 +4160,61604 +3774,61604 +3774,60546 +2975,60546 +2975,59343 +2767,59343 +2767,58034 +3180,58034 +3180,56884 +2727,56884 +2727,55733 +2167,55733 +2167,54518 +2047,54518 +2047,53271 +2393,53271 +2393,52073 +2128,52073 +2128,50859 +2103,50859 +2103,50332 +94987,50332 +94987,48421 +1783,48421 +1783,47221 +2197,47221 +2197,45964 +1726,45964 +1726,44750 +1910,44750 +1910,43635 +2809,43635 +2809,42413 +2806,42413 +2806,41104 +2394,41104 +2394,40088 +3513,40088 +3513,38804 +3322,38804 +3322,37636 +3663,37636 +3663,36401 +3768,36401 +3768,35351 +4492,35351 +4492,34213 +4906,34213 +4906,33043 +5233,33043 +5233,31770 +5324,31770 +5324,30920 +6430,30920 +6430,29664 +6590,29664 +6590,28395 +6766,28395 +6766,27649 +7971,27649 +7971,26291 +8019,26291 +8019,25590 +9226,25590 +9226,24170 +9233,24170 +9233,23382 +10254,23382 +10254,22024 +10432,22024 +10432,21143 +11304,21143 +11304,20557 +12538,20557 +12538,19224 +12820,19224 +12820,18558 +13918,18558 +13918,17321 +14363,17321 +14363,16912 +15703,16912 +15703,15884 +16384,15884 +16384,14953 +17175,14953 +17175,13961 +17920,13961 +17920,13166 +18848,13166 +18848,12937 +20232,12937 +20232,11530 +20674,11530 +20674,11148 +21909,11148 +21909,10486 +22929,10486 +22929,9812 +23938,9812 +23938,9318 +25058,9318 +25058,8498 +25980,8498 +25980,7909 +27043,7909 +27043,6973 +27927,6973 +27927,6483 +29051,6483 +29051,6446 +30376,6446 +30376,5678 +31366,5678 +31366,5562 +32629,5562 +32629,5018 +33717,5018 +33717,4011 +34659,4011 +34659,4346 +36045,4346 +36045,4059 +37221,4059 +37221,3281 +38271,3281 +38271,3100 +39481,3100 +39481,2674 +40638,2674 +40638,3168 +41962,3168 +41962,2129 +43028,2129 +43028,2448 +44300,2448 +44300,1877 +45465,1877 +45465,2011 +46701,2011 +46701,2358 +47936,2358 +47936,1786 +49134,1786 +49134,1872 +50355,1872 +50355,2164 +51565,2164 +51565,2005 +52789,2005 +52789,2376 +53980,2376 +53980,2525 +55182,2525 +55182,2696 +56379,2696 +56379,2410 +57650,2410 +57650,2919 +58797,2919 +58797,3411 +59933,3411 +59933,2910 +61294,2910 +61294,3912 +62296,3912 +62296,4389 +63416,4389 +63416,3917 +64833,3917 +64833,4674 +65867,4674 +65867,5492 +66858,5492 +66858,5141 +68304,5141 +68304,6252 +69157,6252 +69157,6291 +70474,6291 +70474,7304 +71335,7304 +71335,7519 +72591,7519 +72591,8464 +73457,8464 +73457,8940 +74580,8940 +74580,9586 +75606,9586 +75606,10247 +76622,10247 +76622,10724 +77769,10724 +77769,11508 +78705,11508 +78705,12189 +79716,12189 +79716,12907 +80703,12907 +80703,13607 +81711,13607 +81711,14273 +82760,14273 +82760,15159 +83612,15159 +83612,16074 +84430,16074 +84430,17068 +85160,17068 +85160,17882 +86081,17882 +86081,19054 +86591,19054 +86591,19828 +87565,19828 +87565,20678 +88463,20678 +88463,22125 +88554,22125 +88554,22930 +89510,22930 +89510,24078 +89971,24078 +89971,25154 +90525,25154 +90525,26127 +91246,26127 +91246,27052 +92072,27052 +92072,27955 +92972,27955 +92972,28997 +93627,28997 +93627,30158 +94037,30158 +94037,31293 +94496,31293 +94496,32429 +94947,32429 +94947,33493 +95601,33493 +95601,34724 +95792,34724 +95792,35890 +96162,35890 +96162,37228 +95912,37228 +95912,38335 +96462,38335 +96462,39507 +96780,39507 +96780,40595 +97543,40595 +97543,41916 +97104,41916 +97104,43143 +97075,43143 +97075,44241 +98041,44241 +98041,45525 +97482,45525 +97482,46742 +97402,46742 +97402,47937 +97630,47937 +97630,49138 +97978,49138 +97978,50350 \ No newline at end of file diff --git a/inputs/input9_test b/inputs/input9_test new file mode 100644 index 0000000..7fb70de --- /dev/null +++ b/inputs/input9_test @@ -0,0 +1,8 @@ +7,1 +11,1 +11,7 +9,7 +9,5 +2,5 +2,3 +7,3 \ No newline at end of file