diff --git a/bob/day09/day09-p1.py b/bob/day09/day09-p1.py new file mode 100644 index 0000000..e8c8fa0 --- /dev/null +++ b/bob/day09/day09-p1.py @@ -0,0 +1,45 @@ +import itertools + +def get_area(a,b): + min_x = min(a[0],b[0]) + max_x = max(a[0],b[0]) + + min_y = min(a[1],b[1]) + max_y = max(a[1],b[1]) + + x = max_x - min_x + 1 + y = max_y - min_y + 1 + + return x * y + +def read_input(filename): + space = [] + for line in open(filename).read().splitlines(): + x,y = line.split(",") + space.append((int(x), int(y))) + return space + + +# filename = "day09/example_input" # 50 +filename = "day09/input" # 4761736832 + +tiles = read_input(filename) + +# build list of (unique) combinations +tiles_comb = itertools.combinations(tiles,2) + +print("Calculate distances") +# Add distance to the list +tiles_area = [] +for a,b in tiles_comb: + area = get_area(a,b) + tiles_area.append((a,b,area)) + +# def jd_sort(junc_dist): +# return junc_dist[2] +# tiles_area.sort(key=jd_sort) +tiles_area.sort(key=lambda x: x[2]) + + + +print(f"Largest area: {tiles_area[-1][2]}") diff --git a/bob/day09/example_input b/bob/day09/example_input new file mode 100644 index 0000000..c8563ea --- /dev/null +++ b/bob/day09/example_input @@ -0,0 +1,8 @@ +7,1 +11,1 +11,7 +9,7 +9,5 +2,5 +2,3 +7,3 diff --git a/bob/day09/input b/bob/day09/input new file mode 100644 index 0000000..3bd69d9 --- /dev/null +++ b/bob/day09/input @@ -0,0 +1,496 @@ +97739,50344 +97739,51571 +98274,51571 +98274,52752 +97501,52752 +97501,53963 +97513,53963 +97513,55170 +97443,55170 +97443,56360 +97220,56360 +97220,57634 +97539,57634 +97539,58834 +97323,58834 +97323,59898 +96465,59898 +96465,61263 +96996,61263 +96996,62339 +96281,62339 +96281,63628 +96363,63628 +96363,64617 +95438,64617 +95438,65842 +95279,65842 +95279,66911 +94671,66911 +94671,68092 +94363,68092 +94363,69401 +94326,69401 +94326,70239 +93226,70239 +93226,71263 +92569,71263 +92569,72679 +92664,72679 +92664,73377 +91411,73377 +91411,74680 +91242,74680 +91242,75835 +90790,75835 +90790,76580 +89705,76580 +89705,77988 +89600,77988 +89600,78962 +88850,78962 +88850,79537 +87596,79537 +87596,80848 +87280,80848 +87280,81800 +86507,81800 +86507,82573 +85535,82573 +85535,83185 +84410,83185 +84410,84055 +83567,84055 +83567,85119 +82904,85119 +82904,85753 +81836,85753 +81836,86856 +81181,86856 +81181,87287 +79958,87287 +79958,88114 +79065,88114 +79065,89189 +78344,89189 +78344,89828 +77297,89828 +77297,89851 +75854,89851 +75854,90641 +74927,90641 +74927,91493 +74024,91493 +74024,91708 +72758,91708 +72758,92639 +71883,92639 +71883,93141 +70777,93141 +70777,94086 +69872,94086 +69872,94642 +68777,94642 +68777,94418 +67372,94418 +67372,95046 +66314,95046 +66314,95926 +65329,95926 +65329,95544 +63929,95544 +63929,96034 +62813,96034 +62813,96559 +61697,96559 +61697,97195 +60593,97195 +60593,96671 +59241,96671 +59241,97319 +58129,97319 +58129,97045 +56860,97045 +56860,97350 +55683,97350 +55683,98172 +54547,98172 +54547,97713 +53287,97713 +53287,97525 +52066,97525 +52066,98306 +50875,98306 +50875,97591 +49656,97591 +49656,97755 +48445,97755 +48445,97799 +47230,97799 +47230,97741 +46017,97741 +46017,98053 +44763,98053 +44763,97805 +43560,97805 +43560,97114 +42434,97114 +42434,97505 +41131,97505 +41131,96661 +40059,96661 +40059,96718 +38803,96718 +38803,96537 +37591,96537 +37591,95988 +36481,95988 +36481,95537 +35351,95537 +35351,95062 +34233,95062 +34233,94502 +33152,94502 +33152,94197 +31974,94197 +31974,94035 +30725,94035 +30725,93480 +29640,93480 +29640,92675 +28683,92675 +28683,92350 +27487,92350 +27487,91503 +26570,91503 +26570,91119 +25393,91119 +25393,90582 +24296,90582 +24296,89877 +23304,89877 +23304,88930 +22484,88930 +22484,88155 +21556,88155 +21556,88024 +20126,88024 +20126,87039 +19351,87039 +19351,86353 +18333,86353 +18333,85504 +17454,85504 +17454,84880 +16361,84880 +16361,83998 +15508,83998 +15508,83082 +14690,83082 +14690,82035 +14023,82035 +14023,80880 +13499,80880 +13499,80294 +12294,80294 +12294,79160 +11761,79160 +11761,78152 +11076,78152 +11076,77346 +10099,77346 +10099,76187 +9634,76187 +9634,74892 +9415,74892 +9415,74076 +8416,74076 +8416,73130 +7608,73130 +7608,71996 +7139,71996 +7139,70930 +6539,70930 +6539,69915 +5818,69915 +5818,68567 +5858,68567 +5858,67380 +5561,67380 +5561,66437 +4615,66437 +4615,65258 +4284,65258 +4284,63945 +4402,63945 +4402,62746 +4207,62746 +4207,61637 +3678,61637 +3678,60447 +3458,60447 +3458,59293 +3064,59293 +3064,58162 +2488,58162 +2488,56891 +2737,56891 +2737,55722 +2329,55722 +2329,54493 +2400,54493 +2400,53318 +1844,53318 +1844,52080 +2154,52080 +2154,50860 +2506,50860 +2506,50322 +94737,50322 +94737,48449 +2390,48449 +2390,47223 +2086,47223 +2086,46043 +2569,46043 +2569,44800 +2293,44800 +2293,43643 +2809,43643 +2809,42358 +2411,42358 +2411,41109 +2379,41109 +2379,39899 +2588,39899 +2588,38856 +3504,38856 +3504,37681 +3799,37681 +3799,36456 +3926,36456 +3926,35358 +4486,35358 +4486,34172 +4764,34172 +4764,33109 +5384,33109 +5384,31731 +5205,31731 +5205,30944 +6463,30944 +6463,29488 +6194,29488 +6194,28754 +7465,28754 +7465,27704 +8056,27704 +8056,26447 +8278,26447 +8278,25532 +9113,25532 +9113,24513 +9760,24513 +9760,23176 +9932,23176 +9932,22111 +10541,22111 +10541,21320 +11528,21320 +11528,20269 +12157,20269 +12157,19445 +13074,19445 +13074,18598 +13950,18598 +13950,17240 +14261,17240 +14261,16897 +15675,16897 +15675,15943 +16430,15943 +16430,15249 +17440,15249 +17440,13843 +17804,13843 +17804,13266 +18922,13266 +18922,12637 +19980,12637 +19980,11951 +20984,11951 +20984,11277 +21993,11277 +21993,10718 +23077,10718 +23077,9679 +23841,9679 +23841,9217 +24986,9217 +24986,8853 +26176,8853 +26176,7764 +26954,7764 +26954,7166 +28017,7166 +28017,7178 +29376,7178 +29376,5810 +30080,5810 +30080,5959 +31475,5959 +31475,5251 +32498,5251 +32498,4480 +33513,4480 +33513,4576 +34838,4576 +34838,4264 +36011,4264 +36011,3679 +37106,3679 +37106,3299 +38266,3299 +38266,2892 +39425,2892 +39425,2827 +40659,2827 +40659,2940 +41915,2940 +41915,2349 +43051,2349 +43051,2778 +44331,2778 +44331,2194 +45486,2194 +45486,2119 +46700,2119 +46700,2243 +47923,2243 +47923,2326 +49135,2326 +49135,1876 +50346,1876 +50346,2441 +51548,2441 +51548,2483 +52753,2483 +52753,1889 +54012,1889 +54012,2305 +55197,2305 +55197,2876 +56347,2876 +56347,2850 +57571,2850 +57571,3252 +58727,3252 +58727,2720 +60072,2720 +60072,3119 +61235,3119 +61235,4100 +62237,4100 +62237,3882 +63556,3882 +63556,4174 +64741,4174 +64741,4241 +66010,4241 +66010,4837 +67097,4837 +67097,5760 +68042,5760 +68042,5887 +69307,5887 +69307,6281 +70470,6281 +70470,6711 +71622,6711 +71622,7675 +72498,7675 +72498,8378 +73495,8378 +73495,8584 +74783,8584 +74783,9182 +75852,9182 +75852,10124 +76694,10124 +76694,10824 +77688,10824 +77688,11291 +78856,11291 +78856,11876 +79952,11876 +79952,13002 +80614,13002 +80614,14121 +81252,14121 +81252,14643 +82409,14643 +82409,15229 +83532,15229 +83532,16534 +83951,16534 +83951,17485 +84702,17485 +84702,18282 +85619,18282 +85619,18732 +86957,18732 +86957,19710 +87698,19710 +87698,21161 +87817,21161 +87817,22075 +88609,22075 +88609,22913 +89521,22913 +89521,23857 +90295,23857 +90295,24755 +91159,24755 +91159,25741 +91897,25741 +91897,27075 +92013,27075 +92013,28248 +92383,28248 +92383,29045 +93508,29045 +93508,30450 +93370,30450 +93370,31400 +94218,31400 +94218,32543 +94631,32543 +94631,33600 +95279,33600 +95279,34703 +95827,34703 +95827,36066 +95555,36066 +95555,37101 +96338,37101 +96338,38245 +96785,38245 +96785,39467 +96923,39467 +96923,40731 +96811,40731 +96811,41934 +96944,41934 +96944,43040 +97726,43040 +97726,44278 +97667,44278 +97667,45509 +97562,45509 +97562,46697 +97935,46697 +97935,47906 +98133,47906 +98133,49137 +97585,49137 +97585,50344