diff --git a/2024/01/code.py b/2024/01/code.py new file mode 100644 index 0000000..f3e740b --- /dev/null +++ b/2024/01/code.py @@ -0,0 +1,21 @@ +import numpy as np +from pathlib import Path + +filepath = Path("./data/1_example") +filepath = Path("./data/1_input") + +with open(filepath, 'r') as filein: + data = np.transpose([[int(i) for i in l.split()] for l in filein.readlines()]) +data.sort() +data_diff = np.abs(np.diff(data,axis=0).flatten()) +data_sum = data_diff.sum() +print(data_sum) + + +def score_similarity(a: np.ndarray, b: np.ndarray): + left = a# p.unique(a) + right = np.array([np.sum(np.where(b==i, 1, 0)) for i in left]) + return np.sum(left*right) + + +print(score_similarity(*data)) diff --git a/2024/01/example b/2024/01/example new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/2024/01/example @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/2024/01/info.txt b/2024/01/info.txt new file mode 100644 index 0000000..6fb3206 --- /dev/null +++ b/2024/01/info.txt @@ -0,0 +1,74 @@ +--- Day 1: Historian Hysteria --- + +The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit. + +As each location is checked, they will mark it on their list with a star. They figure the Chief Historian must be in one of the first fifty places they'll look, so in order to save Christmas, you need to help them get fifty stars on their list before Santa takes off on December 25th. + +Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! + +You haven't even left yet and the group of Elvish Senior Historians has already hit a problem: their list of locations to check is currently empty. Eventually, someone decides that the best place to check first would be the Chief Historian's office. + +Upon pouring into the office, everyone confirms that the Chief Historian is indeed nowhere to be found. Instead, the Elves discover an assortment of notes and lists of historically significant locations! This seems to be the planning the Chief Historian was doing before he left. Perhaps these notes can be used to determine which locations to search? + +Throughout the Chief's office, the historically significant locations are listed not by name but by a unique number called the location ID. To make sure they don't miss anything, The Historians split into two groups, each searching the office and trying to create their own complete list of location IDs. + +There's just one problem: by holding the two lists up side by side (your puzzle input), it quickly becomes clear that the lists aren't very similar. Maybe you can help The Historians reconcile their lists? + +For example: + +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 + +Maybe the lists are only off by a small amount! To find out, pair up the numbers and measure how far apart they are. Pair up the smallest number in the left list with the smallest number in the right list, then the second-smallest left number with the second-smallest right number, and so on. + +Within each pair, figure out how far apart the two numbers are; you'll need to add up all of those distances. For example, if you pair up a 3 from the left list with a 7 from the right list, the distance apart is 4; if you pair up a 9 with a 3, the distance apart is 6. + +In the example list above, the pairs and distances would be as follows: + + The smallest number in the left list is 1, and the smallest number in the right list is 3. The distance between them is 2. + The second-smallest number in the left list is 2, and the second-smallest number in the right list is another 3. The distance between them is 1. + The third-smallest number in both lists is 3, so the distance between them is 0. + The next numbers to pair up are 3 and 4, a distance of 1. + The fifth-smallest numbers in each list are 3 and 5, a distance of 2. + Finally, the largest number in the left list is 4, while the largest number in the right list is 9; these are a distance 5 apart. + +To find the total distance between the left list and the right list, add up the distances between all of the pairs you found. In the example above, this is 2 + 1 + 0 + 1 + 2 + 5, a total distance of 11! + +Your actual left and right lists contain many location IDs. What is the total distance between your lists? + + +--- Part Two --- + +Your analysis only confirmed what everyone feared: the two lists of location IDs are indeed very different. + +Or are they? + +The Historians can't agree on which group made the mistakes or how to read most of the Chief's handwriting, but in the commotion you notice an interesting detail: a lot of location IDs appear in both lists! Maybe the other numbers aren't location IDs at all but rather misinterpreted handwriting. + +This time, you'll need to figure out exactly how often each number from the left list appears in the right list. Calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list. + +Here are the same example lists again: + +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 + +For these example lists, here is the process of finding the similarity score: + + The first number in the left list is 3. It appears in the right list three times, so the similarity score increases by 3 * 3 = 9. + The second number in the left list is 4. It appears in the right list once, so the similarity score increases by 4 * 1 = 4. + The third number in the left list is 2. It does not appear in the right list, so the similarity score does not increase (2 * 0 = 0). + The fourth number, 1, also does not appear in the right list. + The fifth number, 3, appears in the right list three times; the similarity score increases by 9. + The last number, 3, appears in the right list three times; the similarity score again increases by 9. + +So, for these example lists, the similarity score at the end of this process is 31 (9 + 4 + 0 + 0 + 9 + 9). + +Once again consider your left and right lists. What is their similarity score? diff --git a/2024/01/input b/2024/01/input new file mode 100644 index 0000000..2576b42 --- /dev/null +++ b/2024/01/input @@ -0,0 +1,1000 @@ +61967 56543 +11022 54992 +21268 29417 +90452 95846 +90728 95846 +82351 12878 +40277 58932 +36981 22944 +93875 53190 +39283 59850 +39396 34776 +16395 35328 +32473 10395 +15028 20276 +31930 65432 +24773 22172 +40802 97123 +10909 29189 +23996 60290 +55260 93875 +93378 76216 +46284 95037 +41664 15145 +84475 39021 +52069 55213 +94827 20473 +79648 48127 +43947 76411 +20473 71938 +70251 80695 +13125 65297 +49246 75802 +49184 15227 +92091 54909 +31992 41267 +45911 19856 +93403 97963 +45807 76216 +61063 41259 +47907 21322 +15388 15227 +85798 13686 +60015 50364 +34294 34597 +14526 70647 +79498 72002 +76367 46598 +10763 67546 +53531 88962 +86158 30240 +48843 20473 +74127 95846 +29239 39021 +89243 55213 +42208 52849 +11396 54168 +51485 54805 +28347 34661 +32396 55213 +89137 18330 +84414 55213 +64013 12511 +50364 62725 +69550 70382 +75395 47413 +86240 56543 +22944 56900 +99262 56543 +70893 48848 +49889 85195 +41385 85280 +33498 11649 +53359 11649 +35483 61686 +15429 34776 +82878 78142 +71716 76015 +63677 22034 +38703 71901 +88599 89560 +34092 19913 +79849 34661 +86969 51576 +28571 33019 +26154 22944 +52835 29417 +53205 77890 +20276 39461 +82458 50421 +85308 55213 +23780 34661 +35311 30488 +42273 63441 +68289 14174 +53846 48389 +66984 86158 +69976 83576 +44223 36234 +40372 27603 +83168 76216 +60101 62691 +99675 90166 +70006 84175 +24063 54443 +54560 10210 +30011 34776 +77029 26998 +37798 77700 +69137 77283 +68787 22650 +93357 39021 +18050 81124 +78744 18131 +32059 46598 +21287 42621 +42292 11649 +99706 11352 +86307 34948 +53716 41259 +84440 80333 +39562 66295 +81493 90431 +64911 41267 +41829 82797 +33421 55780 +73962 65004 +70599 48389 +71389 78405 +56211 96609 +86614 20276 +60185 18584 +46519 19856 +85341 21402 +63706 54396 +99509 19131 +77048 68330 +47476 41259 +19677 48389 +21320 22944 +98668 67439 +77246 41489 +20072 31880 +63382 27469 +86557 20276 +80371 51645 +24256 21964 +53783 49002 +36807 85389 +98394 82801 +95346 86158 +10431 85065 +98843 95846 +18651 63897 +10144 65443 +49483 34856 +72449 30766 +94011 91054 +11029 24754 +36006 54821 +18459 65297 +52537 10646 +58677 95846 +52571 24400 +45008 53241 +84084 59701 +63723 65432 +41397 25462 +66176 94916 +37821 87108 +10786 81993 +43825 48389 +59143 99924 +55219 45778 +53780 75436 +52820 46104 +23497 84939 +88371 58423 +41259 37181 +22603 76216 +99333 15881 +96990 19856 +56662 49575 +54876 67245 +25213 78142 +24559 78821 +58907 68881 +14836 15227 +22463 68881 +52592 29417 +39763 40027 +28925 62885 +74177 38729 +58731 56543 +86958 26033 +50538 25025 +18993 10013 +80692 56917 +27924 43417 +57696 84166 +66253 34776 +27631 43340 +66106 94016 +95853 48244 +70430 82286 +23027 26092 +56532 95846 +67501 45349 +12215 41267 +19720 50585 +96226 45042 +74000 27047 +62451 32342 +31717 76164 +45992 51137 +41345 62978 +58818 89347 +49405 34661 +71577 69710 +54334 20032 +23609 78142 +34661 25224 +15665 41259 +69935 21666 +30320 10215 +47745 22944 +16919 79188 +90987 50880 +43151 35249 +56543 85280 +31607 43137 +50565 96043 +76216 53795 +31299 74160 +12068 52582 +34212 25224 +59157 27762 +49371 80778 +12067 34054 +84925 15227 +94050 15227 +16313 95846 +45020 76657 +96730 50985 +35597 80727 +15922 86678 +72237 15949 +19348 91593 +22493 50364 +81453 36932 +63469 31880 +83204 44281 +97516 76216 +29851 85280 +83853 50364 +22722 65432 +44826 11286 +78112 61461 +34712 11649 +77566 63897 +89300 56543 +84751 22250 +17748 34661 +26317 65297 +93586 85526 +93545 46598 +80829 92121 +31655 65297 +70888 19856 +78658 67271 +19856 34776 +39960 56479 +61689 39021 +70480 50390 +55500 21322 +43674 65945 +17507 21322 +37527 60767 +46386 25187 +26815 49575 +84007 56865 +88175 51137 +36052 48389 +59939 53813 +72268 65297 +81352 61501 +16822 68881 +36521 85280 +34361 99506 +63695 86158 +98179 63897 +84080 95846 +35952 25224 +63718 16985 +47260 21322 +32958 86125 +46871 95846 +84506 62971 +22962 87402 +44900 74111 +79913 81638 +83540 20473 +90341 89847 +17097 75291 +95448 11649 +10951 65297 +66309 43216 +71201 15227 +52481 62912 +21951 51137 +22464 62319 +10029 63499 +78832 76216 +98333 11649 +40894 68881 +52946 19856 +50329 14803 +29823 39056 +76686 20473 +83170 26188 +53459 68881 +13042 33617 +78116 60418 +48212 51137 +92069 88727 +57787 34115 +73872 25224 +50550 18671 +97638 62724 +41131 65597 +84806 55213 +94592 31880 +71180 41259 +92360 97729 +98620 62980 +34471 52669 +91532 20276 +35790 61616 +75503 15748 +75074 21322 +11737 41127 +77602 25224 +94166 11649 +11580 58318 +33589 65023 +28957 41259 +48071 85280 +46598 71087 +36777 62347 +60594 20473 +81800 83420 +31339 40736 +16207 47305 +23624 48389 +41126 73202 +95465 44217 +73513 58171 +48492 34661 +27319 65297 +15520 19856 +48278 74391 +42528 42241 +21889 96386 +61833 19076 +13142 93210 +19905 15227 +64895 13547 +15908 78271 +20442 55213 +33221 50364 +78895 40466 +56182 97639 +40093 14980 +85157 26820 +36540 96113 +56873 49315 +39565 30340 +93297 49684 +43957 63789 +63897 50409 +69723 58764 +26167 17686 +78216 51576 +66527 84415 +51137 19856 +36635 56543 +59257 93611 +80851 26970 +21322 36633 +60017 19856 +74310 12230 +54464 85280 +74537 55813 +55344 19856 +19176 41267 +31914 76216 +77455 80335 +34039 39669 +35118 89909 +65432 74023 +37950 11649 +36603 62501 +52464 46856 +32342 72736 +89467 63318 +98246 67207 +15075 17421 +76916 74263 +92157 95846 +31880 43080 +45051 13900 +91452 67550 +68619 90797 +54105 39021 +33071 72624 +63784 57575 +67379 49283 +38131 29417 +57202 55213 +21615 56543 +90526 46598 +96898 65297 +49860 34661 +74266 93975 +21484 44229 +66643 68881 +16715 84749 +90512 73621 +89388 16965 +94053 36641 +35962 65432 +29763 47174 +14745 77272 +34993 34661 +83014 11649 +60837 92670 +15494 20473 +47055 93024 +12035 36814 +49721 39021 +26438 39677 +21933 19856 +16148 40828 +87391 68949 +56399 22506 +48696 72022 +95549 10092 +18684 52865 +44990 21322 +77310 19856 +35505 83623 +89352 74555 +86186 55213 +23227 94800 +37067 34776 +74039 42442 +53442 92091 +85527 55213 +64005 63897 +60463 60857 +84190 19303 +11722 99564 +47545 20473 +50423 25224 +19300 13219 +11549 88441 +41246 56543 +64539 21322 +16656 21331 +81984 29417 +21166 65297 +27236 27913 +73250 22933 +14078 21480 +86888 37494 +60623 68881 +56818 25224 +92340 28382 +72247 42211 +19198 85280 +29546 52039 +44394 65297 +14866 21610 +67444 21322 +85995 96825 +71932 38843 +99764 34776 +79024 43841 +59707 89498 +45503 87250 +83594 96789 +85277 55213 +32640 95846 +27823 23982 +28543 31399 +33759 95846 +23087 91530 +93094 93695 +88151 82097 +53506 17212 +61712 63975 +69833 45914 +19987 60322 +68648 28755 +15919 34380 +76804 90603 +83622 39021 +89705 46485 +29860 58935 +58392 78957 +26149 17889 +19305 89821 +88282 17673 +14085 75808 +78937 41259 +75320 64962 +84453 21322 +29476 94656 +84039 41267 +84385 11391 +39529 52865 +63057 23532 +37397 56543 +39202 19856 +90160 15799 +20310 22944 +40937 41267 +44029 91325 +50399 34661 +83445 39021 +58878 60759 +87071 87733 +44142 46155 +71837 82441 +74478 86781 +68295 50364 +94162 65432 +69323 97655 +63974 61934 +39245 98569 +13669 47701 +44744 34661 +75459 50364 +88291 55213 +99416 11649 +36887 85280 +29988 45252 +97663 76216 +35645 26140 +78021 85280 +67424 69456 +72759 79790 +33820 20473 +95942 39872 +81333 85280 +40810 61461 +69479 32816 +15379 24034 +11921 13179 +52719 54900 +20410 63897 +97887 15408 +40546 43910 +44053 49808 +90572 60565 +80385 78142 +40458 95846 +92895 29481 +30189 84413 +52865 69499 +19745 52865 +50975 49392 +89519 73695 +86176 38188 +47604 62257 +67436 29417 +11296 82182 +85459 91364 +27362 38039 +10585 59869 +46438 22944 +44742 35866 +85280 16513 +21227 81727 +16973 32676 +47127 68881 +98849 68881 +38328 21322 +12186 31773 +13799 71462 +13565 51576 +29848 45510 +76548 86158 +67804 56543 +55213 88508 +88481 12489 +13389 41259 +25035 88404 +50679 51137 +13786 85280 +50406 11649 +38054 89777 +79568 24534 +24756 85373 +93482 86158 +43790 79276 +60250 83576 +43730 21322 +87160 36323 +88807 61112 +97993 89540 +44262 89194 +82245 85280 +40413 96894 +56866 55804 +27892 93799 +15314 52111 +23042 60143 +97060 89497 +58200 19325 +27659 67004 +89411 22944 +87316 89489 +19976 37593 +38865 11649 +45078 24406 +36358 55213 +45579 35021 +99402 73275 +40782 20276 +48389 34465 +61983 65432 +46549 71333 +60731 50364 +28239 82886 +37245 84331 +89695 72707 +45702 35310 +46936 95846 +31661 65432 +63867 34661 +22578 46504 +35924 99928 +97445 95928 +60411 48389 +36833 68881 +10278 50364 +39206 34776 +95474 94852 +15159 45432 +90288 95481 +77881 30096 +56304 62251 +49910 81451 +13678 21322 +42650 94971 +75244 74862 +77750 74920 +54566 50186 +92641 49575 +23566 81405 +39983 70620 +82218 31880 +95885 58807 +97444 40125 +86195 35943 +34776 68881 +20384 76109 +91857 44727 +59888 33738 +47992 61640 +50291 53340 +59747 40258 +98077 68881 +11930 29301 +52116 44318 +96256 77071 +75365 39021 +14830 29417 +34876 92947 +48613 17514 +43229 85569 +15955 72245 +61458 76216 +74993 61461 +97198 63897 +66233 56543 +92861 80868 +22888 50889 +11649 15227 +72510 44999 +60024 46310 +51981 78952 +30134 85280 +15153 48389 +32013 53946 +14541 27325 +54878 19856 +12630 51576 +12646 63897 +68382 76216 +40855 21322 +31477 99082 +94979 10843 +82341 87920 +35488 41259 +57823 99959 +90928 54338 +91407 51576 +81221 22944 +55919 42682 +27235 95483 +68881 73120 +21359 46598 +59534 46435 +91806 50364 +42497 15227 +57049 12517 +76929 26842 +76110 68881 +78586 39021 +51225 65432 +87650 93875 +48080 35764 +68282 80266 +23715 24411 +62383 46689 +35851 38657 +48668 35985 +57008 42062 +44396 52990 +97855 71998 +35578 28469 +22235 56010 +70948 68881 +77965 73892 +15973 14537 +35328 85469 +94454 46598 +62384 19856 +78071 20276 +88122 86158 +88105 68881 +77090 23412 +11822 55213 +31989 39118 +68039 65297 +81126 55174 +43631 32060 +11917 11649 +11974 29417 +62698 41674 +64496 28711 +33691 73796 +92195 66727 +11682 20677 +65996 79079 +92131 95846 +44640 25224 +62049 65297 +67359 34661 +63094 29497 +24813 67897 +41267 38839 +13278 56543 +71572 12828 +80808 78142 +56156 95846 +51530 89113 +75797 63897 +93988 35495 +30272 68056 +31629 16046 +17562 34661 +34072 96205 +43904 62359 +83398 49834 +28423 97195 +82852 90842 +49810 31220 +66513 50188 +27911 45688 +56971 20473 +22800 78142 +86334 41267 +93393 11649 +84601 71534 +86633 79250 +60407 78142 +85126 53116 +74638 36062 +20964 71314 +82352 36930 +83394 29417 +65297 11649 +10164 29082 +15227 76216 +95846 48389 +91167 80269 +72154 47261 +71176 19856 +75281 65297 +51576 50364 +89997 24184 +53631 65432 +24704 25224 +39021 21322 +64838 19091 +76401 48512 +13948 34578 +33099 63897 +94777 12300 +59825 51487 +96739 30997 +41555 48028 +12667 15227 +16397 51137 +74081 58852 +53928 55213 +34791 42483 +29417 27352 +87524 89512 +25224 76216 +47202 25224 +30915 34551 +79149 89897 +92898 72170 +84546 19856 +63881 22611 +65227 85280 +68664 11649 +13738 11834 +48100 20473 +31647 12357 +58285 82005 +38498 61310 +17399 29417 +53470 56543 +94488 41267 +55069 51137 +65843 12011 +86089 21427 +98998 69258 +93772 50364 +61461 21322 +32797 20276 +63534 45983 +42044 68881 +49575 49268 +89725 71824 +13151 55213 +47235 50474 +70742 41267 +69846 83201 +49984 45584 +70773 16704 +41907 58931 +80020 78319 +38557 41267 +59468 17081 +24017 20360 +83576 26453 +44100 42968 +32619 97934 +95538 95846 +10470 41259 +40765 22806 +84349 19856 +31770 75551 +63239 76216 +22175 31938 +50014 51673 +18008 84899 +98253 72600 +38935 22946 +94044 29417 +12440 63667 +71981 22652 +35876 56543 +13131 22143 +78690 34776 +27878 11370 +19659 34776 +64979 50364 +89717 30357 +71844 92010 +26402 90514 +78750 74617 +53297 22944 +49589 50364 +16296 69699 +46311 74647 +83938 50477 +73500 84604 +38665 68881 +62321 73263 +79989 10191 +81079 63922 +19186 15227 +89155 56543 +90154 27651 +36567 65164 +95351 20473 +73278 40535 +47097 19856 +62480 41267 +51246 25224 +94838 27133 +98878 22911 +73123 91366 +21914 67909 +87431 81551 +27032 15227 +15090 61123 +13350 98688 +37173 58301 +92022 11981 +66900 26049 +18381 10986 +75360 15227 +69620 79680 +18780 60264 +84878 68881 +15467 33806 +71799 58322 +47180 19679 +39054 92091 +29531 94509 +62925 70352 +99943 51998 +64891 75738 +88061 20473 +98252 59643 +12766 64598 +38349 30817 +50824 41267 +47031 97828 +82027 46701 +59404 40860 +88020 78142 +83250 72893 +37738 53309 +85272 34122 +57713 65432 +56624 78571 +10906 55213 +42778 39021 +56224 59056 +71584 44879 +42348 55213 +53434 75449 +78142 14981 +40177 28988 +54053 68881 +66277 69900 +35127 50364 +54463 21098 +21554 87868 +89672 76216 +95148 82149 +74621 76216 +40237 20473 +10257 20473 +70014 41883 +42436 41267 +59460 71093 +57487 15227 +65720 91317 +98718 92080 +88722 21322 +63630 26854 +49789 89200 +96784 20473 +30583 20473 +41407 56714 +86109 34661 +13834 44624 +19298 44781 +67868 48389 +73954 14305 +78878 48389 +99934 63566 +53524 51137 +77891 26553 +98684 68881 +28112 38511 +80455 33657 +45447 51355 +77158 75485 +16208 55213 +37619 41978 +77064 20473 +38184 80480 +57747 89791 +88771 29417 +78861 95846 +87502 11649 +31852 98307 +50648 47711 +23961 34661 +96913 79564 diff --git a/2024/02/code.py b/2024/02/code.py new file mode 100644 index 0000000..9e1fc96 --- /dev/null +++ b/2024/02/code.py @@ -0,0 +1,33 @@ +import numpy as np +from pathlib import Path + +filepath = Path("./data/2_example") +filepath = Path("./data/2_input") + +with open(filepath, 'r') as filein: + data = [np.array([int(i) for i in l.split()]) for l in filein.readlines()] + +def report_is_safe(a: np.ndarray): + diff = np.diff(a) + if np.any(np.abs(diff)>3): + return False + sign = np.sign(diff) + steady = np.all(sign>0) or np.all(sign<0) + if not steady: + return False + return True + +analysis = [report_is_safe(r) for r in data] +print(sum(analysis)) + + +def brute_force(a: np.ndarray): + if report_is_safe(a): + return True + for i in range(len(a)): + if report_is_safe(np.delete(a, i)): + return True + return False + +analysis = [brute_force(r) for r in data] +print(sum(analysis)) diff --git a/2024/02/example b/2024/02/example new file mode 100644 index 0000000..b49c10d --- /dev/null +++ b/2024/02/example @@ -0,0 +1,6 @@ +7 6 4 2 1 +1 2 7 8 9 +9 7 6 2 1 +1 3 2 4 5 +8 6 4 4 1 +1 3 6 7 9 diff --git a/2024/02/info.txt b/2024/02/info.txt new file mode 100644 index 0000000..cdfe210 --- /dev/null +++ b/2024/02/info.txt @@ -0,0 +1,57 @@ +--- Day 2: Red-Nosed Reports --- + +Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. + +While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron. + +They're quick to add that - since you're already here - they'd really appreciate your help analyzing some unusual data from the Red-Nosed reactor. You turn to check if The Historians are waiting for you, but they seem to have already divided into groups that are currently searching every corner of the facility. You offer to help with the unusual data. + +The unusual data (your puzzle input) consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example: + +7 6 4 2 1 +1 2 7 8 9 +9 7 6 2 1 +1 3 2 4 5 +8 6 4 4 1 +1 3 6 7 9 + +This example data contains six reports each containing five levels. + +The engineers are trying to figure out which reports are safe. The Red-Nosed reactor safety systems can only tolerate levels that are either gradually increasing or gradually decreasing. So, a report only counts as safe if both of the following are true: + + The levels are either all increasing or all decreasing. + Any two adjacent levels differ by at least one and at most three. + +In the example above, the reports can be found safe or unsafe by checking those rules: + + 7 6 4 2 1: Safe because the levels are all decreasing by 1 or 2. + 1 2 7 8 9: Unsafe because 2 7 is an increase of 5. + 9 7 6 2 1: Unsafe because 6 2 is a decrease of 4. + 1 3 2 4 5: Unsafe because 1 3 is increasing but 3 2 is decreasing. + 8 6 4 4 1: Unsafe because 4 4 is neither an increase or a decrease. + 1 3 6 7 9: Safe because the levels are all increasing by 1, 2, or 3. + +So, in this example, 2 reports are safe. + +Analyze the unusual data from the engineers. How many reports are safe? + +--- Part Two --- + +The engineers are surprised by the low number of safe reports until they realize they forgot to tell you about the Problem Dampener. + +The Problem Dampener is a reactor-mounted module that lets the reactor safety systems tolerate a single bad level in what would otherwise be a safe report. It's like the bad level never happened! + +Now, the same rules apply as before, except if removing a single level from an unsafe report would make it safe, the report instead counts as safe. + +More of the above example's reports are now safe: + + 7 6 4 2 1: Safe without removing any level. + 1 2 7 8 9: Unsafe regardless of which level is removed. + 9 7 6 2 1: Unsafe regardless of which level is removed. + 1 3 2 4 5: Safe by removing the second level, 3. + 8 6 4 4 1: Safe by removing the third level, 4. + 1 3 6 7 9: Safe without removing any level. + +Thanks to the Problem Dampener, 4 reports are actually safe! + +Update your analysis by handling situations where the Problem Dampener can remove a single level from unsafe reports. How many reports are now safe? diff --git a/2024/02/input b/2024/02/input new file mode 100644 index 0000000..f577cd1 --- /dev/null +++ b/2024/02/input @@ -0,0 +1,1000 @@ +73 75 78 81 80 +81 82 83 86 89 89 +66 67 68 71 75 +66 67 69 70 72 74 77 83 +88 90 93 90 91 92 +61 62 60 63 60 +39 41 44 47 48 45 47 47 +63 66 63 66 70 +92 95 92 93 98 +86 88 91 91 92 +39 41 41 42 44 46 49 46 +79 81 82 82 83 84 84 +58 60 63 65 67 67 71 +63 65 66 67 67 70 76 +83 85 88 90 94 96 97 +27 30 34 36 39 40 41 40 +76 78 82 85 86 88 90 90 +57 60 61 63 67 69 73 +63 66 70 71 73 74 80 +42 43 45 51 53 55 +82 85 86 89 92 98 97 +44 45 47 54 54 +31 33 40 43 47 +54 56 59 66 71 +84 82 83 84 85 88 90 +60 59 61 63 66 69 70 69 +33 31 34 35 35 +39 36 38 41 44 46 48 52 +82 81 84 87 93 +63 62 59 62 65 66 +20 18 21 19 17 +43 40 41 40 40 +88 86 87 90 88 91 94 98 +36 34 36 33 34 41 +17 15 16 18 18 20 23 24 +80 77 79 79 77 +93 92 93 95 95 95 +29 27 29 30 31 31 35 +30 29 31 34 36 36 38 43 +31 30 33 37 38 41 42 +12 10 11 15 16 13 +54 51 55 57 59 60 63 63 +60 58 61 65 66 70 +86 83 85 89 90 92 93 99 +28 27 33 36 37 40 42 +47 46 49 51 52 53 58 56 +22 21 23 24 27 34 37 37 +39 38 45 46 48 49 53 +54 51 53 54 57 64 69 +24 24 25 27 29 31 34 37 +69 69 72 75 77 78 77 +16 16 19 21 24 27 27 +26 26 27 29 32 36 +60 60 62 63 65 68 71 76 +71 71 72 73 74 72 75 77 +68 68 67 68 69 70 73 71 +53 53 52 55 58 58 +54 54 52 55 56 60 +32 32 34 35 38 40 38 45 +73 73 73 75 76 +5 5 7 8 8 10 9 +9 9 10 12 15 15 15 +5 5 7 7 10 14 +77 77 80 80 83 86 91 +73 73 77 78 80 83 +8 8 10 11 15 18 21 19 +22 22 24 26 30 30 +68 68 71 75 79 +83 83 87 88 90 95 +33 33 38 40 42 +71 71 74 79 76 +18 18 19 24 25 25 +85 85 90 92 96 +41 41 48 50 57 +54 58 59 61 62 +67 71 72 74 75 77 74 +24 28 31 32 32 +48 52 55 57 58 62 +68 72 74 75 77 78 83 +46 50 49 51 52 54 57 58 +5 9 10 9 10 9 +36 40 43 44 45 46 45 45 +28 32 34 33 35 37 41 +81 85 84 87 88 93 +5 9 12 15 15 17 +41 45 48 48 49 52 49 +8 12 13 15 18 18 18 +16 20 20 23 26 27 29 33 +75 79 80 80 87 +79 83 86 88 91 95 97 98 +59 63 67 70 69 +52 56 59 63 63 +8 12 14 17 20 22 26 30 +74 78 82 84 91 +79 83 85 86 91 92 93 +68 72 73 80 77 +71 75 77 84 86 87 89 89 +70 74 75 81 85 +2 6 11 14 19 +52 59 62 63 65 66 67 +74 80 83 85 86 89 88 +44 51 52 54 55 58 58 +58 64 65 68 69 70 74 +38 45 48 49 50 52 57 +45 51 54 57 60 62 59 60 +41 46 48 47 50 48 +18 23 25 27 26 28 29 29 +84 89 90 92 90 91 95 +28 33 36 34 37 44 +38 44 45 45 47 50 +5 11 12 12 14 17 16 +45 52 55 55 55 +78 84 86 86 88 91 95 +67 73 73 74 80 +1 8 11 12 16 18 +8 13 17 19 21 22 21 +48 54 58 60 63 65 65 +29 36 40 43 47 +14 21 23 24 28 35 +81 87 89 95 97 98 99 +43 50 57 60 62 61 +44 51 54 55 61 62 65 65 +18 25 32 33 37 +37 43 46 53 59 +72 69 66 64 61 59 56 59 +87 86 83 82 79 76 76 +82 80 78 76 75 73 70 66 +23 22 19 16 11 +59 58 57 55 58 56 53 50 +16 13 10 7 10 9 7 9 +93 92 90 91 91 +24 21 20 22 20 16 +49 47 46 47 44 43 37 +96 95 93 91 91 88 +94 91 90 90 89 92 +73 71 69 69 68 65 65 +57 54 51 51 47 +66 64 64 62 55 +26 25 21 18 16 15 13 12 +53 51 47 46 44 41 39 40 +32 29 27 23 22 20 20 +42 41 38 35 31 29 28 24 +36 33 30 28 24 22 17 +29 28 22 21 18 +77 75 73 70 65 62 61 63 +42 40 38 31 29 28 26 26 +38 35 30 27 24 20 +35 34 28 25 22 21 15 +12 13 10 8 6 +93 95 92 90 87 89 +63 65 63 62 60 57 57 +98 99 97 95 93 91 87 +58 61 59 56 53 51 44 +92 93 91 93 92 90 87 85 +82 85 84 83 80 83 86 +42 45 44 42 45 45 +42 43 41 44 41 38 34 +96 99 97 94 91 90 92 87 +96 98 95 95 93 92 +23 26 25 22 21 19 19 20 +35 36 34 31 31 31 +22 23 22 22 18 +57 58 57 54 54 51 46 +83 84 80 77 74 72 71 +69 70 67 63 66 +83 86 83 79 79 +14 17 16 12 9 7 5 1 +26 28 24 21 14 +66 67 62 61 60 57 +59 62 61 60 55 54 53 56 +23 25 20 17 16 14 11 11 +30 32 30 28 27 20 17 13 +62 65 64 57 55 52 51 44 +74 74 73 71 69 +59 59 58 55 57 +28 28 25 23 20 17 15 15 +32 32 31 30 27 26 22 +69 69 68 65 59 +27 27 25 24 26 24 23 +37 37 36 38 35 37 +10 10 11 8 8 +65 65 67 65 63 62 58 +76 76 75 77 71 +61 61 59 56 56 54 52 50 +18 18 16 15 14 13 13 14 +69 69 69 67 66 63 60 60 +72 72 70 67 65 62 62 58 +88 88 88 87 80 +69 69 66 63 59 58 +94 94 93 89 92 +85 85 81 78 78 +20 20 16 14 10 +77 77 74 72 70 66 60 +54 54 52 45 44 43 42 40 +40 40 33 32 34 +67 67 60 59 59 +19 19 14 12 8 +78 78 76 73 71 65 60 +35 31 28 27 24 +35 31 29 28 25 24 23 26 +58 54 52 51 49 49 +52 48 46 44 42 39 35 +51 47 44 42 41 34 +59 55 52 50 53 51 +45 41 43 40 41 +61 57 58 56 56 +25 21 24 23 21 20 16 +35 31 28 31 28 25 20 +23 19 16 16 15 +91 87 86 85 82 81 81 84 +57 53 53 51 50 49 49 +66 62 62 60 57 54 50 +56 52 49 49 48 45 38 +24 20 17 14 10 8 +23 19 16 15 13 10 6 8 +61 57 56 52 50 47 47 +83 79 77 75 71 67 +27 23 21 17 11 +74 70 68 63 62 61 59 57 +48 44 38 35 38 +50 46 45 39 39 +68 64 57 54 50 +78 74 73 72 67 61 +66 61 58 57 54 +37 30 28 26 28 +31 25 22 19 17 17 +79 73 71 68 67 63 +66 61 59 56 50 +34 28 26 24 25 24 22 +15 8 9 8 10 +71 66 65 64 61 63 61 61 +24 17 15 13 11 9 11 7 +97 90 88 87 89 84 +67 60 59 59 57 +46 41 39 36 36 39 +14 9 8 8 7 7 +86 79 78 75 75 74 70 +67 60 60 59 52 +92 87 86 83 80 76 74 73 +29 23 21 19 16 12 15 +83 76 72 70 70 +80 75 74 72 69 66 62 58 +47 40 39 35 32 26 +32 26 19 16 14 12 +40 34 33 27 26 25 23 26 +52 47 45 44 41 34 33 33 +20 14 13 11 5 1 +55 50 48 47 42 37 +52 55 56 57 60 61 63 62 +19 21 22 23 26 29 29 +70 73 75 78 81 83 87 +59 62 64 65 66 68 74 +47 48 50 49 52 +37 38 41 44 42 43 44 42 +18 20 19 22 24 27 27 +53 56 57 58 60 61 60 64 +57 59 60 58 59 66 +52 53 53 56 58 59 +45 48 49 49 50 47 +21 23 24 24 24 +26 28 31 31 32 34 38 +18 19 21 21 26 +52 54 56 60 63 65 66 69 +26 29 31 32 33 37 40 38 +31 32 35 39 42 42 +57 59 60 61 65 68 71 75 +41 44 47 51 53 59 +23 25 28 34 37 40 42 +59 60 62 63 65 72 69 +11 13 15 22 23 25 25 +35 36 42 43 45 48 50 54 +54 57 58 60 67 69 74 +44 41 42 43 45 +78 76 78 81 83 84 82 +48 45 46 48 51 54 54 +62 61 64 67 68 72 +26 23 24 26 29 30 37 +26 23 20 23 26 27 +45 43 45 46 48 47 48 47 +41 40 42 40 43 43 +22 21 18 21 23 24 25 29 +88 85 87 88 89 90 88 94 +40 38 39 39 40 43 45 +53 51 54 57 57 55 +53 52 54 54 54 +30 29 29 30 34 +17 16 16 17 24 +2 1 4 8 9 11 14 +56 53 54 58 61 60 +52 51 54 58 60 60 +43 42 45 49 53 +54 53 56 60 65 +62 60 66 69 72 +13 10 11 17 19 20 18 +11 10 11 14 17 24 26 26 +41 40 42 45 47 50 56 60 +45 44 50 51 56 +3 3 4 5 7 9 12 13 +74 74 75 76 79 78 +81 81 84 85 88 89 89 +28 28 29 31 33 34 38 +44 44 46 49 52 54 57 62 +5 5 8 7 9 +22 22 20 23 25 23 +51 51 50 51 54 57 57 +52 52 49 51 55 +28 28 30 29 36 +38 38 39 41 41 43 46 +53 53 54 54 56 54 +15 15 18 18 19 22 22 +9 9 9 11 14 18 +2 2 5 8 8 11 16 +49 49 50 53 54 58 59 60 +84 84 87 91 92 90 +4 4 8 11 11 +8 8 12 15 19 +52 52 55 59 60 66 +6 6 7 8 13 16 +67 67 68 74 73 +32 32 39 40 43 43 +43 43 46 53 55 58 61 65 +83 83 88 90 92 99 +70 74 77 78 81 82 85 +17 21 24 26 28 30 28 +43 47 49 52 52 +62 66 67 69 73 +55 59 62 63 65 68 73 +29 33 35 37 34 36 38 40 +54 58 55 57 60 58 +26 30 28 31 31 +41 45 47 46 49 53 +30 34 37 35 37 40 47 +71 75 77 79 82 82 83 +47 51 51 54 57 60 63 61 +82 86 88 89 89 89 +27 31 32 32 34 38 +39 43 44 44 47 48 54 +47 51 54 55 58 62 64 67 +23 27 28 32 33 30 +38 42 45 46 50 53 53 +25 29 33 36 39 43 +18 22 23 27 34 +80 84 86 87 88 95 98 +25 29 31 37 35 +30 34 36 37 44 44 +67 71 74 81 82 83 87 +20 24 27 34 37 42 +34 41 43 45 46 47 +41 46 48 51 53 54 55 52 +26 31 33 35 37 39 42 42 +62 69 72 73 76 80 +53 59 62 65 71 +41 46 47 48 49 50 47 49 +68 74 72 73 74 76 79 78 +42 49 47 50 51 52 54 54 +6 11 9 11 15 +19 26 25 27 29 34 +39 46 47 47 49 +82 88 91 93 96 96 98 95 +2 9 9 11 11 +60 66 67 67 71 +17 23 23 26 27 33 +5 11 14 15 19 20 22 +5 10 12 16 17 15 +63 70 74 77 77 +30 36 39 43 47 +6 11 15 16 17 24 +15 21 24 30 31 +72 79 81 88 87 +31 36 42 45 48 49 51 51 +18 24 31 32 36 +26 31 32 38 39 40 41 48 +43 41 39 36 35 38 +75 74 71 69 66 64 64 +39 36 33 32 29 26 25 21 +35 32 31 28 26 20 +24 23 22 24 23 20 19 18 +30 29 28 29 28 29 +62 60 59 58 57 60 60 +44 42 41 38 40 36 +89 88 87 85 83 84 81 74 +52 49 48 45 45 44 +41 38 37 37 35 32 31 34 +57 55 54 54 54 +46 45 44 42 40 40 36 +25 23 21 21 15 +74 73 70 66 63 60 +55 53 51 47 44 41 43 +69 67 66 62 60 60 +97 96 94 90 89 86 82 +44 41 40 36 35 32 25 +44 43 37 35 32 +74 72 65 62 60 63 +58 55 52 47 46 43 40 40 +89 87 81 78 77 73 +74 71 68 61 55 +31 32 31 28 27 25 +8 10 9 8 10 +79 80 78 76 74 72 72 +90 92 90 89 86 85 81 +92 95 94 93 91 90 87 82 +18 21 23 20 17 +69 70 67 65 67 64 66 +95 97 94 93 91 94 94 +39 41 44 41 39 35 +18 21 24 22 16 +3 5 4 4 2 1 +27 30 30 29 30 +6 9 8 7 7 7 +78 79 78 78 77 75 71 +98 99 98 97 96 96 89 +21 23 19 17 16 13 10 +44 46 44 41 39 36 32 35 +13 15 11 9 7 7 +78 81 77 74 70 +91 94 92 88 83 +85 88 85 79 78 +92 93 90 83 84 +85 88 86 80 78 77 75 75 +25 26 24 23 21 18 11 7 +17 18 11 10 9 2 +72 72 71 68 67 +64 64 62 60 62 +54 54 52 49 49 +95 95 94 91 90 86 +17 17 14 11 5 +37 37 38 35 34 +99 99 96 93 94 97 +78 78 81 78 75 73 73 +84 84 81 78 80 76 +85 85 83 85 82 79 77 71 +92 92 92 91 90 88 86 85 +75 75 75 74 71 70 67 69 +5 5 3 3 3 +64 64 62 62 59 55 +87 87 85 85 84 77 +40 40 39 35 34 +60 60 57 54 50 47 45 47 +44 44 42 40 37 36 32 32 +53 53 51 49 48 44 40 +56 56 55 52 51 47 42 +20 20 18 13 10 9 +18 18 13 10 9 7 6 8 +96 96 93 90 85 82 80 80 +68 68 65 59 57 53 +97 97 92 89 84 +53 49 46 43 40 37 35 +39 35 32 31 29 26 24 27 +32 28 27 26 25 24 24 +77 73 70 68 67 63 +46 42 41 38 36 34 29 +29 25 24 27 25 22 20 17 +54 50 51 49 46 48 +75 71 68 71 70 70 +20 16 19 16 12 +93 89 88 86 83 86 84 78 +58 54 54 53 50 +59 55 52 49 49 48 49 +75 71 71 70 67 67 +24 20 19 19 15 +54 50 48 48 43 +54 50 46 45 42 39 38 37 +22 18 14 13 14 +62 58 57 53 53 +21 17 14 10 8 4 +38 34 30 27 26 24 17 +61 57 55 54 47 44 +59 55 48 45 43 42 43 +71 67 64 61 56 55 53 53 +99 95 93 91 85 83 79 +85 81 80 78 71 65 +34 27 26 25 24 +44 39 37 34 37 +58 53 50 49 47 45 43 43 +25 18 15 14 10 +66 59 58 56 55 50 +46 41 38 37 35 37 34 31 +93 87 89 86 89 +18 11 10 11 9 7 6 6 +94 88 91 88 87 86 82 +30 24 23 21 22 15 +74 67 65 65 62 +78 73 72 72 75 +69 62 62 60 58 55 55 +90 83 83 80 78 74 +51 45 45 44 41 40 37 32 +33 27 23 21 18 16 +27 20 19 15 17 +92 87 83 82 79 77 77 +88 83 79 78 77 73 +46 41 37 34 32 29 23 +70 65 62 57 55 52 49 46 +95 88 81 80 83 +93 87 82 79 78 75 74 74 +98 91 86 84 83 79 +80 73 66 63 58 +21 14 11 8 1 +29 23 22 20 17 12 8 +39 41 39 38 34 32 29 +1 2 5 6 12 16 +23 29 31 35 37 35 +64 64 62 58 56 55 55 +80 78 76 75 74 75 +53 53 52 53 50 48 47 43 +70 72 78 79 81 83 +38 34 29 27 24 22 18 +46 47 46 43 40 39 37 +12 12 14 11 13 +13 18 21 26 30 +71 66 61 60 59 62 +32 29 32 33 34 36 40 +58 51 48 43 42 39 39 +5 5 6 5 7 +84 83 82 84 82 77 +60 53 49 48 45 44 37 +28 27 30 32 32 32 +11 15 15 16 17 23 +43 47 48 53 52 +67 71 73 74 74 75 77 74 +10 13 14 15 18 18 +58 62 63 67 64 +74 80 82 84 87 84 84 +67 63 61 60 58 60 59 54 +21 25 28 31 32 35 38 37 +90 88 87 90 87 84 81 77 +19 23 28 31 34 +63 59 59 58 58 +83 82 79 79 78 80 +3 7 13 15 16 18 21 25 +12 12 14 17 18 21 19 +96 96 90 89 84 +51 55 57 59 62 66 68 72 +7 11 14 16 15 17 19 19 +57 52 51 49 48 46 39 38 +85 84 86 88 92 97 +16 12 8 7 6 3 +78 71 68 66 62 61 58 59 +15 21 24 26 29 26 29 30 +17 13 10 9 6 4 3 +17 18 19 21 19 22 22 +18 18 21 18 21 22 23 27 +63 67 72 75 78 80 82 88 +44 40 38 36 36 34 +59 55 52 51 48 45 42 42 +95 94 91 90 89 83 +61 61 66 69 70 72 76 +61 62 60 58 54 52 49 42 +64 64 63 62 61 61 57 +69 72 71 71 70 70 +49 48 49 51 51 +50 44 44 41 37 +76 79 83 86 89 92 95 95 +16 13 11 11 9 8 +92 95 92 90 89 82 +37 33 32 35 34 32 30 +5 9 11 13 15 18 22 +6 10 13 12 14 17 +62 63 65 68 69 68 71 70 +18 14 13 10 9 11 +23 30 37 38 41 44 47 49 +15 18 17 15 13 11 11 8 +25 18 15 11 7 +64 64 67 67 70 72 76 +56 59 57 56 53 52 51 51 +56 52 53 51 49 46 49 +20 16 12 10 10 +44 50 53 54 57 58 61 58 +44 42 40 35 36 +84 80 77 73 76 +60 65 69 71 73 75 78 82 +98 93 91 88 86 88 +74 74 74 77 80 81 81 +69 70 67 68 67 67 +44 44 42 39 38 37 33 +86 80 77 74 73 73 +57 56 53 55 61 +16 13 9 7 9 +3 3 4 7 10 12 12 +49 51 52 52 55 56 62 +5 12 14 15 16 17 17 +40 40 42 41 48 +86 89 87 83 79 +66 64 67 64 68 +78 78 79 81 84 88 +84 84 85 86 93 94 97 99 +24 30 34 35 37 37 +83 89 89 92 94 96 94 +33 33 26 25 22 21 +60 59 56 53 50 44 40 +56 63 64 66 63 65 70 +30 37 39 42 43 42 45 49 +35 40 45 46 52 +6 6 6 8 11 16 +74 70 63 62 57 +52 52 54 60 63 66 66 +57 62 62 63 63 +65 64 67 69 69 71 72 +61 61 59 56 54 51 51 +16 22 25 28 28 32 +15 19 23 26 27 29 31 32 +58 58 60 61 62 67 +43 41 43 46 46 51 +42 41 43 45 50 +48 48 50 53 54 56 59 +72 67 68 67 64 62 58 +63 68 71 76 79 81 78 +26 20 17 14 12 9 12 11 +63 59 54 52 50 47 44 +91 91 93 91 92 95 93 +83 79 76 73 67 65 65 +20 23 26 28 31 33 36 +59 60 62 64 66 68 69 +52 55 58 60 63 64 +68 69 71 72 74 76 79 80 +72 73 75 77 80 82 84 85 +14 11 9 6 5 +10 11 13 16 18 20 22 +32 29 28 27 26 25 24 23 +14 15 16 18 21 +45 42 39 36 33 32 30 29 +19 16 15 12 10 9 +92 93 94 96 98 +25 23 20 17 14 +44 46 49 50 51 53 55 +50 47 46 44 42 39 37 +9 11 14 15 18 20 23 24 +22 20 17 15 14 12 10 9 +59 58 55 52 49 48 46 +35 32 31 30 27 +56 58 61 63 65 67 68 +73 72 71 70 69 67 64 62 +86 85 82 81 80 77 74 71 +42 40 38 36 33 30 +63 61 58 57 54 52 +81 80 77 74 71 70 67 +21 24 25 27 29 30 +16 19 22 25 26 +23 25 26 29 32 35 36 +66 67 69 71 73 76 78 +36 34 32 30 28 27 25 +48 46 45 44 41 38 37 +32 35 36 39 40 +11 14 16 19 20 21 22 23 +24 26 27 30 32 33 34 +23 26 27 30 32 34 +44 45 48 50 53 56 +35 38 39 42 44 +29 26 25 23 21 19 +1 2 4 6 9 12 +8 11 13 14 17 +79 77 76 75 72 71 +92 90 87 84 82 81 +83 85 88 89 90 93 +10 13 14 16 18 20 23 25 +49 52 54 55 57 59 60 63 +27 30 32 35 38 40 42 44 +86 85 83 81 79 77 +21 18 16 15 12 10 +86 84 81 78 77 +56 59 60 61 64 67 +16 13 11 8 7 6 5 4 +46 45 42 41 38 36 33 32 +42 39 38 35 33 32 +43 45 46 48 50 52 53 +65 66 68 70 72 75 +57 55 52 51 50 49 47 +42 39 36 33 30 28 +29 30 31 33 35 +96 93 92 89 86 84 81 80 +7 9 10 12 15 +93 92 90 87 86 84 83 +67 65 62 59 57 56 +95 94 91 90 87 85 +33 32 29 28 27 25 +62 61 59 58 55 53 51 +85 83 80 79 77 75 +47 48 50 51 52 54 +15 17 18 19 21 24 27 28 +83 80 78 77 75 +64 62 59 58 55 53 51 +90 88 87 85 83 +70 71 73 75 78 81 82 +80 77 76 74 71 68 66 +16 17 18 20 23 +50 53 54 56 59 60 62 63 +29 32 34 37 40 42 +58 57 56 54 53 52 +42 43 45 46 49 50 51 52 +47 50 53 56 59 61 63 65 +24 25 28 29 32 33 35 36 +31 28 26 23 20 17 14 +74 77 79 81 83 +56 57 60 61 63 66 67 70 +62 65 68 69 70 73 +19 18 16 15 14 +13 12 11 10 8 6 3 +42 45 48 50 52 55 57 59 +29 30 32 34 35 37 38 40 +19 20 21 22 24 27 29 +76 75 73 72 70 67 64 +52 55 56 57 59 61 64 67 +88 90 91 93 96 97 99 +54 51 48 46 44 41 40 +84 85 88 91 93 95 98 +79 76 74 72 70 +27 25 22 21 19 16 +74 75 77 78 80 82 84 +74 75 76 77 80 81 82 83 +30 33 35 36 39 40 +11 13 16 18 20 23 25 +26 29 31 32 33 +79 77 74 73 70 68 67 +2 5 6 7 9 10 +17 19 22 24 27 28 +47 45 44 43 40 +91 88 87 86 85 +49 50 53 54 55 58 60 63 +12 13 14 16 17 +88 90 93 94 97 +89 91 92 94 95 +8 7 6 5 3 +84 86 87 90 92 94 +84 85 86 87 89 +17 16 14 13 11 +37 36 35 34 32 30 29 27 +89 87 84 81 78 76 75 +80 81 84 87 89 92 +64 62 60 58 57 +62 61 59 56 53 51 +35 34 31 28 25 24 23 +76 79 80 82 83 84 86 89 +94 91 90 89 87 85 83 +82 80 78 77 74 73 71 69 +38 36 34 33 32 31 30 28 +55 57 58 60 62 65 68 +55 56 57 59 60 63 +70 69 66 64 62 61 59 +67 68 71 74 77 79 81 +70 68 65 63 61 +19 16 15 14 11 +24 23 22 21 20 18 +52 49 46 43 40 +79 81 83 86 87 88 90 +18 16 15 14 12 9 8 +38 35 33 30 28 26 23 22 +44 41 40 38 37 +81 82 84 85 86 87 89 91 +85 84 81 79 76 75 +50 51 53 54 55 56 57 60 +13 16 18 21 23 24 26 +13 15 16 19 22 +79 77 75 74 72 69 66 64 +23 26 28 29 30 +94 92 90 88 85 83 80 78 +51 49 47 45 44 42 40 37 +35 33 32 29 26 +81 80 79 77 74 71 +88 87 85 83 82 +20 18 16 14 13 12 9 8 +17 16 13 10 9 6 4 2 +50 47 46 43 42 41 39 +71 74 75 76 79 80 +75 76 79 80 83 86 88 +53 56 58 59 60 63 64 +66 64 61 59 56 55 54 +78 79 82 83 86 87 88 +24 27 28 31 33 35 37 40 +13 14 17 18 19 20 21 22 +73 75 76 77 78 81 84 +61 58 56 55 53 52 +14 16 17 18 19 22 24 27 +71 73 76 78 80 81 84 +6 8 9 10 12 14 15 18 +42 39 37 36 35 33 32 +24 22 21 18 15 14 +76 74 73 71 70 68 67 64 +10 9 8 7 6 5 4 2 +4 6 8 10 12 14 15 16 +16 13 12 11 9 8 5 3 +76 78 81 82 85 88 91 +9 11 12 14 16 18 19 21 +57 58 59 61 62 63 65 67 +31 29 28 27 25 22 20 +65 68 71 73 75 76 77 80 +98 96 93 91 88 87 84 81 +48 51 54 57 58 59 +23 22 19 17 15 14 +99 97 95 93 90 89 88 87 +76 74 72 70 69 +53 56 59 61 62 64 65 +61 60 57 56 53 50 47 +21 23 26 29 31 +63 62 61 59 56 54 51 50 +17 18 21 23 25 27 29 30 +81 80 79 77 76 75 74 +49 47 44 43 40 +42 41 39 37 35 +27 29 32 35 36 37 38 41 +62 65 66 69 71 74 76 79 +5 8 10 13 16 +16 13 11 8 5 4 2 +65 67 69 71 73 +77 78 81 83 84 86 +65 66 68 70 71 73 +44 41 40 39 38 37 35 34 +32 31 29 28 25 22 21 20 +29 26 25 22 21 18 +53 55 57 58 60 62 +43 42 39 37 34 32 +9 10 12 14 16 17 20 21 +5 7 9 10 11 +52 50 48 45 42 41 39 38 +74 77 78 81 83 86 88 +69 70 72 73 76 78 81 82 +82 80 78 77 74 71 +55 58 59 60 63 +76 77 78 80 82 +65 63 62 61 59 57 54 52 +62 64 65 68 69 +74 71 70 68 66 64 +75 76 79 82 83 +57 55 53 52 49 48 46 43 +11 12 15 16 19 21 24 +45 48 50 51 54 +89 88 87 85 83 80 78 77 +76 77 79 80 81 +50 47 44 42 41 +66 69 72 73 76 79 81 +72 70 69 68 65 64 61 60 +28 30 31 32 34 36 39 +24 21 20 18 16 +15 14 11 8 7 +64 62 60 57 56 55 53 +90 93 94 95 98 +34 35 37 40 43 +24 22 19 18 17 16 14 13 +40 39 37 35 34 31 28 +55 54 52 51 48 47 +28 30 32 35 37 +10 12 14 15 18 20 +56 58 61 62 65 +83 85 86 88 91 94 97 +74 71 69 66 63 +64 67 69 71 74 +85 83 82 80 77 75 72 69 +12 13 16 19 22 +92 89 87 86 84 +41 44 47 50 52 53 55 57 +28 31 34 37 39 42 44 +47 44 42 40 39 36 +21 18 16 13 10 9 7 +97 94 92 89 88 86 83 +22 23 25 27 30 31 34 +75 72 71 70 67 66 65 63 +54 52 50 49 47 46 43 +48 46 43 40 37 +54 57 58 61 62 64 +72 71 68 66 64 62 60 +17 19 20 21 24 25 28 +53 54 55 57 60 62 64 65 +20 17 16 15 12 11 10 9 +55 58 61 64 65 +29 32 33 35 36 +62 64 65 67 70 +20 22 23 24 25 +76 79 82 83 85 87 +53 55 56 59 61 64 66 69 +4 5 6 8 9 +69 70 72 74 76 77 79 81 +74 76 79 82 83 86 +87 86 85 82 79 77 75 74 +19 21 22 25 26 29 30 31 +52 55 57 58 60 61 62 +73 71 70 68 67 +41 39 37 34 31 29 27 24 +40 39 38 36 34 33 +57 60 61 63 64 67 69 72 +67 68 71 73 76 77 79 81 +78 75 73 71 68 66 +39 37 35 32 31 +13 16 19 20 22 +40 43 44 47 48 51 +72 69 66 63 60 57 +64 65 66 68 70 73 75 76 +21 20 17 15 14 12 +83 82 80 78 77 74 +15 16 18 19 21 24 27 30 +68 66 65 63 61 60 58 55 +67 65 62 60 58 55 52 49 +95 93 91 89 87 86 84 83 +16 15 14 13 12 +36 39 42 45 48 51 +28 30 32 35 36 37 38 +73 74 76 79 80 83 +18 16 13 11 8 5 +97 94 92 91 89 87 86 +80 82 84 87 90 93 95 96 +34 36 38 39 40 43 +60 57 56 54 51 50 48 46 +38 41 43 45 46 48 50 52 +67 66 64 63 61 +51 48 46 43 41 40 39 37 +81 80 78 76 73 70 67 +56 53 51 50 47 +27 29 31 32 34 37 38 +81 79 77 74 71 +17 16 14 12 9 6 4 1 +94 91 90 87 85 +45 47 50 53 55 57 +22 25 27 28 29 30 31 34 +87 86 85 83 82 81 78 76 +23 26 28 30 33 +96 94 92 91 90 87 +23 26 28 30 32 34 37 38 +35 33 30 27 24 21 20 +83 85 86 88 89 91 93 +57 59 62 65 67 +80 79 78 75 74 71 70 +1 3 4 6 8 9 11 14 +83 82 81 78 77 74 72 +95 94 93 91 89 87 85 82 +36 39 42 45 47 50 +53 55 56 59 60 63 65 +84 82 80 78 77 76 +63 61 60 59 56 54 +88 87 86 84 83 +69 72 74 75 78 81 +82 81 78 77 76 75 73 +34 33 30 28 27 25 22 20 +65 68 70 73 76 79 80 81 +81 78 77 74 72 71 +60 58 55 53 51 +66 64 63 62 61 59 57 55 +7 8 11 13 14 15 16 +55 54 53 51 49 48 46 +1 2 3 4 7 8 +52 54 56 58 61 64 +29 30 31 33 36 37 +50 53 54 57 58 61 64 65 +36 35 33 30 29 26 +67 68 69 70 71 +71 73 76 78 81 +91 88 85 83 81 +68 67 66 63 61 +78 79 80 81 83 85 87 89 +90 88 87 84 83 81 +7 9 10 12 15 18 19 +38 36 33 31 29 26 25 +78 76 74 72 71 70 +35 34 32 30 29 28 26 25 +46 43 42 40 37 34 +55 53 51 49 47 44 42 +49 50 52 54 55 56 59 60 +43 41 39 36 35 32 31 +73 74 75 78 79 82 83 85 +36 39 41 43 44 46 49 +28 25 24 21 18 +81 83 84 86 89 90 91 92 +36 38 39 41 42 45 48 49 +73 72 69 67 65 63 +91 90 88 87 85 82 81 80 +42 43 45 47 49 51 +88 86 83 80 79 77 +59 56 54 52 49 47 +78 80 83 84 87 90 +49 52 54 56 59 62 64 66 +57 58 61 63 65 68 70 71 +31 34 35 37 40 42 43 +43 41 39 38 36 34 31 29 +25 28 31 32 34 +50 49 48 45 44 41 39 37 +48 50 52 54 55 57 +49 52 55 56 58 +21 24 27 29 32 34 +19 21 22 23 26 +71 74 77 78 80 81 82 +67 69 70 71 73 74 77 79 +95 92 89 87 85 84 81 78 +22 25 27 29 31 33 36 38 +70 72 74 76 79 +79 77 75 74 71 +34 31 28 25 22 20 17 16 +1 4 7 8 10 12 14 17 +14 16 18 19 20 22 23 25 +29 28 27 26 24 +66 65 63 60 58 55 +66 65 64 63 60 57 56 +38 40 43 46 47 +32 29 28 25 22 21 +55 57 60 62 65 68 69 +58 59 62 64 66 69 71 74 +32 30 27 26 23 21 18 15 +58 55 52 49 46 43 +89 91 93 94 96 +21 23 24 27 30 +30 29 26 23 22 21 20 +64 62 59 58 56 55 54 +32 31 28 27 25 24 23 21 +47 49 52 55 57 59 61 63 +73 75 77 78 80 82 83 diff --git a/2024/03/code.py b/2024/03/code.py new file mode 100644 index 0000000..df92369 --- /dev/null +++ b/2024/03/code.py @@ -0,0 +1,20 @@ +import re +from pathlib import Path + +filepath = Path("./data/3_example") +filepath = Path("./data/3_input") + +with open(filepath) as filein: + data = filein.read() + +regex_mults = re.compile("mul\((\d{1,3},\d{1,3})\)") +pairs = [[int(i) for i in pair.split(',')] for pair in regex_mults.findall(data)] +print(sum([x*y for x,y in pairs])) + +regex_dos = re.compile("do\(\)(\S*?)don't\(\)") + +dont_data = ("do()"+data).split("don't") +do_data = "".join([s[s.find('do()'):] for s in dont_data]) +pairs = [[int(i) for i in pair.split(',')] for pair in regex_mults.findall(do_data)] + +print(sum([x*y for x,y in pairs])) diff --git a/2024/03/example b/2024/03/example new file mode 100644 index 0000000..1f4eda2 --- /dev/null +++ b/2024/03/example @@ -0,0 +1,10 @@ +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX diff --git a/2024/03/info.txt b/2024/03/info.txt new file mode 100644 index 0000000..a62c3d3 --- /dev/null +++ b/2024/03/info.txt @@ -0,0 +1,40 @@ +--- Day 3: Mull It Over --- + +"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. + +The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?" + +The computer appears to be trying to run a program, but its memory (your puzzle input) is corrupted. All of the instructions have been jumbled up! + +It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y), where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 by 46 to get a result of 2024. Similarly, mul(123,4) would multiply 123 by 4. + +However, because the program's memory has been corrupted, there are also many invalid characters that should be ignored, even if they look like part of a mul instruction. Sequences like mul(4*, mul(6,9!, ?(12,34), or mul ( 2 , 4 ) do nothing. + +For example, consider the following section of corrupted memory: + +xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) + +Only the four highlighted sections are real mul instructions. Adding up the result of each instruction produces 161 (2*4 + 5*5 + 11*8 + 8*5). + +Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications? + +--- Part Two --- + +As you scan through the corrupted memory, you notice that some of the conditional statements are also still intact. If you handle some of the uncorrupted conditional statements in the program, you might be able to get an even more accurate result. + +There are two new instructions you'll need to handle: + + The do() instruction enables future mul instructions. + The don't() instruction disables future mul instructions. + +Only the most recent do() or don't() instruction applies. At the beginning of the program, mul instructions are enabled. + +For example: + +xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) + +This corrupted memory is similar to the example from before, but this time the mul(5,5) and mul(11,8) instructions are disabled because there is a don't() instruction before them. The other mul instructions function normally, including the one at the end that gets re-enabled by a do() instruction. + +This time, the sum of the results is 48 (2*4 + 8*5). + +Handle the new instructions; what do you get if you add up all of the results of just the enabled multiplications? diff --git a/2024/03/input b/2024/03/input new file mode 100644 index 0000000..330b7fc --- /dev/null +++ b/2024/03/input @@ -0,0 +1,6 @@ +}mul(620,236)where()*@}!&[mul(589,126)]&^]mul(260,42)when() when()$ ?{/^*mul(335,250)>,@!<{when()+-$don't()*'^?+>>/%:mul(422,738),mul(694,717);~;%<[why()>@-mul(417,219)?&who(474,989){select()-{#mul(366,638)mul(773,126)/*{mul(757,799)]when()mul(778,467)^mul(487,365)]*'{where(952,954){?who()who()when()mul(172,666)#?$,-mul(250,228)(]when()}mul(760,139)mul(892,161)!'@[%when()<(mul(775,872)+~#)//$select()mul(946,63)how()??select()?from(277,915)~'mul(637,565)~mul(881,294)who()what()}mul(995,866)?mul(952,57)who()mul(387,599)mul(46,724)who()[how()select()mul(992,19)'~mul(909,687)where()mul(953,804)from()/;where(474,270)from()}mul(907,410)&(&what()%{mul(192,898)who()-,mul(196,400)#--{%]how()mul(144,141)~@[when()!%:[mul(377,942)^*mul(89,46)who()<}when()?!'%mul(172,448){]@mul(351,18)~]&!$mul(490,127)/]] }}mul(851,465)when()*-why()what()))@+^<-select()do()%#+;%:mul(549,307)#mul(968,958)mul(125,903)what()who()$where()%who()how()mul(139,859)<&/+how()mul(339,100)@(:mul(306,909)?)--what()who()/)*mul(724,497)'how()from()mul(489,24)${/%/:how()>(mul(397,282)}?from()who()$/'mul(86,511)mul(463,903);(^@mul(302,904)-,who()what()from(892,368)where()-mul(707,359)/who()/';;++;mul(687,987)^:select()select():mul(915,123)<]!:'/[select()mul(809,835)why()when())* mul(139,828))why()who() ,mul(807,713)where()>:mul(350,287)where()-where()+:~{who() mul(437,102) %when()select(),mul(813,883)]when()>(from()don't()]where()@/:how())'#mul(337,905)*>>*!don't()>(+}:mul(488,283)<~>mul(703,476),what()@(} mul(487,921)from()select()why()mul(761,203)who()how()mul(32,930)[how()do())/}where()mul(778,306))mul(593,810)mul(629,319)';$mul(122,109){ ^^-mul(720,536)?!+mul(519,541)$'/@who()!~where()$mul(461,98) +$[mul(647,228)^why()how()>why()^{mul:from()%who()/$%}%mul(810,82)]^+[mul(377,189)){&select()/(select()$$mul(343,443)who():-don't()}how()'how()]:select()why(){mul(963,385)/^why()who()^mul(131,676)mul(113,570)~';*mul(853,789)${>%{:](*$mul(736,139)??%^where()what()~]mul(447,113)don't()(^;select(921,651)<[#why()mul(912,658)/{&from()where()-what()why()who()mul(587,480)]!how()]from()mul(389,102)'@mul(200,564)>#/,#;mul(24,400){):,!+;];mul(595,551)!who()how()]$select()mul(969,989)/?%mul(899,264)@what(507,249)&mul]~*mul(354,715)>,mul(914,563)>'};~!select()don't()&{mul(50,819)select()@>:+ when(501,666)!mul(970,506)who()mul? }~[when()%mul(358,287)!mul(291,276):#what()::mul(946,666)'??;+'/>'mul(31,79)~#*}#-}/where(532,773)mul(919,720)where()@^@]&#how(){^;mul(561,111)^&^? select()[why(803,159)(*mul(716,153)};{]how()[#+',mul(883?:from()why()what()?%]!why(393,804)~mul(231,805)how()when()why()@select()mul(552,136)$;[!where(454,987)who()what()mul(555,591)mulfrom()?from()^select()mul(467,281)mul(702,811)}}{;don't()[mul(543,7)from(608,658)&^?mul(144,343)from()who()-?&don't()mul(860,384)where(611,825)%&+,^{where()@select()%}%what()}do()/who())}where(740,982)#-why():,mul(523,265)+select()[):]when():mul(200,994)}when(436,935)<%;)&!mul(156,920)when()mul(822,281)~>mul(3,591)when()*select()$mul(993,139)where()(!$why():%+from()mul(167,958),;select(579,937)from()?{?from(644,816)mul(675,905)why()mul(787,123)%mul(982,476)~mul(613,499)#;)'mulhow(280,254)mul(393,812)#mul(54,319)(;what()%/@(mul(23,133)mul(401,60)who()$mul(615,621)]@what()$mul(77,795)from()+{!+!;mul(935,990)select()+!>mul(843,623)what()]$,/#)/mul(374,785)@ /don't()how()%select() -how()#who()*^mul(113,822)from()%what()/from()mul(305,505)what())<&~from()mul(841,37)when()#(select()& /mul(879,852)]from()/mul(485,947)?where(276,795)mul(197,752)?;mul(926,356) mul(701,87)who(66,480))~who(514,148)@!mul(533,170)%!+mul(983,219)!&$]@ @ *mul(409,813)/)^>@{/why()?mul(411,364@$$:mul(367,910)??what()+~ > -mul(475,252)from()]/])%select()~mul(726,104)when()&&'/mul(463,124)where()how()(!how()[(~[%-&mul(487,73)]]/mul(818,611)~where()&what(){$'mul(669,330)}(mul(14,255)'(why()don't()%$mul(748,857)+)<:don't()<]-'[mul(205,925),/ select(),mul(611,78))%where()+why()what()])$^mul(922,30where(), :do(),why(),what()$when(){when()%%mul(788,912){&!*what()what()#from(550,915)mul(414,182)!how()who() select():~^where()mul(361,64);,when()$?why()<(why()mul[}when()/&?mul(404,92)}from()!(where()why()mul(162,794)mul(156,595)&&what()/#~'<@;mul(619,461)}who();what()$%who()>'mul(84,893)*how()!>* ;:[~mul(904,58)when()>~mul(397,193)&/<]{<(;^how()mul(835,565)select()][?mul(179,388)from()*mul(590,514^~-[mul(141,691)[!how()from()do()select()mul(662,493)who()mul(852,288)what(289,959)from()&%){mul(388,80)<;)mul(129?$>:;![mul(838,473)%'-~mul(521,965)!mul(301,798){when()/ '&how()from()>mul(412,607)~~;~>who(759,414)mul(505,681)]why()&>mul(11,690):]@&where()where()!}how(){don't()^what())mul(896,34)(]when()+]%from(676,897)mul(352,130)}select():(how(962,114)$-why()how()}mul(346,43)where()select()}why()don't()< mul(253,930),how()+? mul(980,251)from():where()}[,mul(824~where(837,118)-select()/mul(389,969)& )!from()from()where() mul(477,689)#select()!^how()mul(270,320)$@&,-from()mul(505,37)what()!who()+?,don't()from(644,533)@&mul(946,497)why()where()+select()%$@mul(985,698) :[@/do()mul(634,683)from()[<&mul(471,76),)from()(mul(765,236)where()[}mul(103,839))')where()+],(mul(415,82)?]how()[/mul(545,345);~(mul(717,102)from()@>mul(873,432~[[!{mul(407,39)>{~%where()*mul(66,512)mul(408,714]who()when()don't()why()@@'{/:mul(823,809)what():]mul(501,427)mul(667,732)from()^from()@;mul(84,235)?}%from() : #mul(788,725)mul(140%>}[where():)when()mul(693,122)'(?+]!!mul(644,111)!+*-~where()select()+*mul(366,69)*]when()&^({)--mul(931,970)%~from())]{<@@mul(983,532)]&^]+who()!&$mul(558,679)(@who()where();^mul(140,309)how()^don't()'who()>('*mul(83,388)mul(421,988)@::what()mul(385,22),)%:}who())/mul(754,201)~{when()mul(606,345)-[?]mul(762'from()from()mul(502,876)select()@,<{@]mul(595,401)**select()$mul(669,55)~~+(,#!/usr/bin/perl&(mul(621,865)[select() -+select()how())mul(852,28<>-what()'mul(808,223) +>#@,mul(49,51)+'+ {what()mul(459,620)mul(676,939)mul(785,481)[%,how()->#when()mul(941,842)?when()who()mul(626;don't() ##mul(369,396)why()why()mul(18,620)mul(660,703)~$don't()from(891,902)mul(624,59!!+mul(881,448):;mul(103,918),>}why(295,520)?mul(975,493)~where()/mul(500,773);&/what()$);%>mul(574,896){when()& -{why()!mul(767,832)%^^?mul(176,339)^$?? {?>mul]+/who()<}~why()select()when()mul(585,105)mul(326,283) @select()mul(881,190)@(,[@$[-!:mul(978]how()mul(244,274)(why()mul(107,435)~'@}how()who(),mul(514,868)select()how():;/mul(371,314)how(683,764)#%~;where()}why(),mul(630,194)+,-(how()mul(556,839)!@]:how(904,253)/+)mul(949,374)'>>~@what(702,586)how()mul(93,979)^(who()})${mul(500,125) mul(554,209))[where():/where()mul(489,287)#when(),&',mul(857mul(735,380)*!<&{^mul(908,597)?]what()who()mul(830,216)~'mul(131,112)mul(214,624);>[ why(727,278)from()(*mul(277,717,{how()mul(491,389)<'mul(308,352)*#mul(473,610)(#;#mul(96,433)-what()how(893,680)where()]*>mul(15,226)*}do() &/;[&<]mul(570,554)(:mul(162,708)where():+{^when()who(195,632)from(512,233)(mul(735,501);mul(47,211)}^$how()~do()#+@from()mul(403,568)~who())what()from(519,688)mul(479,938)why()')?['mul(912(&~(don't()%why()%why()]>mul(901,522)mul(236,396)-,who()what()where()%#:when(738,307)mul(638,827)%! what()%^when()-don't():mul(69,715);^who()select()~who()+what()mul(483,819))^/mul(692,711)<>?,,who()'mul,mul(45,587)why()}'select()/[how()-what() mul(623,228)-?'>mul(738,552)%>!/when()?[why() mul(364,106)'when()^who(382,157)who()&>mul(417,796))where()(mul(792,820)[from()(*/*where()%mul(504,794)mul(342,18)@'how()mul(929,33)how()}mul(336,88)'+;where()}mul(114,443)why();when()[@!'when()mul(66,853)]select();(&$&why() *mul(255,88)#*when()^mul(118,466)when()/!')%from()mul(396,750)$when():)-select()~mul(711,817)who()~ ,]select()**how()mul(531,995)from()mul(816,42)mul(801,817)'?:;'~mul(830,904)%[/why()who()-mul(296,626)/^~*where()+(+from()mul(311,114)mul(266,973)~^)$--,:mul(372,293)!+,what()mul(376,438)$/]}~,@>{mul(324,122)mul(207,152)'mul(568,638)!>[,>+/>>mul(514,968)why()why(8,771)who()~ #>/?mul(190,876)!mul(70,561)who()how()>mul(265[/where() from()$why()#^mul(101,15);$^from()-!mul(570,448)/?(]who()/how()$-{mul(621,492)@?don't()who()}>*#mul(659,911))how()what():)<(do()from()-)%mul(134,954)select()mul(572,608)why()-)$+mul(392,779) +;who()~mul(268,986)#/from()],}mul(632,679) when()select() -& select()~mul(707,831),^~*from()how(),[mul(210,504)why()select()@)who()mul(188,858)$#;select()mul(828,586)&#where()@mul(48,75)$#+!])what()$mul(899,170)#$ from()mul(786{?#{~%@:mul(96,375)[mul(958,29)what()&where(203,927)>*#)select()-*mul(519,379)why()]mul(750,986)%+;#when()[$<[mul(144,674)*^who()mul(523,649)#-mul(48,556)!@~)/@->mul(170,217)mul(628,552)how()};mul(433,161)when()-,/%'what(891,571)mul(797,743)from()</^-mul(412,25)when()<)??}:*mul(409,767)how()!<}[)select()!,,mul(978,831)why(5,443);[{-mul?from()>@where()>mul(596,740){#mul(853,990)+:when()#/{mul(418,161)[:why()$/}mul(728,815)*mul(448,232)#+why()/~select()mul(798,812)what():(mul(305,330)where()<>do()# mul(485,702)$@what())mul(33,730)^mul(250,103)>[/}from()who())}why()/mul(580,640)~mul(39,871)/)@how():where()what())~mul(66,708)select()where())!)when()+:'mul(886,576)from()(when()]mul(664,110)^why()($ from()+(@mul(301~select()}:mul(198,8)^![mul(558,124)mul(271,988);<<[//-&mul(79,763)+ 'mul(389,9)(select();-;when()mul(678,773)+,(}{-when()#@mul(522,262)]don't()what()[<%where(412,191)*:(mul(522,99)#>+*where()'mulfrom()*}who()how())who()&when()mul(809,282)(&how()?mul(389,999)#what())$why() select()mul(646,75)@mul(864,690)}mul(951,939)from()%where()mul(957,667)? >/]mul(22,31)?,mul+mul(970,622)^^{ *-^%mul(166,954)when(){#from(178,855)]mul(697,375)<:*@why()-&why()mul(745,382)$>how()@^%why();who()what()mul(501,986)why(782,397)[?( mul(491,604),(mul/,@*##]++where()<}mul(678,467);-+how()/do()/)?$what()mul(483,452,+[~mul(179,979)+}($>(#!*)mul(143,707){mul(732,344)mul(743,974)#mul(580,824)why()what()!when()when()&who())how()mul(10,399)}*)when()&~what(375,175)#mul(540,576)select(156,142)<*(&);%*from();~mul(377,827)what()@^mul(2,573)what(891,305)+(~mul(192,965)#mul(411,367),+mul(181,566)why()how()select()?]~^)-mul(571,574),who()&[ @select()mul(721,269); ->why()#mul(641,715)why()mul(38,177) *]<$why(65,872)!mul(251,717)<{mul(490,192)mul(334,149)mul(921,662)(+~mul(767,331)](^$>?'do())&(@#mul(873,278)!when()how()$what()mul#^how(511,214)]]mul(726,818) +(~from()mul(961,791)$)^>]+~mul(320,807)mulfrom()^+<;>,mul(425,375)where()/^$from()what()}?mul(310,951)when()why(38,420){(?from(84,74)[&select()mul(18]when();[when()from()how()select();@]mul(434,652)%>select()]-?mul(984,804)*mul(363,658)*/ &from()?how();^how()mul(909,440)+!*)&<*@{where()mul(237when()'&mul(624,801)? [!mul(473,118)mul(421,299)when()select()mul(358,981)mul(179,656)@#{:from()^$]$)do();how()+$where()%#from()(&!)^mul(446,656)-:$from()why()}@;when()*mul(831,757):who()! %%? do()mul(554,594)@when()who()how()>'>#mul(992,883)from()[(how()what()'mul(684,266)from()where()$?{'mul(656,521how()-);}~mul(413,681)^how(){!*{-mul(605,813/&who()/mul(208,330)&select()%[~how()[mul[@;+mul(291,832)[mul(954,916)-<, }(mul(360,461)??+?'select()select()mul(176,724)--:%mul(529,706)<'who(807,145)( '^~:mul(394,403)>mul(461,505)/])#+'-mul(555,534)who()what()^ ]*mul(972,671)+ *who(){mul(7,361),}}when()/[mul(519,583)?*who()+do()@where()where()* how(),#how()mul(907,286)>/@why(929,601)'&,@mul(174,628)<^from()mul(400,722)-/~&mul(705,103)&from() (~}mul(821,931)select()$^+what()'^do()/ mul(741,976)who();@,how()mul(11,473)/who(97,948)<:when():!;'mul(486,596)~%why() mul(972,412)&;mul(915,634)),<~>*[^%mul(810,448)+-mul(696,812))-{{mul(141,61)where(806,736)>!;mul(969,802))how()why()?[:mul(269,857)when()select()who()>#@:what() where()mul(722,901)+'from()]mul(284,470)select()when()$why(){~why()!what()don't(),why();<(select()mul(17,245)][?/when()&;mul(582,931)select(604,965){+do()]$select()mul(388,976)' :#mul(368,451)+mul(191,133)$'mul(121,338)#:where()who()#$/mul(477,95)(mul(868,121)?where()/^';,*:mul(241,456)(mul(565,994)&mul(435,842)<,~/+{mul(866,963)'+;when()where()[mul(649,460) when()(!mul(306,571)who()when()(select()mul(946,26)&)~/}mul(681,34)!from()%#'what()$$mul(71,890)^:select()/where()mul(974,246)mul(198,364))what()mul(256,64)from(650,475),!-+%*+/where(126,215)mul(267,232)where()@$-*^ mul(357,369)select()(&{:&^mul(488,801)select())?don't()]#+{}*#?;mul(584,742)&>]where()?where()'mul(939,130)mul(802,6)(what()+what(567,791)*&-#!(mul(738,680)where()^{^):&%%mul(203,350)]{;mul(14,735){from(527,639)/-+mul(234,797)!mul(416,25) ,>]from()&from()];mul(495,316),where()~!)%*who()mul(666,581)?^[!*what()mul(386,330)who()~$what()- diff --git a/2024/04/code.py b/2024/04/code.py new file mode 100644 index 0000000..190ab31 --- /dev/null +++ b/2024/04/code.py @@ -0,0 +1,94 @@ +import numpy as np +from pathlib import Path + +filepath = Path("./data/4_example") +filepath = Path("./data/4_input") + +directions = np.array([ + [[0,0], [1,0], [2,0], [3,0]], + [[0,0], [-1,0], [-2,0], [-3,0]], + [[0,0], [0,1], [0,2], [0,3]], + [[0,0], [0,-1], [0,-2], [0,-3]], + [[0,0], [1,1], [2,2], [3,3]], + [[0,0], [-1,1], [-2,2], [-3,3]], + [[0,0], [1,-1], [2,-2], [3,-3]], + [[0,0], [-1,-1], [-2,-2], [-3,-3]], +]) + +with open(filepath) as filein: + data = [line.rstrip() for line in filein.readlines()] + +def find_xmas(arr, i,j): + count = 0 + for d in directions: + x,m,a,s = "0000" + try: + assert np.all([i,j] + d >= 0) + x = arr[i][j] + m = arr[i+d[1,0]][j+d[1,1]] + a = arr[i+d[2,0]][j+d[2,1]] + s = arr[i+d[3,0]][j+d[3,1]] + if x+m+a+s == "XMAS": + count += 1 + except IndexError: + pass + except AssertionError: + pass + return count + +global_count = 0 +for i in range(len(data)): + for j in range(len(data[0])): + if data[i][j] == 'X': + count = find_xmas(data, i, j) + global_count += count + # print(count if count else '.', end="") + # else: + # print(".", end="") + # print('') + +print(global_count) + + +data = np.array([[c for c in line] for line in data]) + +directions = np.array([ + [[-1,-1],[0,0],[1,1]], + [[1,1],[0,0],[-1,-1]], + [[-1,1],[0,0],[1,-1]], + [[1,-1],[0,0],[-1,1]], +]) + +def find_x_mas(arr, i,j): + count = 0 + for dir in directions: + try: + d = dir + [i,j] + assert np.all(d >= 0) + m = arr[d[0,0],d[0,1]] + a = arr[d[1,0],d[1,1]] + s = arr[d[2,0],d[2,1]] + if m+a+s == "MAS": + count += 1 + except IndexError: + pass + except AssertionError: + pass + if count == 2: + return True + else: + return 0 + +global_count = 0 +n,m = data.shape +for i in range(n): + for j in range(m): + if data[i][j] == 'A': + count = find_x_mas(data, i, j) + global_count += count + # print(count if count else '.', end="") + # else: + # print(".", end="") + # print('') + +print(global_count) diff --git a/2024/04/example b/2024/04/example new file mode 100644 index 0000000..1f4eda2 --- /dev/null +++ b/2024/04/example @@ -0,0 +1,10 @@ +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX diff --git a/2024/04/info.txt b/2024/04/info.txt new file mode 100644 index 0000000..7249fe4 --- /dev/null +++ b/2024/04/info.txt @@ -0,0 +1,70 @@ +--- Day 4: Ceres Search --- + +"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! + +As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; she'd like to know if you could help her with her word search (your puzzle input). She only has to find one word: XMAS. + +This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. It's a little unusual, though, as you don't merely need to find one instance of XMAS - you need to find all of them. Here are a few ways XMAS might appear, where irrelevant characters have been replaced with .: + +..X... +.SAMX. +.A..A. +XMAS.S +.X.... + +The actual word search will be full of letters instead. For example: + +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX + +In this word search, XMAS occurs a total of 18 times; here's the same word search again, but where letters not involved in any XMAS have been replaced with .: + +....XXMAS. +.SAMXMS... +...S..A... +..A.A.MS.X +XMASAMX.MM +X.....XA.A +S.S.S.S.SS +.A.A.A.A.A +..M.M.M.MM +.X.X.XMASX + +Take a look at the little Elf's word search. How many times does XMAS appear? + +--- Part Two --- + +The Elf looks quizzically at you. Did you misunderstand the assignment? + +Looking for the instructions, you flip over the word search to find that this isn't actually an XMAS puzzle; it's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this: + +M.S +.A. +M.S + +Irrelevant characters have again been replaced with . in the above diagram. Within the X, each MAS can be written forwards or backwards. + +Here's the same example from before, but this time all of the X-MASes have been kept instead: + +.M.S...... +..A..MSMS. +.M.S.MAA.. +..A.ASMSM. +.M.S.M.... +.......... +S.S.S.S.S. +.A.A.A.A.. +M.M.M.M.M. +.......... + +In this example, an X-MAS appears 9 times. + +Flip the word search from the instructions back over to the word search side and try again. How many times does an X-MAS appear? diff --git a/2024/04/input b/2024/04/input new file mode 100644 index 0000000..7a3f85f --- /dev/null +++ b/2024/04/input @@ -0,0 +1,140 @@ +XMXMAXXSXSSMMMXAMXMMMAMXMAMXAMSAMXSAMXMXMMMAXXMASMSMSAMXMSMMMAMXMXAMMAMMMXMAMMMMMAMMMMSAMXMMAMXAXMXMAMXSXSMMSMMMMSMMXXAMSMSASAXMMMSMMMSMASMM +MSMSMSMXMMAASAMXMASMMXSSMSSMSMMXXSAMXMXMXMSMMXMMMAAXXAAAMXSSSMAAXSXSMSASXMMSMMAAMAMXMASMSASASXMASMMSMSAMMASXAXAASAAMAMSXMAXAMAMSAXAAMASMAMAM +MAAAAXXAAXXMMMSASASASAAAAAAAAAXSMSAMMMAMAMAAMMMAMMMMMSSXSAMXAMMMMAXSAXAXMMAAASXMMASMMMSXSASAXMSAAXAMAMAXSAMMSMSSSMSMMAAAMMMMMAMMASMSMAXMASAM +XMSMSMSASXMAAAMMMAMAMMSMMMMXMSMAASXMASASXMSMMAMXXAMXAMXMMAXSMMMSAMXMAMSMAMSSMMAMSMSASAMAMAMAMAMSAMXMAMXMMASAMXMAXXXAXXSSMXASXXXSAMXXMAXSMXAS +MMAMXXXAAAMMMSSSMMMXMAXXSXXXSAAMMMXMXSAXMAXASMSMXAMXSSXMSSMXXSXMAXSMXMAMSMAMAMMMAXSMMAMAMAMMMSMMXXASASXXSAMMSMMAMXSXMAMAXXXSXMXAAXXXSAMSMS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AASMSX +SXXSXSSMMAASASMMMSAMAMAMASASAXXAMAMAMSSSMMMSMSAMASXAAMAMXSXSAMAMAXXSASXSASMSXSSMASAMMMAMMXSSSMAMMMMXASMSMMXAXXAXXXAAMMMASAMXAMAAXAXMSSSXSSXM +MAXSAMXXMSAMXSASMMAMXMXMASAMASMMMAMSMMAXMAAAAMAXAMMMSSXMXAAAMMSSXMASXSXMAMXMMMAMAMASASMMSMAAXMAXAXXMMSAAXSMMMSMSMMSXXASXSMSSMSSXXMMMAAXMXMXA +MMMXAMXXAMASXSAMXSSMAMXMAMAMAXAASAXMAMXMSMSSSSSMXSAXMAXSAMXMMAMXMAXMAMXMMSMMASAMXSAMXSAAAMMMMSMSSSMAMMMMXMASAMASAMMMSMSAXMAXMAMAMMAMMSMMSMMM +AAASXMASXSMMAMMMXAXMASAMASAMXSSMSMXSAMMAXAAAAAAAASAXSAXMAXXSMXSAMSAXAXXSAMASMSXSAMXSAMXSXSMXXXXAAAXSMXXXASMMSAASMMAAAAMMMMASMAMAXSAXSAASAAAX +SXXAMMAXMAMMXMXMASASMSASMSXSAMAMXAMSAMXSSMASMSMMMXSAMXSSMMAXSXSASXMSAMXXMMMAMXXMXXSAMXMMMXXMASMMSMMMMSAMXSMAXMASXSMSSSMXXAMMXASMXAMXSASXSSMS diff --git a/2024/05/code.py b/2024/05/code.py new file mode 100644 index 0000000..7f1f6ad --- /dev/null +++ b/2024/05/code.py @@ -0,0 +1,53 @@ +from pathlib import Path + +filepath = Path("./data/5_example") +filepath = Path("./data/5_input") + +with open(filepath) as filein: + rules_l = [] + while True: + dataline = filein.readline().rstrip() + if dataline == '': + break + else: + rules_l.append([int(i) for i in dataline.split('|')]) + data_rest = filein.readlines() + +rules = {(a,b) for a,b in rules_l} + +instructions = [[int(i) for i in line.rstrip().split(',')] for line in data_rest] +erroneous = [] +sum = 0 +for instruction in instructions: + for i in range(len(instruction)-1): + pages = tuple(instruction[i:i+2]) + if pages not in rules: + erroneous.append(instruction) + break + else: + center = len(instruction)//2 + sum += instruction[center] + +print(sum) + +sum = 0 +def multiple_goes(l: list): + result = [] + for i in range(len(l)): + safe = True + for i in range(len(l)-1): + pages = tuple(l[i:i+2]) + if pages not in rules: + safe = False + l[i:i+2] = pages[::-1] + if safe: + break + return l + +for instruction in erroneous: + multiple_goes(instruction) + # print(instruction) + center = len(instruction)//2 + sum += instruction[center] + +print(sum) diff --git a/2024/05/example b/2024/05/example new file mode 100644 index 0000000..9d146d6 --- /dev/null +++ b/2024/05/example @@ -0,0 +1,28 @@ +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 diff --git a/2024/05/info.txt b/2024/05/info.txt new file mode 100644 index 0000000..d28d31a --- /dev/null +++ b/2024/05/info.txt @@ -0,0 +1,92 @@ +--- Day 5: Print Queue --- + +Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. + +The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically significant facility, an Elf operating a very familiar printer beckons you over. + +The Elf must recognize you, because they waste no time explaining that the new sleigh launch safety manual updates won't print correctly. Failure to update the safety manuals would be dire indeed, so you offer your services. + +Safety protocols clearly indicate that new pages for the safety manuals must be printed in a very specific order. The notation X|Y means that if both page number X and page number Y are to be produced as part of an update, page number X must be printed at some point before page number Y. + +The Elf has for you both the page ordering rules and the pages to produce in each update (your puzzle input), but can't figure out whether each update has the pages in the right order. + +For example: + +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 + +The first section specifies the page ordering rules, one per line. The first rule, 47|53, means that if an update includes both page number 47 and page number 53, then page number 47 must be printed at some point before page number 53. (47 doesn't necessarily need to be immediately before 53; other pages are allowed to be between them.) + +The second section specifies the page numbers of each update. Because most safety manuals are different, the pages needed in the updates are different too. The first update, 75,47,61,53,29, means that the update consists of page numbers 75, 47, 61, 53, and 29. + +To get the printers going as soon as possible, start by identifying which updates are already in the right order. + +In the above example, the first update (75,47,61,53,29) is in the right order: + + 75 is correctly first because there are rules that put each other page after it: 75|47, 75|61, 75|53, and 75|29. + 47 is correctly second because 75 must be before it (75|47) and every other page must be after it according to 47|61, 47|53, and 47|29. + 61 is correctly in the middle because 75 and 47 are before it (75|61 and 47|61) and 53 and 29 are after it (61|53 and 61|29). + 53 is correctly fourth because it is before page number 29 (53|29). + 29 is the only page left and so is correctly last. + +Because the first update does not include some page numbers, the ordering rules involving those missing page numbers are ignored. + +The second and third updates are also in the correct order according to the rules. Like the first update, they also do not include every page number, and so only some of the ordering rules apply - within each update, the ordering rules that involve missing page numbers are not used. + +The fourth update, 75,97,47,61,53, is not in the correct order: it would print 75 before 97, which violates the rule 97|75. + +The fifth update, 61,13,29, is also not in the correct order, since it breaks the rule 29|13. + +The last update, 97,13,75,29,47, is not in the correct order due to breaking several rules. + +For some reason, the Elves also need to know the middle page number of each update being printed. Because you are currently only printing the correctly-ordered updates, you will need to find the middle page number of each correctly-ordered update. In the above example, the correctly-ordered updates are: + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 + +These have middle page numbers of 61, 53, and 29 respectively. Adding these page numbers together gives 143. + +Of course, you'll need to be careful: the actual list of page ordering rules is bigger and more complicated than the above example. + +Determine which updates are already in the correct order. What do you get if you add up the middle page number from those correctly-ordered updates? + +--- Part Two --- + +While the Elves get to work printing the correctly-ordered updates, you have a little time to fix the rest of them. + +For each of the incorrectly-ordered updates, use the page ordering rules to put the page numbers in the right order. For the above example, here are the three incorrectly-ordered updates and their correct orderings: + + 75,97,47,61,53 becomes 97,75,47,61,53. + 61,13,29 becomes 61,29,13. + 97,13,75,29,47 becomes 97,75,47,29,13. + +After taking only the incorrectly-ordered updates and ordering them correctly, their middle page numbers are 47, 29, and 47. Adding these together produces 123. + +Find the updates which are not in the correct order. What do you get if you add up the middle page numbers after correctly ordering just those updates? diff --git a/2024/05/input b/2024/05/input new file mode 100644 index 0000000..b804f99 --- /dev/null +++ b/2024/05/input @@ -0,0 +1,1371 @@ +84|39 +48|11 +48|79 +88|98 +88|82 +88|12 +69|67 +69|77 +69|22 +69|61 +41|75 +41|56 +41|59 +41|95 +41|83 +24|97 +24|98 +24|54 +24|48 +24|47 +24|16 +33|59 +33|92 +33|47 +33|16 +33|82 +33|88 +33|78 +92|82 +92|59 +92|88 +92|78 +92|97 +92|63 +92|56 +92|74 +11|35 +11|39 +11|27 +11|75 +11|47 +11|24 +11|77 +11|79 +11|43 +36|44 +36|33 +36|46 +36|26 +36|83 +36|35 +36|96 +36|39 +36|72 +36|76 +59|55 +59|78 +59|84 +59|36 +59|69 +59|61 +59|97 +59|17 +59|12 +59|67 +59|76 +98|55 +98|66 +98|32 +98|97 +98|61 +98|67 +98|63 +98|26 +98|46 +98|84 +98|22 +98|45 +72|54 +72|48 +72|45 +72|31 +72|12 +72|99 +72|87 +72|75 +72|88 +72|63 +72|78 +72|69 +72|59 +35|87 +35|83 +35|59 +35|75 +35|82 +35|88 +35|99 +35|98 +35|45 +35|47 +35|74 +35|69 +35|97 +35|56 +43|59 +43|33 +43|75 +43|72 +43|54 +43|31 +43|95 +43|24 +43|83 +43|39 +43|16 +43|47 +43|92 +43|44 +43|32 +17|43 +17|26 +17|75 +17|41 +17|79 +17|72 +17|83 +17|39 +17|22 +17|95 +17|46 +17|32 +17|92 +17|47 +17|27 +17|24 +31|16 +31|78 +31|67 +31|22 +31|12 +31|45 +31|17 +31|55 +31|11 +31|82 +31|99 +31|98 +31|63 +31|79 +31|97 +31|56 +31|61 +85|56 +85|36 +85|66 +85|22 +85|48 +85|98 +85|76 +85|43 +85|96 +85|61 +85|67 +85|55 +85|82 +85|84 +85|69 +85|11 +85|17 +85|78 +75|16 +75|63 +75|99 +75|59 +75|97 +75|55 +75|54 +75|82 +75|74 +75|96 +75|88 +75|98 +75|12 +75|36 +75|69 +75|85 +75|45 +75|31 +75|61 +46|75 +46|24 +46|72 +46|77 +46|83 +46|59 +46|88 +46|32 +46|16 +46|39 +46|44 +46|74 +46|31 +46|99 +46|54 +46|87 +46|47 +46|27 +46|35 +46|95 +39|88 +39|78 +39|85 +39|59 +39|83 +39|47 +39|82 +39|92 +39|97 +39|48 +39|72 +39|75 +39|63 +39|45 +39|56 +39|16 +39|87 +39|35 +39|31 +39|99 +39|95 +96|66 +96|35 +96|26 +96|79 +96|87 +96|84 +96|27 +96|11 +96|33 +96|77 +96|95 +96|46 +96|76 +96|39 +96|17 +96|44 +96|47 +96|83 +96|43 +96|41 +96|22 +96|72 +95|75 +95|54 +95|92 +95|98 +95|59 +95|87 +95|16 +95|47 +95|63 +95|12 +95|72 +95|97 +95|85 +95|99 +95|56 +95|48 +95|83 +95|69 +95|74 +95|88 +95|78 +95|31 +95|82 +47|92 +47|45 +47|61 +47|31 +47|54 +47|16 +47|97 +47|98 +47|63 +47|85 +47|78 +47|48 +47|82 +47|12 +47|69 +47|87 +47|88 +47|75 +47|72 +47|83 +47|56 +47|74 +47|99 +47|59 +74|11 +74|12 +74|82 +74|17 +74|16 +74|22 +74|78 +74|85 +74|56 +74|45 +74|96 +74|55 +74|99 +74|76 +74|63 +74|97 +74|69 +74|48 +74|84 +74|31 +74|98 +74|36 +74|61 +74|67 +22|32 +22|87 +22|39 +22|72 +22|43 +22|47 +22|59 +22|79 +22|41 +22|83 +22|35 +22|77 +22|26 +22|88 +22|54 +22|95 +22|24 +22|46 +22|27 +22|44 +22|33 +22|66 +22|75 +22|92 +78|26 +78|96 +78|84 +78|46 +78|22 +78|44 +78|63 +78|45 +78|76 +78|67 +78|55 +78|56 +78|82 +78|61 +78|97 +78|11 +78|43 +78|69 +78|98 +78|12 +78|79 +78|36 +78|17 +78|66 +27|74 +27|75 +27|24 +27|77 +27|54 +27|92 +27|48 +27|31 +27|99 +27|41 +27|59 +27|83 +27|82 +27|72 +27|85 +27|88 +27|16 +27|78 +27|98 +27|39 +27|87 +27|47 +27|95 +27|35 +45|77 +45|44 +45|11 +45|27 +45|79 +45|41 +45|84 +45|96 +45|17 +45|22 +45|55 +45|69 +45|43 +45|61 +45|66 +45|36 +45|67 +45|33 +45|76 +45|46 +45|26 +45|24 +45|32 +45|12 +76|75 +76|87 +76|54 +76|33 +76|41 +76|32 +76|46 +76|35 +76|88 +76|92 +76|22 +76|47 +76|83 +76|95 +76|72 +76|77 +76|44 +76|26 +76|43 +76|39 +76|79 +76|27 +76|24 +76|66 +83|85 +83|69 +83|99 +83|56 +83|63 +83|87 +83|88 +83|98 +83|61 +83|45 +83|48 +83|92 +83|55 +83|16 +83|54 +83|59 +83|74 +83|31 +83|67 +83|12 +83|75 +83|82 +83|97 +83|78 +56|79 +56|11 +56|61 +56|77 +56|69 +56|45 +56|12 +56|84 +56|67 +56|66 +56|63 +56|44 +56|33 +56|17 +56|96 +56|36 +56|43 +56|46 +56|32 +56|27 +56|26 +56|76 +56|55 +56|22 +63|41 +63|96 +63|22 +63|32 +63|36 +63|12 +63|44 +63|67 +63|55 +63|61 +63|33 +63|79 +63|45 +63|26 +63|27 +63|17 +63|11 +63|84 +63|46 +63|69 +63|76 +63|66 +63|77 +63|43 +16|26 +16|99 +16|85 +16|61 +16|56 +16|98 +16|22 +16|82 +16|78 +16|12 +16|84 +16|17 +16|96 +16|36 +16|45 +16|63 +16|76 +16|11 +16|69 +16|48 +16|55 +16|79 +16|97 +16|67 +82|67 +82|76 +82|45 +82|17 +82|36 +82|46 +82|79 +82|11 +82|69 +82|84 +82|55 +82|96 +82|22 +82|66 +82|44 +82|97 +82|26 +82|12 +82|56 +82|98 +82|43 +82|63 +82|32 +82|61 +79|35 +79|83 +79|54 +79|47 +79|59 +79|24 +79|92 +79|39 +79|88 +79|77 +79|33 +79|26 +79|44 +79|66 +79|46 +79|87 +79|95 +79|43 +79|75 +79|74 +79|41 +79|32 +79|27 +79|72 +54|61 +54|69 +54|45 +54|99 +54|82 +54|88 +54|17 +54|16 +54|98 +54|78 +54|56 +54|36 +54|63 +54|11 +54|31 +54|59 +54|85 +54|67 +54|74 +54|55 +54|48 +54|12 +54|97 +54|96 +32|54 +32|85 +32|33 +32|92 +32|59 +32|72 +32|75 +32|95 +32|31 +32|39 +32|87 +32|83 +32|35 +32|16 +32|78 +32|24 +32|88 +32|48 +32|47 +32|77 +32|74 +32|99 +32|41 +32|27 +44|88 +44|85 +44|83 +44|32 +44|47 +44|48 +44|95 +44|31 +44|99 +44|59 +44|41 +44|27 +44|35 +44|54 +44|16 +44|24 +44|75 +44|72 +44|92 +44|77 +44|39 +44|33 +44|74 +44|87 +87|45 +87|75 +87|59 +87|88 +87|61 +87|92 +87|69 +87|97 +87|82 +87|31 +87|99 +87|12 +87|48 +87|54 +87|74 +87|36 +87|85 +87|56 +87|63 +87|67 +87|55 +87|98 +87|78 +87|16 +55|44 +55|66 +55|96 +55|76 +55|39 +55|24 +55|77 +55|22 +55|43 +55|84 +55|17 +55|11 +55|46 +55|33 +55|67 +55|95 +55|27 +55|79 +55|35 +55|32 +55|47 +55|41 +55|36 +55|26 +67|46 +67|17 +67|33 +67|72 +67|96 +67|35 +67|36 +67|79 +67|39 +67|66 +67|41 +67|27 +67|11 +67|44 +67|43 +67|26 +67|76 +67|47 +67|84 +67|22 +67|95 +67|77 +67|32 +67|24 +97|17 +97|69 +97|12 +97|84 +97|67 +97|56 +97|11 +97|32 +97|26 +97|27 +97|45 +97|96 +97|22 +97|55 +97|43 +97|46 +97|36 +97|61 +97|33 +97|66 +97|63 +97|44 +97|79 +97|76 +66|32 +66|99 +66|33 +66|87 +66|83 +66|92 +66|74 +66|44 +66|59 +66|41 +66|77 +66|54 +66|16 +66|39 +66|31 +66|27 +66|95 +66|47 +66|35 +66|72 +66|24 +66|75 +66|88 +66|46 +26|27 +26|33 +26|66 +26|32 +26|44 +26|41 +26|72 +26|88 +26|75 +26|74 +26|46 +26|95 +26|54 +26|43 +26|83 +26|47 +26|77 +26|39 +26|92 +26|24 +26|35 +26|31 +26|59 +26|87 +99|79 +99|63 +99|36 +99|43 +99|96 +99|48 +99|26 +99|78 +99|85 +99|12 +99|69 +99|76 +99|17 +99|82 +99|56 +99|61 +99|97 +99|45 +99|67 +99|84 +99|11 +99|98 +99|22 +99|55 +12|77 +12|22 +12|33 +12|36 +12|17 +12|96 +12|41 +12|11 +12|27 +12|26 +12|76 +12|39 +12|84 +12|35 +12|43 +12|55 +12|24 +12|66 +12|61 +12|79 +12|46 +12|44 +12|32 +12|67 +77|39 +77|48 +77|41 +77|99 +77|59 +77|82 +77|85 +77|75 +77|72 +77|54 +77|47 +77|95 +77|78 +77|31 +77|16 +77|83 +77|24 +77|92 +77|35 +77|74 +77|87 +77|97 +77|98 +77|88 +61|17 +61|43 +61|36 +61|95 +61|41 +61|46 +61|66 +61|33 +61|67 +61|55 +61|27 +61|22 +61|77 +61|24 +61|35 +61|96 +61|39 +61|79 +61|32 +61|76 +61|84 +61|44 +61|26 +61|11 +84|83 +84|35 +84|26 +84|47 +84|22 +84|46 +84|27 +84|92 +84|54 +84|33 +84|44 +84|43 +84|66 +84|32 +84|77 +84|87 +84|79 +84|72 +84|76 +84|95 +84|75 +84|41 +84|24 +48|69 +48|82 +48|97 +48|61 +48|96 +48|12 +48|67 +48|22 +48|78 +48|45 +48|66 +48|76 +48|98 +48|17 +48|84 +48|55 +48|46 +48|36 +48|56 +48|43 +48|63 +48|26 +88|16 +88|11 +88|96 +88|59 +88|85 +88|45 +88|31 +88|74 +88|69 +88|36 +88|63 +88|48 +88|55 +88|78 +88|67 +88|61 +88|99 +88|97 +88|84 +88|17 +88|56 +69|24 +69|79 +69|12 +69|96 +69|66 +69|44 +69|33 +69|26 +69|32 +69|36 +69|84 +69|41 +69|17 +69|11 +69|43 +69|39 +69|27 +69|55 +69|76 +69|46 +41|98 +41|85 +41|99 +41|35 +41|24 +41|16 +41|88 +41|97 +41|92 +41|54 +41|48 +41|39 +41|72 +41|87 +41|47 +41|74 +41|78 +41|82 +41|31 +24|88 +24|59 +24|78 +24|99 +24|74 +24|72 +24|85 +24|39 +24|56 +24|35 +24|75 +24|95 +24|92 +24|63 +24|31 +24|82 +24|87 +24|83 +33|99 +33|24 +33|85 +33|41 +33|27 +33|74 +33|77 +33|48 +33|83 +33|39 +33|95 +33|31 +33|75 +33|54 +33|72 +33|35 +33|87 +92|55 +92|85 +92|16 +92|96 +92|12 +92|36 +92|31 +92|45 +92|98 +92|69 +92|99 +92|11 +92|61 +92|48 +92|67 +92|54 +11|66 +11|72 +11|17 +11|87 +11|95 +11|46 +11|44 +11|26 +11|33 +11|22 +11|84 +11|76 +11|41 +11|32 +11|83 +36|95 +36|77 +36|43 +36|84 +36|24 +36|17 +36|11 +36|27 +36|32 +36|79 +36|47 +36|41 +36|22 +36|66 +59|56 +59|48 +59|16 +59|11 +59|82 +59|85 +59|63 +59|99 +59|96 +59|45 +59|74 +59|98 +59|31 +98|12 +98|44 +98|36 +98|33 +98|56 +98|76 +98|11 +98|96 +98|69 +98|79 +98|43 +98|17 +72|56 +72|55 +72|74 +72|16 +72|97 +72|82 +72|85 +72|83 +72|92 +72|98 +72|61 +35|63 +35|16 +35|92 +35|31 +35|85 +35|78 +35|48 +35|95 +35|72 +35|54 +43|35 +43|74 +43|88 +43|77 +43|66 +43|27 +43|41 +43|46 +43|87 +17|35 +17|84 +17|77 +17|44 +17|87 +17|33 +17|76 +17|66 +31|48 +31|84 +31|36 +31|69 +31|96 +31|76 +31|85 +85|12 +85|97 +85|63 +85|26 +85|45 +85|79 +75|78 +75|92 +75|67 +75|56 +75|48 +46|92 +46|33 +46|41 +46|85 +39|98 +39|74 +39|54 +96|32 +96|24 +95|45 + +26,46,44,33,77,41,39,95,47,83,75,54,88,59,74 +63,61,11,79,26,44,32,33,77 +72,92,16,48,98 +48,82,59,85,55 +66,84,76,33,79,75,92,41,44,46,35 +63,69,61,55,67,36,11,84,76,22,26,46,44,32,33,27,77 +33,77,17,32,24,26,11,61,43,79,46,76,84,22,12,41,96,27,55,67,36,44,39 +11,17,84,76,79,26,43,66,46,44,32,33,77,41,24,95,47,83,87 +27,77,41,24,39,35,95,72,83,87,75,92,54,88,74,31,99,85,48,78,82 +87,75,54,88,59,74,31,99,48,78,97,56,63,45,69,12,61,55,67 +46,17,66,76,77,67,26,35,61,96,22,44,11,24,27 +39,35,72,83,87,75,92,59,74,31,99,85,48,78,82,98,63 +24,27,17,76,79,44,26,32,35 +98,88,63,45,56,72,78,85,82,12,69,59,87,54,47,75,31,83,48,16,74,99,92 +67,17,84,76,22,79,43,46,32,33,24,35,47 +78,27,33,24,85,74,92,54,75,95,48,99,39 +95,47,72,83,87,75,92,54,88,74,31,16,99,85,48,98,97,56,63,45,69 +83,16,77,35,59,31,46,27,74,92,39,66,87,54,41,33,75,44,95 +72,33,39,88,54,26,27,24,41,22,92,35,46,87,44,83,43,77,75,32,79,95,66 +79,36,41,46,44,72,35,27,17 +84,26,66,32,33,35,95,72,92 +31,16,45,69,61,12,74,17,82,85,11,88,48,98,67,63,99,56,96,78,36 +78,87,16,95,35,45,85 +61,55,67,36,96,11,17,84,76,26,43,66,46,33,27,77,41,24,39 +56,78,99,69,47,16,98,92,72,83,75,74,82,45,31,85,63,12,48 +54,59,95,31,92,87,16 +72,87,24,92,59,95,47,75,88,41,99,82,16,85,39 +17,22,26,84,67,55,36,11,61,79,69,97,76 +77,26,11,32,43,66,63,33,44,67,76 +77,85,47,99,44,31,95,27,87,35,54,16,74,39,83,59,41,32,24 +47,72,83,87,75,92,54,59,74,85,48,78,82,98,97,56,63,69,12 +74,31,48,78,98,56,45,69,61,11,84 +26,11,97,56,67,66,69,32,17,43,55,36,33,22,79,76,96,61,45,44,12,84,63 +72,83,77,92,27,75,41,35,44,33,54,43,46,79,26,47,22,66,24 +95,41,44,59,66,88,35,77,27,79,43,72,26,47,92,46,54,33,83 +45,69,12,55,67,36,96,11,17,84,76,22,26,43,66,46,44,32,27,77,41 +48,98,56,69,36,76,79,43,66 +84,77,35,83,44,39,66,75,72,27,79,26,17,24,43,76,87,22,46,47,95,32,33 +69,74,92,98,59,63,99,83,72,45,47,95,54,87,48 +92,56,96,59,74,69,85,99,98 +11,84,76,26,43,66,46,44,32,33,27,77,41,24,39,35,95,83,87 +97,67,11,76,79,43,66,32,33 +66,44,27,77,24,39,35,95,72,83,75,88,74,31,16 +36,11,76,43,44 +88,97,63,98,56,87,75,99,59,35,48,92,95,83,78,54,47 +76,77,32,55,27,79,46,66,17,12,69,43,45,84,44,41,33 +77,41,27,92,99,75,24,44,46,59,32 +76,24,12,32,96,79,77,36,84 +77,24,35,72,83,87,75,92,88,59,31,16,85,82,98 +67,77,39,22,84,47,46,41,44,26,95,35,27,76,66,11,79,96,33,24,43 +69,12,61,36,96,84,76,22,79,26,43,46,33,41,24 +46,96,78,22,26,11,76 +47,72,92,88,59,74,16,78,82,98,56,63,12 +75,92,54,59,74,31,99,85,48,56,63,69,12,67,36 +43,54,44,35,77,26,92,76,47 +87,92,54,88,59,74,31,16,99,85,48,78,82,98,56,63,45,69,12,61,55 +36,11,17,24,66,32,84,61,77 +33,24,22,35,47,83,76,77,92,66,54,44,75,32,41,26,46,87,79 +63,36,96,11,17,26,46,44,77 +87,92,47,75,32,27,16,33,39,44,41,72,88,46,77,59,95,54,99,35,24 +22,26,43,66,46,32,33,27,95,83,75,54,88 +76,96,82,97,98,61,44 +84,82,17,99,67,48,11,85,12,22,69,96,55 +46,32,41,39,95,75,54,16,99 +87,92,16,99,78,98,56 +45,61,74,12,11,76,67 +46,27,32,77,92,88,47,31,99 +63,85,26,97,82,36,17,56,48,22,45,99,61,84,78 +41,48,95,77,82,31,74,85,72,88,35,99,27,39,78,24,92 +61,87,92,55,31,69,67,56,88,16,48,97,74,54,63 +44,32,27,77,41,24,35,95,47,72,83,87,75,54,88,59,74,31,16,99,85 +79,66,46,32,27 +54,56,97,83,95,24,82,31,85,88,35,16,92 +26,17,45,12,43,96,48 +99,48,82,56,63,45,69,61,55,67,17,76,79 +66,16,72,27,88,77,44 +98,97,56,63,45,12,61,55,36,96,11,17,22,79,26,66,46,44,32 +39,35,95,47,72,83,87,75,92,54,88,59,74,31,99,85,48,78,82,98,97,56,63 +56,69,85,67,11,43,96,17,55,76,26,84,45 +54,59,16,99,78,82,11 +63,84,61,97,11,79,16,67,99,82,96,22,76,56,36 +39,59,72,33,83,95,48,74,87,16,41,54,77,85,35,92,47,78,31,88,99 +98,97,56,12,61,36,96,11,17,84,22,79,26,43,46,44,32 +84,76,22,79,26,43,32,27,77,41,47,72,92 +69,12,61,55,96,11,17,84,22,79,26,43,66,46,44,32,33,27,77,41,24 +79,82,66,48,76,22,17,55,45,67,36,63,43,98,11,61,78 +54,88,59,74,31,16,99,85,48,78,82,98,97,63,45,69,12,61,55,67,36,96,11 +45,61,97,99,72,74,12 +95,47,72,54,88,59,31,16,99,85,48,98,97,56,69 +83,87,75,92,54,88,59,74,31,16,99,85,48,82,98,97,63,45,69,12,55 +56,98,31,54,16,83,48,35,92,24,95,78,87 +82,98,97,45,12,61,55,67,36,96,11,17,84,76,22,79,43,66,44 +79,26,43,46,33,27,77,41,24,39,95,47,83,87,75,88,59 +78,16,97,56,61,67,11,48,99,22,31,82,17,69,96 +56,98,69,63,78,55,31,16,83 +46,76,79,44,77,55,84,36,26,33,12,39,43,67,17 +26,92,41,83,87,75,35,43,46,88,32,33,44,47,77,24,27,72,39,95,59 +85,96,97,74,48,11,55,69,36,31,59,63,82,16,45,17,99,67,61,12,98 +46,66,92,33,39,27,47,44,72 +11,99,67,55,63,97,48,69,74 +88,32,75,41,72,74,33,44,39,31,95,47,54,87,83,16,59 +72,83,92,48,98,97,61 +31,69,12,36,98,97,85,11,61,48,82 +77,59,27,26,32,24,92,83,35,87,66,39,41,46,74,88,54,95,44 +82,56,69,36,11 +55,56,74,96,45 +46,17,69,32,76,97,43,33,22 +36,96,17,84,76,22,79,26,46,44,32,27,77,41,24,39,35,47,72 +69,55,26,66,77,41,24 +98,75,78,95,16,35,87,88,47,99,39,82,48,56,63,59,92,97,31,83,54 +36,17,85,59,55,78,12,56,96,11,84,67,63,61,74,45,99,31,97 +99,97,87,82,16,63,88,12,74,98,56,45,92,69,75,78,59,55,61,54,67,31,48 +79,67,55,11,63,46,17,69,43,44,26,97,45,61,76,36,98 +17,36,84,16,74,12,67,11,76,78,96,97,82,61,45 +11,66,96,79,67,35,39,22,84,33,76,55,43,27,61,44,24,36,32 +27,72,78,77,33,85,39 +27,17,32,67,36,33,69,43,12,61,66,24,11,77,96 +78,56,31,82,39,74,92 +78,82,98,97,36,84,46 +31,99,78,12,96,11,17,84,22 +77,35,95,54,83,87,43,41,72,39,92,22,79,44,66,26,46 +66,24,84,27,61 +43,77,33,54,95,88,46,26,75,92,32,74,66,24,47,72,83,59,35,44,41 +27,77,41,24,39,35,95,47,72,83,87,75,92,54,88,59,31,16,99,85,48,78,82 +88,59,74,31,16,99,48,82,98,56,63,45,69,12,61,67,96,11,17 +85,88,36,75,56,98,82,45,59,78,54,74,92,16,67 +95,76,24,55,84,27,77,33,26,35,67,44,11,17,43 +97,22,11,78,84,69,26,85,82,55,98,17,48,12,36,61,76,96,43,56,45,67,79 +78,97,56,45,69,61,67,96,17,76,22,79,46 +59,97,31,61,98,88,74,54,85,55,48,12,83,87,16,99,78,75,45 +24,39,35,95,47,72,83,87,75,92,54,88,59,74,31,16,99,48,78,82,98,97,56 +43,66,46,44,32,27,77,41,24,39,35,95,47,72,83,87,92,88,59,74,31 +82,98,97,56,63,45,61,55,67,36,96,11,17,84,76,22,26,43,66,46,44 +88,54,27,83,41 +69,75,31,47,56,45,95 +11,84,22,66,27 +59,16,99,48,82,98,97,56,63,69,12,61,55,67,96,17,84 +31,98,39,16,78,24,85,72,87,56,48,95,99 +32,33,27,35,72,87,54,74,31 +43,33,27,24,39,72,31 +87,74,47,16,54,72,45,56,97,82,31,75,83,59,35,48,98,92,63 +61,55,67,36,96,11,17,76,22,79,26,43,66,46,44,32,33,27,77,41,24,39,35 +33,84,72,79,24,95,41,36,27 +41,24,35,95,47,87,92,54,88,59,31,16,99,85,82 +97,56,45,79,76,16,36,17,61,11,22 +82,45,97,98,16,61,67,54,88,48,63,78,74,12,99,96,31,85,11 +17,22,66,44,77,41,35,95,75 +96,17,84,76,22,79,43,46,44,32,27,77,41,24,39,35,95,47,83 +85,98,56,11,45,96,78,63,69,31,22,67,36 +72,16,99,24,27,87,41,47,39,54,75,44,92,77,33,74,31,59,88,32,46,35,95 +26,43,32,33,27,39,72,54,88,59,74 +69,61,55,67,96,11,84,22,79,66,46,32,33 +88,48,75,59,31,54,56,82,74,92,45,78,12,55,87 +74,31,16,99,85,48,78,82,98,97,56,63,45,69,12,61,55,67,96,11,17,84,76 +11,43,78,46,61,55,96 +72,83,92,54,88,74,31,16,85,48,78,98,63,69,61 +76,41,33,36,11,77,24,39,84,66,61,27,67,55,17,22,35,44,32,79,26 +48,11,82,96,97,45,16 +32,33,27,35,47,72,83,92,54,88,74,31,99,85,48 +48,82,98,56,63,45,69,61,67,96,76,79,26,43,66 +66,41,33,32,27,36,96,43,11,79,24,17,95,46,84,44,35,76,39,67,47 +54,74,85,78,97 +39,35,95,47,72,83,87,75,54,88,59,74,31,16,99,85,48,78,82,98,97,56,63 +88,31,16,48,78,98,97,63,12,61,36,96,17 +47,31,39,43,54,77,66,35,44,59,72,92,24,32,95,88,33,27,46 +11,17,84,26,66,46,44,32,33,27,41,24,39,47,72,83,87 +82,97,55,17,84,43,44 +67,82,99,87,63,61,88,55,48,69,45 +67,69,84,24,55,41,11 +75,16,45,12,55,67,36 +74,31,48,97,12,96,17,84,76 +83,72,66,24,46,96,17,35,79,22,43,44,32 +35,95,47,72,83,92,54,88,74,85,78,97,56,63,45 +46,77,87,39,35,22,47,95,33,44,92 +75,41,59,74,43,95,24,72,26,77,32,44,66 +36,96,84,79,26,66,46,32,33,27,77,41,39,35,95,47,72 +35,87,33,46,22,92,88,79,47,41,24,44,32,72,54,43,27,83,39,95,66 +36,11,17,26,41 +84,76,22,79,43,33,27,77,24,35,95,75,92 +11,79,66,27,39,95,87 +39,24,32,26,12,17,44 +84,43,83,35,41,76,22,32,46,27,79,87,92,47,24 +61,43,22,84,67,36,46,78,63,12,11,96,17 +77,41,24,39,95,83,87,54,74,31,48,82,98 +59,98,78,75,97,63,45,61,88,72,99,82,69 +78,67,55,74,63,56,31,36,92,12,45 +63,45,67,96,26,43,66,44,77 +96,36,77,22,76,61,27,12,55,39,33,79,26,84,32,43,67 +82,98,69,16,75,85,78,67,87,12,63,56,99 +82,96,54,63,69,99,55,74,11 +95,47,72,83,87,92,54,88,59,74,31,16,99,48,97,63,69 +11,84,22,79,26,66,46,44,32,33,27,77,41,24,39,35,95,47,72,83,87 +41,92,99,31,82,72,24,98,88,48,16,47,78,74,59,95,97,75,85,35,87 +72,83,75,92,54,59,74,31,16,85,48,82,98,97,63,45,69,12,61 diff --git a/2024/06/code.py b/2024/06/code.py new file mode 100644 index 0000000..4b3a17c --- /dev/null +++ b/2024/06/code.py @@ -0,0 +1,163 @@ +from pathlib import Path +from itertools import cycle +import numpy as np + +filepath = Path("./data/6_example") +filepath = Path("./data/6_input") + +UP = ord("^") +RIGHT = ord(">") +DOWN = ord("v") +LEFT = ord("<") +EMPTY = ord(".") +FULL = ord("#") +WALKED_X = ord("|") +WALKED_Y = ord("-") +WALKED_B = ord("+") +BLOCKED = ord("O") + + +def eval_pos(state): + for i, line in enumerate(state): + for j, tile in enumerate(line): + if tile in "^v><": + return np.array([i, j]), tile + + +class surveillance: + + dirs = cycle( + [ + np.array([-1, 0]), + np.array([0, 1]), + np.array([1, 0]), + np.array([0, -1]), + ] + ) + + def __init__(self, state): + map = [[ord(c) for c in line.replace("^", ".")] for line in state] + self.map = np.array(list(map)) + self.history = np.copy(self.map) + self.pos, dir = eval_pos(state) + self.heading = next(self.dirs) + self.next_heading = next(self.dirs) + self.present = True + self.path = list() + self.potential_loops = list() + self.ignore_next = False + + def __str__(self): + x, y = self.pos + map = self.history[:] + n, m = map.shape + if (x >= 0 and x < n) and (y >= 0 and y < m): + map[x, y] = self.view + for x, y in self.potential_loops: + map[x, y] = BLOCKED + return "\n".join(["".join([chr(i) for i in line]) for line in map]) + + def advance(self): + self.update_history() + if self.path_clear(): + self.loop_check() + self.path.append(tuple([*self.pos, self.view])) + self.pos += self.heading + else: + self.heading = self.next_heading + self.next_heading = next(self.dirs) + self.ignore_next = True + + def update_history(self): + x, y = self.pos + trail = WALKED_X if self.heading[0] else WALKED_Y + self.history[x, y] = trail if self.history[x, y] == EMPTY else WALKED_B + + def path_clear(self): + n, m = self.map.shape + u, v = self.pos + self.heading + if (u < 0 or u >= n) or (v < 0 or v >= m): + self.present = False + return True + if self.map[u, v] == FULL: + return False + return True + + def loop_check(self): + if self.ignore_next: + self.ignore_next = False + return + x, y = self.pos + u, v = self.next_heading + + x_slice = slice(x, None, u) if u else x + y_slice = slice(y, None, v) if v else y + line = self.history[x_slice, y_slice] + try: + first_block = np.argwhere(line == FULL).flatten()[0] + except IndexError: + first_block = len(line) + + line = line[:first_block] + walked_2 = WALKED_X if u else WALKED_Y + qualified = [WALKED_B, walked_2] + in_line = any([np.any(line == w) for w in qualified]) + + if not in_line: + return + idx1 = np.argwhere(line == walked_2).flatten() + idx1 = idx1[0] if len(idx1) else len(line) + idx2 = np.argwhere(line == WALKED_B).flatten() + idx2 = idx2[0] if len(idx2) else len(line) + idx = min(idx1, idx2) + p = self.pos + self.next_heading * idx + if (*p, self.next_view) in self.path: + self.potential_loops.append(self.pos + self.heading) + + def _view(self, heading): + view = { + (-1, 0): UP, + (1, 0): DOWN, + (0, 1): RIGHT, + (0, -1): LEFT, + } + return view[tuple(heading)] + + @property + def view(self): + return self._view(self.heading) + + @property + def next_view(self): + return self._view(self.next_heading) + + @property + def walked_tiles(self): + return {tuple([x, y]) for x, y, _ in self.path} + + def tick(self, n, plot=True): + for _ in range(n): + if not self.present: + break + self.advance() + if plot: + print(self) + print(len({tuple([x, y]) for x, y, _ in self.path})) + print(len(self.potential_loops)) + + def walk(self, plot=True): + while self.present: + self.advance() + if plot: + print(self) + print(len({tuple([x, y]) for x, y, _ in self.path})) + print(len(self.potential_loops)) + + +if __name__ == "__main__": + with open(filepath) as filein: + state_0 = [line.rstrip() for line in filein.readlines()] + + nppsm_lab = surveillance(state_0) + nppsm_lab.walk(plot=True) + # nppsm_lab.tick(14) diff --git a/2024/06/example b/2024/06/example new file mode 100644 index 0000000..a4eb402 --- /dev/null +++ b/2024/06/example @@ -0,0 +1,10 @@ +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... diff --git a/2024/06/info.txt b/2024/06/info.txt new file mode 100644 index 0000000..7f5002f --- /dev/null +++ b/2024/06/info.txt @@ -0,0 +1,190 @@ +--- Day 6: Guard Gallivant --- + +The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. + +You still have to be careful of time paradoxes, and so it will be important to avoid anyone from 1518 while The Historians search for the Chief. Unfortunately, a single guard is patrolling this part of the lab. + +Maybe you can work out where the guard will go ahead of time so that The Historians can search safely? + +You start by making a map (your puzzle input) of the situation. For example: + +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... + +The map shows the current position of the guard with ^ (to indicate the guard is currently facing up from the perspective of the map). Any obstructions - crates, desks, alchemical reactors, etc. - are shown as #. + +Lab guards in 1518 follow a very strict patrol protocol which involves repeatedly following these steps: + + If there is something directly in front of you, turn right 90 degrees. + Otherwise, take a step forward. + +Following the above protocol, the guard moves up several times until she reaches an obstacle (in this case, a pile of failed suit prototypes): + +....#..... +....^....# +.......... +..#....... +.......#.. +.......... +.#........ +........#. +#......... +......#... + +Because there is now an obstacle in front of the guard, she turns right before continuing straight in her new facing direction: + +....#..... +........># +.......... +..#....... +.......#.. +.......... +.#........ +........#. +#......... +......#... + +Reaching another obstacle (a spool of several very long polymers), she turns right again and continues downward: + +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#......v. +........#. +#......... +......#... + +This process continues for a while, but the guard eventually leaves the mapped area (after walking past a tank of universal solvent): + +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#........ +........#. +#......... +......#v.. + +By predicting the guard's route, you can determine which specific positions in the lab will be in the patrol path. Including the guard's starting position, the positions visited by the guard before leaving the area are marked with an X: + +....#..... +....XXXXX# +....X...X. +..#.X...X. +..XXXXX#X. +..X.X.X.X. +.#XXXXXXX. +.XXXXXXX#. +#XXXXXXX.. +......#X.. + +In this example, the guard will visit 41 distinct positions on your map. + +Predict the path of the guard. How many distinct positions will the guard visit before leaving the mapped area? + +--- Part Two --- + +While The Historians begin working around the guard's patrol route, you borrow their fancy device and step outside the lab. From the safety of a supply closet, you time travel through the last few months and record the nightly status of the lab's guard post on the walls of the closet. + +Returning after what seems like only a few seconds to The Historians, they explain that the guard's patrol area is simply too large for them to safely search the lab without getting caught. + +Fortunately, they are pretty sure that adding a single new obstruction won't cause a time paradox. They'd like to place the new obstruction in such a way that the guard will get stuck in a loop, making the rest of the lab safe to search. + +To have the lowest chance of creating a time paradox, The Historians would like to know all of the possible positions for such an obstruction. The new obstruction can't be placed at the guard's starting position - the guard is there right now and would notice. + +In the above example, there are only 6 different positions where a new obstruction would cause the guard to get stuck in a loop. The diagrams of these six situations use O to mark the new obstruction, | to show a position where the guard moves up/down, - to show a position where the guard moves left/right, and + to show a position where the guard moves both up/down and left/right. + +Option one, put a printing press next to the guard's starting position: + +....#..... +....+---+# +....|...|. +..#.|...|. +....|..#|. +....|...|. +.#.O^---+. +........#. +#......... +......#... + +Option two, put a stack of failed suit prototypes in the bottom right quadrant of the mapped area: + +....#..... +....+---+# +....|...|. +..#.|...|. +..+-+-+#|. +..|.|.|.|. +.#+-^-+-+. +......O.#. +#......... +......#... + +Option three, put a crate of chimney-squeeze prototype fabric next to the standing desk in the bottom right quadrant: + +....#..... +....+---+# +....|...|. +..#.|...|. +..+-+-+#|. +..|.|.|.|. +.#+-^-+-+. +.+----+O#. +#+----+... +......#... + +Option four, put an alchemical retroencabulator near the bottom left corner: + +....#..... +....+---+# +....|...|. +..#.|...|. +..+-+-+#|. +..|.|.|.|. +.#+-^-+-+. +..|...|.#. +#O+---+... +......#... + +Option five, put the alchemical retroencabulator a bit to the right instead: + +....#..... +....+---+# +....|...|. +..#.|...|. +..+-+-+#|. +..|.|.|.|. +.#+-^-+-+. +....|.|.#. +#..O+-+... +......#... + +Option six, put a tank of sovereign glue right next to the tank of universal solvent: + +....#..... +....+---+# +....|...|. +..#.|...|. +..+-+-+#|. +..|.|.|.|. +.#+-^-+-+. +.+----++#. +#+----++.. +......#O.. + +It doesn't really matter what you choose to use as an obstacle so long as you and The Historians can put it into position without the guard noticing. The important thing is having enough options that you can find one that minimizes time paradoxes, and in this example, there are 6 different positions you could choose. + +You need to get the guard stuck in a loop by adding a single new obstruction. How many different positions could you choose for this obstruction? diff --git a/2024/06/input b/2024/06/input new file mode 100644 index 0000000..1436e70 --- /dev/null +++ b/2024/06/input @@ -0,0 +1,130 @@ +..................#................................................................#........#..................................... +...#...........#...................................................#........................................#.................#... +...................................#................#.#...............#.................................................#......... +.....#......#................#.....................................................................#..........#........#......#... +............................................................................................#.....................#............... +.....................#..##...#........................#.................#.......................#..#.........#.......#...#......#. +............##....................................##..................#...............................#....#...................... +.............#............#.#..#.......#...........#..............#...............#.....#......................................... +....................#..........##.........#.........#................#............................................................ +....#.......#................................................................#...#.#..........................................#.#. +..#..............#.....................................#..........#.#....#..............#..................#.#............#....... +.#.......#.........................#........................#..#.....#............................................................ +........#...#......................#...........#......................................#....................#...................... +.............................#..............#........##....#....................#......#....................#............#......#. +..............#..............#............#.......................##....#..........................................#.........#.... +.............#............#..........#..........#...#.....................................................#....................... +..#........#.....#..........................................#................................................#...#.#...#.......... +........#.....................#...#..#......#.........................................................#.....##.........#.......... +..............................................................................................#...#............................... +..#.......................#..........................#......#...................................................................#. +.......#.........................#..............#.........#.............#.......................................#...#............. +..................#.................#.......................#....................#....................................#........... +...#...#.......#......##.#...............#....#..............#..........................................#....#..#................. +#................................#.......#.....#.......#.............#..................#........#................................ +...........#..................................#.......................................................................#.#..#...... +.......#........#.........................................#..........................#...........................#.....#.......... +................#..#.....................#..#...........................#...........................................#............. +#...#.......................#................................................#................#................................#.. +..........#...........................#.......#............................................................................#.....# +..................................#............................................................#.................................. +......................#........#.............#....#.....#.......#..........................#..........................#........... +...........................##.................#.............#........................#...#..................#..................... +.............................................................................................................#....#..........#.... +................#...................................#...........#..........#....................#............................#.... +........#....#................................................#................##..#..................................#........... +...........#....................................................#...#.#......#.................................................... +.......................#.........................................................^....................................#........... +..........................#.............##..#........#.#....#.......#....................#...........#.........#.....#............ +........#...........................#..#..........................................................#............................... +....#....................................#....#.........................................#.........#............................... +...............#...................................#.....#.................................#....................................#. +......#...............................................................#.............................#........................#.... +.........................#.....#.........................#.#...............#.........#.....#..................#..#.........#...... +.........................................................#......#........##.......................#...#......#................#... +.......................................#.....#.................................#.................................................. +..................#..................................#..........................................................................#. +...................#....#.........#.......#................#....................#.........................#......#.....#..#....... +................................#..............................................................................#....#............. +.....................#.#.............#.................#..........#.......#.........................................#............. +......#....................#....................................................................#...#............................. +........#........#...........#.##.............#........................#............#..............#.........#....#........#...... +........................#.................................................................#....................................... +............................................................#.....#....................#............#.....#....#............#..... +...........#............#....#........................................................##............#..............#.............. +...........#...........#.....#..............#..............##....#........#......#................................................ +..#................................................................................#......................#......#................ +....................#.........#......................#.............................#.......#.......................#.............# +..#...#....#......................................................................................................#............... +...........#................................................................................#...............................#..... +....................................#............#..........#.........................#..................................#.......# +...................#......#...................#............#......#........#................#.............#...........#.........#. +........................#..................................#........#..................#.......................................... +............#..#...........#..................##....................#...........................................#................. +.......................................................................................#.....#............#....................... +...............................................#....#................................#..#..........................#..#........... +..............#..#.....#.........#....................#.......#..#..............#...............................#.....#........... +..........#............................#.......................................................................................... +........................................#........#........................................................#.#..................... +#................#......................#..................................................................................#...... +...............................................................................#................................#................. +...................................................................................................................#.#........#... +#........................................................................#......................................#.#............... +...#......#............#...................#.............#........#..........................................#......#............. +..............##....#...................................................#......................#.................................. +...............#........................................................................#...........#...#.#....................... +..........#.#.....#................................#...........#........#.......#................................................. +#....................#......................................................................................#..................... +..............#...##...........................................#.............#.......#..................#..............#.......... +.#.............................................#..............................................................................#... +...#................................#............................................#............................#................... +..............................#......................................................#..........................................#. +...................#.....................................#..................................#......#.............................. +....#.#..........##.............#.......#........................##..........#.................#.................................. +#..#................#........##....................................................................................#.............. +........#...#.........................................................................#........................................... +......................................................#....#...................#..#.................................#............. +........#...............#........#..............................................#............................#.................... +...#..............................#.........................................##.......................................#....#....... +...#................#..............#.......#...................................................................................... +........#..................#.............................................................#...........................#....#....... +......................#.#..........#.......#..................................#..#...#............#...............#............... +.....#..................#....#..#......#.......................#.....................................................#............ +.....#................................#.........................#..................#.#..........#...#............#.....#.......... +....#...................#....#.#.........#........#..................................................................#....#..#.... +........#...............#......................................#........#..............................#.......................... +....#...#.#.....#..............#..................#..........#...#..#......................#...#..........#......................# +...........#...................................................................................................#................#. +.................................##..............#.............................#...............................#.................. +...........#.................#.............##...................................#.......................#.................##...... +.....#..................#......#........#.................................................#..#........................#..#........ +......#.......#......................................................................#.#.........#....#........................... +..................#.#........................#......#................................................................#......#..... +.....................#............#...................#.....#....................................#.......#..........#.......#..... +#.............................#...............................#...#............................................................... +..##.........#........#......................................#.....................#...#.............#............#..#............ +..........#.....................#..#....................#...#....................#....................#.....................#..... +...........#..........#...............#..#..........#..............................................#.#............................ +............#...#...#.............#.........#.............................#...............#....................................... +.........#...........#...............................................................#............................................ +.#..#.................................................................#............#.#.......................##................... +........##............#...................#................................#...................................................... +............................................#..........................#.......................................................... +#...................#...........#..............#...#............#.#........#.................#......#............................. +........#....................................#.................................................................................... +...........#.........#..#...............#...........#.....##.#......#....##............#....#....#.#.........##.........#......... +..#......................#..........#.................#.................#......#.............................#........#........... +....................#.................#....#..............................#....#.............#....#....#.....................#.... +............#.................#.................................#...............................#..#...........................#.. +...................................................#.....#..............#.......#....................#.#.......................... +..#.........##..#........#...................................................................................#............#....... +.....#..............................#......................................................................#........#............. +................................#........##.......#...............#..............#.......#...#.#........#......................... +..............................#.....................#.........................................#..................................# +...........#...................##.................#.................................#...............................#........#.... +..............................#...##......#..................#...#................................#......#.......#...............# +.....................##......#......#.#.......#..............#......#.................#.........#...................#............. +..........................#................................#...........#.......................................................... +...#.....#....................#.....................#...#.....#.............................#.#....#.....#.#.................#.... +............................#...#........#......................................................................#.....#........... +............#..........##..................#.............................................................#.....#..#............... diff --git a/2024/07/code.py b/2024/07/code.py new file mode 100644 index 0000000..b61e50d --- /dev/null +++ b/2024/07/code.py @@ -0,0 +1,58 @@ +from pathlib import Path + +filepath = Path("./example") +filepath = Path("./input") + +with open(filepath, "r") as filein: + data = [ + (int(line.split(":")[0]), [int(b) for b in line.split(":")[1].split()]) + for line in filein.readlines() + ] + +ops1 = { + "+": lambda a, b: a + b, + "*": lambda a, b: a * b, +} + +ops2 = { + "+": lambda a, b: a + b, + # "-": lambda a, b: a - b, + "*": lambda a, b: a * b, + # "/": lambda a, b: a / b, + "|": lambda a, b: int(f"{a}{b}"), +} + + +def guess_operators(goal, operands, ops, operators=None): + if operators is None: + operators = "" + if len(operands) == 1: + return operands[0] == goal, operators + + for k, f in ops.items(): + first = f(*operands[:2]) + new_operands = [first] + operands[2:] + test, result = guess_operators(goal, new_operands, ops, operators + k) + if test: + return test, result + else: + return False, result + + +def work_through_data(data, ops): + sum = 0 + for goal, operands in data: + test, operations = guess_operators(goal, operands, ops) + if test: + calc = "".join([f"{a} {b} " for a, b in zip(operands, operations)]) + str( + operands[-1] + ) + sum += goal + else: + calc = "impossible" + # print(goal, calc) + return sum + + +print(work_through_data(data, ops1)) +print(work_through_data(data, ops2)) diff --git a/2024/07/example b/2024/07/example new file mode 100644 index 0000000..fc6e099 --- /dev/null +++ b/2024/07/example @@ -0,0 +1,9 @@ +190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20 diff --git a/2024/07/info.txt b/2024/07/info.txt new file mode 100644 index 0000000..1147cf6 --- /dev/null +++ b/2024/07/info.txt @@ -0,0 +1,49 @@ +--- Day 7: Bridge Repair --- + +The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? + +When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed. + +You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and stole all the operators from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input). + +For example: + +190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20 + +Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value. + +Operators are always evaluated left-to-right, not according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: add (+) and multiply (*). + +Only three of the above equations can be made true by inserting operators: + + 190: 10 19 has only one position that accepts an operator: between 10 and 19. Choosing + would give 29, but choosing * would give the test value (10 * 19 = 190). + 3267: 81 40 27 has two positions for operators. Of the four possible configurations of the operators, two cause the right side to match the test value: 81 + 40 * 27 and 81 * 40 + 27 both equal 3267 (when evaluated left-to-right)! + 292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20. + +The engineers just need the total calibration result, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is 3749. + +Determine which equations could possibly be true. What is their total calibration result? + +--- Part Two --- + +The engineers seem concerned; the total calibration result you gave them is nowhere close to being within safety tolerances. Just then, you spot your mistake: some well-hidden elephants are holding a third type of operator. + +The concatenation operator (||) combines the digits from its left and right inputs into a single number. For example, 12 || 345 would become 12345. All operators are still evaluated left-to-right. + +Now, apart from the three equations that could be made true using only addition and multiplication, the above example has three more equations that can be made true by inserting operators: + + 156: 15 6 can be made true through a single concatenation: 15 || 6 = 156. + 7290: 6 8 6 15 can be made true using 6 * 8 || 6 * 15. + 192: 17 8 14 can be made true using 17 || 8 + 14. + +Adding up all six test values (the three that could be made before using only + and * plus the new three that can now be made by also using ||) produces the new total calibration result of 11387. + +Using your new knowledge of elephant hiding spots, determine which equations could possibly be true. What is their total calibration result? diff --git a/2024/07/input b/2024/07/input new file mode 100644 index 0000000..e413496 --- /dev/null +++ b/2024/07/input @@ -0,0 +1,850 @@ +20261572812: 98 138 31 2 666 +45327: 8 9 335 97 87 +829287: 99 13 816 7 1 744 9 +231630061: 460 2 33 93 500 1 52 8 +651017: 713 52 851 +30996182: 4 107 24 60 50 60 182 +16545464: 810 5 1 85 3 6 4 6 19 +146327: 7 4 8 7 7 1 1 3 73 466 7 +326: 6 4 5 7 91 4 62 8 85 7 3 9 +14687269: 7 63 8 5 6 337 1 857 1 3 +1730: 82 7 613 522 21 +6511850: 626 2 36 4 1 8 9 9 1 665 +13883777: 43 3 923 109 3 1 1 11 +19083747060: 546 3 33 44 5 5 38 3 6 7 +1568: 84 9 71 662 6 63 9 1 +203: 72 48 4 70 9 +157: 70 83 4 +1494863426: 249 6 2 4 2 748 9 4 3 4 +416767: 392 19 52 90 9 55 +60088: 8 1 2 723 12 67 +3169: 25 98 3 685 31 +11301912270: 2 680 336 4 5 6 9 5 274 +2292: 29 418 11 5 2 +48651: 40 304 4 5 6 +33745743: 49 3 9 890 9 1 846 9 +867714120: 374 4 6 5 327 234 +26733890742: 8 95 2 8 4 729 45 6 1 6 +4511655425: 11 59 4 94 613 3 64 +44441: 92 524 72 81 7 1 +7991: 6 5 9 1 764 7 7 5 733 1 +278337: 8 7 248 8 4 5 375 6 30 6 +476229876539: 94 3 1 9 8 9 29 9 1 5 7 39 +1733207525: 13 2 525 3 19 6 301 25 +1466117: 8 17 9 509 846 +1189: 4 5 5 3 889 +7817084617971: 781 708 4 570 47 9 72 +151614: 16 4 3 5 92 +8682: 2 8 86 3 24 +7446697: 35 71 38 7 97 +8668844903: 2 5 276 5 3 8 1 2 6 71 8 3 +22949069796: 2 815 9 8 9 7 6 73 6 8 9 4 +73257040: 4 54 1 3 9 7 7 6 21 3 7 +2434621: 629 289 34 1 78 85 +135: 20 7 5 +213408: 1 369 86 234 2 +106817943544: 2 74 29 852 61 50 14 4 +50897732: 53 4 3 2 8 98 66 5 15 74 +481687: 63 545 18 44 151 +866107837: 68 962 5 662 4 +21651: 1 7 4 3 6 5 2 5 +1867497: 33 5 629 3 784 6 +658564: 2 6 4 6 53 42 4 4 4 2 2 +1286: 6 327 878 70 5 +150654: 7 53 20 2 52 +32009509009: 619 108 3 6 29 95 7 4 9 +128298588: 8 2 5 77 4 8 9 8 65 2 8 12 +106971480: 1 6 7 23 5 88 6 7 4 85 99 +1298: 838 4 118 5 333 +109869: 30 95 499 68 4 3 +9534854: 9 47 9 1 5 628 449 36 1 +16008: 295 7 1 948 105 884 4 +7800300697: 60 9 37 8 450 231 3 4 +19656: 93 6 4 53 42 3 +3331320: 17 7 6 124 80 744 85 3 +2023999391: 681 118 4 7 7 4 514 +239993784: 7 41 2 5 527 191 7 948 +769876: 4 6 6 285 8 5 9 1 1 5 9 1 +730784: 545 6 6 41 32 +94876096665: 24 2 7 20 1 6 1 7 4 2 665 +459334762: 2 2 9 93 2 3 8 9 412 8 2 +6027067800: 3 27 695 221 120 +42749: 4 7 399 44 5 +137175: 84 9 59 25 +16830002448: 337 6 2 9 3 7 8 17 6 477 +473075680: 453 64 172 76 70 +950398: 63 8 119 5 398 +3374757296819: 721 4 4 9 71 514 130 +8906411904: 43 834 398 20 624 +89494: 6 2 451 8 9 634 3 1 6 7 6 +385612430: 10 7 677 103 79 +226663: 1 7 5 11 280 2 2 1 5 69 +7019457032: 2 83 3 809 1 41 826 +117829733: 332 846 297 22 6 4 1 +4293: 47 5 61 8 4 576 92 9 +27956: 4 3 50 13 6 +1698430: 2 4 737 4 72 226 156 +904: 46 9 2 654 52 20 68 +592947912: 1 219 8 5 903 8 3 83 8 3 +594519: 59 1 4 51 9 +82300: 7 2 113 64 50 +18655560: 3 365 66 1 84 +183864: 4 9 80 95 978 +4549914: 4 6 46 9 1 582 8 4 952 9 +627883: 6 278 8 3 +18928824: 3 5 6 262 81 4 2 24 +57994: 1 4 95 2 15 73 2 1 31 +1759022: 39 1 8 5 42 8 493 +5033908: 23 706 3 31 35 +556387631: 7 7 54 90 3 6 67 6 3 32 +1458452: 2 3 1 4 90 158 678 9 4 +746735089: 45 775 519 2 67 91 3 9 +96495380: 4 85 303 17 6 1 4 149 +275290785: 1 5 3 8 42 4 5 505 4 6 5 9 +9455765: 424 946 4 69 4 +603870572: 903 86 6 6 6 9 491 2 2 +2110: 51 114 91 8 62 +2463: 3 303 756 2 3 1 791 1 +65915810695: 65 827 88 810 696 +185882150: 1 8 58 821 47 +95795337: 86 254 617 953 37 +159378123309: 8 9 7 6 1 520 82 20 5 3 3 +480856880: 9 7 73 6 670 3 8 1 6 4 8 7 +2592: 75 176 8 5 +123664181: 1 8 391 8 4 644 6 2 723 +29321568: 834 366 189 96 1 +195388: 903 36 6 277 63 +4824530231: 15 75 7 497 36 30 231 +33868: 5 3 78 4 5 6 1 53 1 +734046: 81 65 44 15 114 +14871045810: 619 6 4 2 1 148 45 81 1 +3448940: 774 88 4 931 9 +48501274: 61 5 67 9 5 6 9 45 88 6 +7122124803: 6 105 8 92 16 480 2 3 +56015: 62 14 9 9 7 +63596840304: 3 3 91 27 92 5 15 2 2 +17858156412: 7 3 49 450 9 7 540 9 3 +390165: 6 3 8 22 316 6 2 4 9 37 +1276750: 50 6 51 1 8 28 9 98 4 6 +9471132: 816 67 2 3 633 3 132 +5998115: 51 4 4 9 6 816 515 +405042823: 54 75 42 823 +270329888710: 6 3 38 9 5 8 8 72 4 7 10 +9011938: 5 3 5 1 7 36 36 3 7 9 3 20 +660: 4 75 581 +1341831680: 4 7 258 141 88 56 560 +22831300800: 7 4 876 5 591 80 7 5 9 +6298914: 5 113 64 8 914 +29294: 3 9 76 876 2 11 +237239168: 35 7 1 8 2 828 85 7 67 1 +1802251877126: 15 2 267 25 2 9 77 129 +11008: 4 865 554 2 96 74 +642251445: 64 22 5 144 5 +2064: 3 2 78 543 7 9 5 2 +13773890668: 71 833 4 7 7 9 528 7 78 +28935437: 12 51 7 219 353 6 7 7 +2400515: 480 5 4 55 60 +761: 12 8 84 53 528 +3640: 20 6 480 7 20 78 +60299935213: 472 589 964 225 6 4 3 +224408: 8 8 9 1 8 29 2 95 8 2 5 3 +2046614307: 7 55 3 12 9 25 14 307 +31922850999: 6 9 1 19 1 118 7 9 4 5 6 8 +83457941113: 84 300 2 5 1 69 99 6 13 +608409710: 58 4 6 1 4 52 7 41 55 2 +819044459: 7 975 3 705 2 6 +10019018: 93 43 97 430 18 +2726736: 664 958 82 21 2 8 +849157: 996 2 9 5 1 2 1 1 1 7 421 +7278520: 1 2 981 6 3 2 1 9 4 8 5 61 +118060806: 373 11 5 143 43 6 +20902: 70 81 2 69 32 5 26 1 +639450: 359 70 6 435 735 +41696: 5 212 8 +7392: 3 765 3 453 7 1 6 +4249867874: 62 1 9 1 19 7 58 69 +32408375: 32 40 832 5 5 +1609379: 38 605 7 8 1 +1045: 9 67 6 7 956 +3060188: 8 606 1 818 9 2 6 5 8 +288224602: 1 942 3 773 2 32 730 +119: 4 3 93 8 6 +26606: 8 49 7 671 3 9 6 4 5 633 +70567960: 42 210 9 95 8 +11162592: 89 9 9 493 12 98 +1312192163295: 79 25 1 193 83 8 6 8 95 +23027: 876 2 542 8 7 +92299: 201 457 443 +73140250: 102 581 713 +134246144: 61 8 87 93 8 34 +44: 9 3 8 22 3 +66755594563: 55 62 9 1 1 4 42 3 6 4 4 3 +1235240: 9 8 90 2 69 +1167032: 9 40 2 7 38 4 7 9 7 9 73 2 +2620881661: 8 7 362 3 9 6 6 656 5 +187793: 8 179 692 98 1 +47794: 3 69 3 43 44 65 8 76 +284165701644: 99 706 353 701 644 +335162944: 57 6 98 2 944 +169260: 6 70 403 +178035795: 38 34 9 7 9 40 6 3 755 +66948420: 21 7 6 5 43 924 +2479370: 247 93 50 3 16 +6967886707: 696 7 88 6 705 +31062240000: 49 1 6 5 53 8 4 5 74 33 +8117959754763: 2 701 4 98 6 584 9 2 1 3 +14179652599: 3 70 50 492 2 94 84 7 +8834: 29 3 69 4 2 +211195608: 67 686 1 48 8 39 +9141370: 9 9 358 7 6 1 5 41 9 1 7 7 +398636: 12 5 60 4 4 6 1 322 +45629: 427 4 18 86 588 42 4 6 +209140108: 701 1 16 49 7 38 +54854749: 3 8 8 31 1 36 3 8 2 2 9 7 +36782309: 3 59 8 80 2 307 +5143959332411: 1 57 15 5 9 9 332 402 8 +1602608: 3 91 8 5 349 9 2 3 688 5 +37788: 6 8 7 687 3 +283577: 1 9 13 263 995 2 +115730: 9 3 2 124 26 2 56 8 9 2 +20700: 48 2 2 7 49 3 6 7 991 53 +276460: 25 6 6 415 3 6 70 +3271850: 322 4 392 793 10 +188703367670: 5 46 9 1 6 9 8 8 766 9 +126394406: 141 169 6 649 7 880 6 +43849535: 2 1 58 36 94 7 52 5 +7113117119: 702 9 31 137 34 11 8 +512831269: 9 29 572 229 883 15 4 +886: 4 8 15 700 6 +290874054503317: 5 9 986 8 10 900 663 5 +1150293: 4 185 21 424 9 8 885 +16808387: 45 747 23 5 8 764 +338100965: 7 1 333 5 28 35 8 74 91 +5743: 42 591 84 1 8 7 +1017379449: 233 3 95 9 18 7 6 5 2 6 9 +312579238: 665 2 442 1 89 2 2 991 +436338339683: 55 5 392 436 7 1 1 46 4 +47035605: 55 4 63 37 1 2 342 3 +85619743907: 594 144 83 743 907 +924237690: 1 8 1 37 6 9 34 11 7 688 +43212856321: 65 367 1 2 856 276 45 +5352: 506 7 39 7 9 10 1 8 303 +244908: 27 62 917 23 3 +136335660: 8 865 3 8 549 37 6 41 +30147022: 597 8 8 789 910 +267424: 1 932 3 2 6 1 5 68 1 137 +651: 6 46 5 +87604475: 8 1 725 4 236 79 2 8 9 2 +11278205567: 765 7 7 490 8 724 36 +30585804: 367 926 90 1 24 +19147: 9 69 245 34 +10826820: 520 7 522 33 68 15 5 +12150: 81 2 75 +4889: 80 6 1 5 3 9 9 1 9 380 18 +120193530: 39 642 6 2 34 4 6 9 6 +207977: 10 5 6 117 977 +1324: 4 66 5 977 +129600605: 2 5 4 331 720 7 5 3 252 +33300996: 925 36 93 6 5 +1551665414: 888 8 1 5 7 569 8 3 1 4 +1281554136: 7 62 90 6 837 487 +121034377174: 6 71 2 103 953 6 763 5 +7706354167554: 7 539 475 3 878 43 9 8 +17506596: 29 6 1 59 31 8 327 5 4 4 +413531: 9 1 19 33 2 86 9 8 899 +20895: 3 77 9 7 8 3 4 75 8 6 1 +408404: 44 7 1 327 6 3 62 9 4 6 6 +10722: 97 6 5 6 6 3 3 4 4 1 23 8 +996: 1 7 5 965 1 6 7 5 +507325: 6 83 5 88 25 +29347686: 4 2 89 9 424 8 4 1 25 8 3 +1356080: 3 129 876 8 4 +518639: 3 9 4 5 3 7 168 7 7 9 2 5 +68790276: 4 74 115 2 1 6 7 9 71 5 4 +27608836421: 74 23 112 303 478 2 +1866792852: 9 2 6 5 2 6 7 291 57 5 4 +3227072784: 34 858 526 57 912 +408841: 8 6 833 2 5 72 2 3 7 56 6 +625: 82 77 6 5 453 +710281278: 493 635 6 8 6 707 9 6 7 +7947543334: 52 6 6 7 4 908 4 5 32 2 +13287971: 8 1 3 4 4 797 2 +920304107: 4 44 9 581 107 +145: 2 6 4 95 2 +1221276: 628 4 23 3 84 +3152042325: 8 44 183 5 895 +9004631: 878 46 64 31 294 +32755464: 83 7 9 62 4 426 63 +465434: 763 61 3 +117023125: 95 9 11 871 949 3 9 4 1 +5489531364874: 871 3 526 8 7 84 9 7 9 4 +227647935510: 573 82 158 3 17 95 +987686437: 289 89 64 6 37 +489723554: 580 3 84 3 554 +2980101: 348 83 916 94 9 +932: 38 4 82 1 698 +10720145: 9 9 2 1 3 913 6 4 31 9 38 +1582199043: 331 239 95 2 44 +4939116: 488 5 845 66 6 +12960: 533 16 6 791 274 8 +1131: 6 5 4 7 893 +3956427580: 63 628 275 83 +579603: 5 13 72 45 920 +120: 2 44 31 1 1 +707973546: 698 9 969 3 6 50 7 889 +82171: 81 407 764 +59078: 146 444 74 1 4 +372416: 43 78 364 6 14 +283157070382: 1 5 1 73 6 547 4 4 7 9 8 4 +127665181: 753 6 892 46 513 +3931604: 48 840 233 19 428 +2922: 2 2 6 42 9 304 8 2 +1628538200: 2 833 6 97 7 7 7 40 251 +18933: 3 5 4 7 2 6 7 5 3 1 870 +1983470022326: 85 1 1 3 8 5 72 2 5 6 97 6 +1518804: 47 883 650 38 9 4 +206771: 533 223 932 896 6 8 4 +14944382: 55 3 94 1 15 936 9 323 +420277: 87 5 9 133 987 7 3 1 +3451113: 75 46 3 35 778 +24826110: 973 81 9 5 7 15 +2273099665: 5 7 2 5 690 397 735 +2236642944: 64 6 9 46 835 96 79 68 +184786375236: 229 83 38 804 36 +3354043148: 7 93 846 609 8 +45799: 59 10 64 3 7 +29664054396: 886 310 6 45 72 6 2 4 9 +22212: 60 256 7 8 56 28 +320339168: 20 8 161 14 94 750 2 8 +207560639: 8 597 883 85 31 2 70 +5549006: 384 76 94 900 6 +638281767: 97 5 96 6 654 3 +14219040: 7 351 2 6 54 2 1 6 32 5 3 +80115: 11 581 67 366 6 1 2 43 +12344046: 78 4 2 8 21 2 117 74 2 2 +25789271222525: 5 9 9 70 73 86 67 5 863 +6248074: 37 584 3 80 75 +69253: 9 3 1 33 8 9 3 24 6 3 616 +5420650221: 45 6 1 20 6 491 4 108 1 +82962: 5 2 69 7 7 729 3 3 3 6 1 3 +28999: 604 13 47 +1065075928: 80 2 3 99 4 664 1 6 +127772: 77 823 401 75 2 78 +130939215: 691 9 6 84 21 1 9 8 +7660: 935 6 2 8 115 +451212: 230 7 42 6 19 +2247886690: 51 1 4 8 452 6 6 667 70 +1811035556: 9 9 82 5 899 51 79 56 +4109365120: 7 62 932 476 20 316 +17089560: 4 5 8 43 3 43 6 512 10 9 +22982: 8 55 52 93 9 +186: 2 8 3 28 145 +1377312127: 5 655 33 24 8 531 70 9 +24621407: 548 52 2 432 863 +57879912: 2 24 63 5 41 1 1 3 8 4 +9319523: 224 416 8 3 23 +210304: 4 162 9 9 74 14 4 +87226: 96 3 3 2 80 7 +2148130634: 20 77 642 3 22 34 +112797844: 60 1 687 151 8 44 +34875: 44 9 2 634 5 +704382941: 3 9 462 6 9 3 2 8 1 533 1 +514339: 5 1 4 33 7 +91172: 3 34 7 7 779 805 3 +10679126102: 7 7 410 3 2 99 8 671 62 +917320: 32 3 4 710 1 +55748: 151 5 7 51 5 1 9 9 4 2 6 7 +982512: 13 3 221 459 9 376 9 +434145: 3 3 8 97 8 99 5 6 8 7 61 8 +1472458: 20 5 4 1 64 88 6 244 66 +152: 78 4 8 2 60 +1241: 22 2 83 80 6 +2740059: 48 8 6 2 41 61 63 +528: 494 32 2 +4800: 57 138 26 79 16 +1322689: 9 4 96 268 9 +987420: 4 89 693 26 34 84 4 6 6 +6243825: 8 615 1 3 825 +2466861957: 881 7 4 42 7 183 9 54 +4914: 3 2 819 +11451: 94 96 3 20 51 +23964156: 78 38 3 396 54 1 5 7 1 +2163758589: 478 21 710 4 29 433 +5237550860: 7 828 6 229 5 9 43 20 +338665: 32 6 7 78 6 7 6 6 4 9 664 +178: 3 7 9 80 8 +2147171: 69 1 75 7 7 7 9 4 3 83 4 5 +1605002: 27 9 71 5 93 8 +256854564: 20 38 803 59 6 918 +291006063: 8 6 4 6 2 505 20 9 6 5 4 +3639475198: 42 13 9 129 862 +77155930: 76 88 27 59 30 +3946048: 95 472 44 33 4 2 9 7 38 +2160667: 523 1 5 96 797 +165008: 8 456 5 5 89 9 +18151435: 8 37 9 53 395 +5369239218: 8 59 8 9 238 1 215 +5049390643: 7 651 7 4 52 591 8 9 43 +56719056: 9 568 33 7 4 1 762 8 48 +451791000: 33 46 19 8 58 30 9 +2603596800: 7 779 8 629 668 640 +1242803851704: 891 9 58 20 5 69 1 703 +19728171: 543 5 4 9 17 1 +726115: 7 1 2 3 336 5 20 5 2 6 9 +197421: 4 7 7 4 80 345 2 594 +342622733: 48 235 81 630 7 733 +611736748: 972 247 91 97 28 +5709688746: 6 8 20 6 8 8 7 9 84 59 93 +26935: 8 7 13 267 9 3 1 1 51 8 9 +1110319: 3 408 25 6 2 9 619 +1729: 728 8 984 9 +1516073592: 24 477 4 3 578 64 3 +10192: 20 38 5 2 +4199874129612: 658 8 64 668 724 9 7 +4463235120291: 949 8 57 973 5 106 91 +469476: 2 6 2 158 61 2 683 6 6 7 +5635257: 9 6 2 29 3 6 52 2 3 5 1 6 +139207: 1 870 2 8 7 +2768307332: 477 5 4 7 9 2 49 1 94 +115373519: 7 279 65 8 6 98 4 4 3 4 9 +13997490486: 5 7 7 1 5 7 570 30 9 3 91 +1680: 20 461 2 718 +1270: 135 484 80 563 9 +2821947: 4 6 5 6 56 2 9 6 895 7 3 2 +825506: 1 77 28 3 382 6 98 3 4 8 +393493259: 577 828 3 33 28 5 5 9 +7301408: 145 67 35 41 6 4 128 +63195971622: 1 51 6 633 5 3 9 9 4 3 8 3 +2782104: 662 229 7 52 6 +569: 8 17 537 3 4 +146904291: 20 7 785 707 297 1 1 +775581: 692 42 51 26 38 +72170: 8 28 8 22 248 35 +15580: 32 7 60 91 82 +15137565: 8 2 1 3 37 267 667 +4932150: 9 2 9 4 39 56 3 171 +25927855: 81 4 8 765 20 2 +79854: 7 1 3 7 9 94 3 3 20 8 9 6 +22979158: 476 9 3 6 8 327 70 3 4 +127781982: 47 80 5 268 28 30 3 43 +2102: 5 4 83 9 295 2 +105687: 32 33 13 4 70 +36448653989: 36 44 865 321 3 776 +170271265: 27 6 8 270 36 2 903 +14111307: 2 1 5 2 2 21 5 265 64 7 9 +34356195344: 4 966 68 794 9 656 +213840: 55 8 9 6 9 +919113216: 74 6 6 4 6 7 1 9 3 9 888 7 +4412885624: 7 500 5 17 9 7 9 85 27 2 +109: 1 4 98 +9371772: 2 2 4 4 2 485 26 6 1 8 3 +816: 3 41 43 9 6 8 +372878004: 997 85 440 4 +1080585: 731 342 5 1 6 9 2 96 1 2 +200215: 77 2 4 90 63 +618205474: 3 9 21 3 245 70 472 +814900: 76 13 49 87 725 +19021857936: 13 2 5 2 8 7 2 9 4 977 9 7 +7647520449: 4 79 5 9 3 5 3 83 7 8 3 97 +27673593644: 7 611 2 6 7 59 308 4 +5303585976395: 86 3 46 67 6 988 388 9 +4761: 2 4 8 7 2 +47095296: 4 969 5 5 2 3 2 3 8 3 54 6 +540397305: 4 55 983 204 3 734 81 +29687553: 92 4 537 579 6 81 +1323: 41 295 988 +7119955: 2 637 9 3 57 +25443072: 96 704 18 576 1 54 +5959: 9 725 10 8 7 +4114: 3 5 257 131 35 93 +82044355016: 92 332 3 93 95 4 7 76 4 +294366037: 4 56 11 247 63 33 5 89 +214663955220: 2 5 29 7 7 901 429 30 6 +3262: 50 9 16 7 +11457938: 416 5 486 56 2 +906440: 19 1 75 60 34 +2191342561199: 330 8 5 444 4 153 975 +437950713: 145 7 6 9 8 50 713 +246758: 92 9 297 781 61 +82810: 12 975 58 72 7 +7891: 73 11 578 +1255272: 125 42 9 81 91 +27973: 3 23 4 79 11 282 +68667: 678 3 6 77 7 +136624821: 673 29 831 7 1 +41550483: 74 9 55 6 58 687 853 +309186514: 2 3 6 98 6 545 447 7 91 +8249343115: 94 70 12 87 3 109 6 +399336: 62 8 11 22 226 8 7 +795786: 4 89 439 7 89 +298384: 83 7 1 7 9 42 8 7 6 2 6 4 +11562407: 6 9 8 4 16 5 1 5 7 6 240 5 +186661952: 9 7 274 698 61 +34885431: 387 508 56 40 3 917 +2067520: 89 16 841 7 910 +128753: 45 4 3 93 7 +511005: 8 8 43 857 7 5 +28633297: 78 29 892 3 97 +63180: 46 596 44 91 3 81 +990793851: 7 5 9 2 4 8 3 39 3 6 3 51 +16421139602: 9 67 3 6 4 27 6 1 69 6 1 2 +139: 6 8 91 +1649833: 3 3 738 902 833 +2671786336: 26 717 7 7 75 858 6 +10141397: 55 790 4 3 44 9 951 +2464139376: 734 563 5 9 31 9 586 4 +424715: 9 4 501 9 869 +81979110546: 910 879 90 54 5 +2986635261: 1 70 96 4 61 88 599 3 +2152893601: 6 9 1 6 2 97 85 492 8 5 3 +61426224: 4 3 85 8 8 978 +40496968: 3 1 5 5 9 847 49 9 7 84 2 +30897645282: 8 6 55 921 933 33 7 +22188546846: 9 8 2 40 9 3 136 7 4 47 +18083286: 2 5 4 78 1 522 44 24 1 2 +33589182: 5 36 96 16 43 533 9 46 +538: 4 91 7 80 4 77 6 +2803584: 9 97 9 7 6 3 73 8 2 9 5 56 +8723: 9 78 1 2 3 +52823506: 528 23 494 9 2 +53738020: 99 68 53 110 72 820 +205872: 2 71 5 5 2 2 9 8 7 1 855 8 +676868645553: 6 685 83 686 1 45 550 +193662: 5 6 4 8 1 18 8 5 929 5 1 2 +80168990: 2 8 1 1 20 8 7 4 87 8 55 1 +39364: 7 656 1 49 8 260 8 84 +5957812: 52 5 9 4 7 791 +10356: 79 4 63 6 12 +34261: 4 54 9 5 6 4 5 491 +749180: 23 9 137 676 95 797 +4663718: 6 78 1 474 3 1 743 7 38 +1925011: 40 59 4 814 715 +52506566150: 6 2 7 5 6 3 2 9 6 661 50 +8945777399: 6 7 90 5 3 15 3 15 2 39 9 +3028272604: 484 8 638 552 604 +188437635: 5 436 5 4 9 72 8 12 2 1 1 +181156501: 6 48 31 50 567 1 +325638624: 8 3 800 44 4 841 60 +8032850: 79 52 7 73 767 19 64 +433839131280: 2 1 3 3 8 7 6 5 454 10 2 4 +86385975: 69 36 1 1 535 75 65 +13686: 46 2 280 1 245 +1712014581552: 341 2 621 4 44 11 57 4 +1489310550: 78 449 9 9 525 +255151481: 54 51 1 27 5 18 69 78 8 +63232569: 23 47 98 94 16 4 569 +15505: 8 35 30 1 5 +489767: 5 960 102 89 78 +325626915: 395 6 8 914 68 2 9 5 1 +14129837307: 28 90 7 239 89 652 9 +764: 721 5 33 6 +4223: 7 463 56 919 7 +166163510506: 16 531 6 847 510 506 +587419833297: 3 37 6 882 9 69 33 2 97 +399277947: 31 8 927 7 664 2 281 +170242241098: 49 39 425 38 8 13 907 +5668108: 9 227 545 6 58 +203298244380: 6 69 493 315 964 +33496949455: 809 49 35 1 845 6 249 +501967675: 7 9 1 784 5 3 6 6 7 62 5 5 +1876910: 5 4 6 2 8 4 389 5 6 708 2 +2965650: 3 707 8 50 +118205: 95 51 42 2 99 4 2 261 +100089048: 8 4 2 70 3 4 4 7 825 2 3 8 +46834203: 9 4 41 9 6 135 4 +88282419: 44 2 282 4 17 +1181936466: 1 6 3 9 72 22 94 7 1 6 7 5 +16346: 8 7 4 86 6 +79124454: 6 4 6 3 2 4 20 310 3 9 2 3 +8135081494: 8 1 1 338 7 6 938 3 8 6 8 +333717154: 3 918 472 3 530 3 65 4 +58432: 3 900 2 8 64 +26363: 9 7 82 269 1 +2099820378: 443 5 948 375 3 +12057: 632 2 19 3 8 +147361111: 917 7 7 49 78 3 4 6 3 34 +1045885343: 7 249 6 853 46 +170369280: 87 4 7 6 24 2 46 120 +669944977: 331 46 44 97 7 +257509: 263 583 5 61 60 49 +1757606033: 258 4 7 17 2 3 67 4 562 +4072900: 6 65 918 216 4 845 +984: 2 4 77 866 17 +1530342088: 128 6 17 140 28 389 5 +171554880: 128 480 8 346 56 588 +1018072: 2 4 8 9 1 87 598 9 88 1 +2349979998225: 78 332 66 57 9 3 223 +3024234657: 64 2 95 6 17 41 1 48 55 +1515192: 621 1 29 7 4 3 +305325282: 272 33 31 91 61 82 +54685: 7 18 9 3 1 2 4 9 7 82 38 +71892: 3 9 69 79 98 9 5 7 93 4 9 +221909351484: 78 8 219 359 2 547 6 +799880400: 6 9 4 9 747 250 4 3 396 +26946: 2 2 3 8 1 9 4 221 8 3 4 6 +280535: 7 811 3 341 565 11 +7694: 11 699 3 +77108114084: 2 50 4 320 3 6 4 8 5 21 4 +2144050592168: 1 4 97 6 6 9 3 3 8 402 1 8 +514177: 4 54 6 3 47 2 5 4 4 333 5 +5795806: 49 117 118 +255481250: 4 121 82 997 25 +53713731064: 7 89 7 8 9 4 9 6 3 1 674 1 +3827: 2 64 6 38 7 789 +12069: 302 37 9 9 875 +26340: 5 40 49 633 86 5 +39004: 9 1 66 3 49 40 7 77 98 +199466019: 88 909 2 1 3 5 4 5 5 2 4 4 +94346225618: 548 1 5 879 559 5 7 7 1 +411053: 97 5 6 31 3 3 9 5 +15666: 54 4 72 2 19 3 84 6 +7685786934: 768 5 713 73 919 14 +2639: 565 1 804 487 783 +116657452: 5 5 29 9 8 4 9 7 2 3 5 2 +391689: 1 3 4 1 240 96 9 +20629030: 3 3 685 4 96 49 30 +92190575: 9 85 162 357 798 57 5 +200187465: 5 3 7 2 7 1 7 470 7 298 6 +841: 7 2 5 5 491 +2124: 3 593 2 343 +36610063992: 2 43 93 9 4 918 554 +114822786: 181 97 654 9 +10260285: 5 1 371 137 200 2 85 +16025920: 7 6 188 21 1 9 638 +17613507: 6 15 3 45 9 807 3 8 6 3 +239580: 1 83 310 2 484 +2027025: 779 40 55 3 15 +7115144510: 89 890 45 945 283 95 +3388245182269: 9 89 846 679 7 489 54 +1595992599927: 2 85 10 6 3 933 92 6 1 +4531547: 93 5 6 1 1 6 118 8 7 20 +789698706: 635 9 658 6 35 6 +1433136093: 4 9 64 27 5 818 750 93 +424116828954: 580 43 483 918 741 +139600188: 516 991 3 91 +120808840: 9 9 9 7 851 564 6 7 1 7 5 +10581: 48 19 1 673 786 4 +82117538: 5 1 79 33 5 9 94 63 +27964789: 21 257 656 987 4 86 5 +956: 9 35 21 +3163734: 554 79 833 6 1 +583: 3 1 9 571 +1161556284: 3 427 5 9 8 1 4 6 9 73 1 8 +605316855: 867 9 37 65 29 +7787780235: 7 9 6 382 7 41 5 303 3 +1267497: 2 13 7 3 400 6 4 2 3 2 4 5 +21273569: 96 695 55 78 5 4 337 +5218526406: 700 35 710 88 30 8 +6422539915: 8 896 896 8 109 2 18 +7471037503: 965 9 959 897 2 746 +1760697625: 5 2 7 60 697 623 +104951442: 954 22 4 8 3 7 2 1 6 59 +796965533: 29 3 4 34 4 7 2 84 5 612 +2637180: 90 25 49 6 78 +65441892692: 6 544 18 92 692 +2055416: 63 303 62 48 3 96 2 9 +3726049: 8 88 3 84 154 481 +192424: 9 71 8 248 3 8 11 21 8 +114575369: 387 925 73 32 9 +730: 4 4 2 66 8 58 +894217550: 565 989 8 801 6 8 6 5 5 +126551425: 2 371 131 652 97 385 +4561: 4 8 5 116 8 9 3 31 5 1 9 2 +85412348: 773 3 9 3 7 7 1 79 6 8 7 4 +8653448: 6 989 27 31 1 6 9 2 +38808424190: 10 485 93 8 4 302 4 8 +8051: 3 80 97 +5219: 974 114 4 8 15 6 830 8 +15324: 90 2 82 4 560 +6746536845: 70 878 8 8 711 45 +1191528: 1 6 289 260 72 +177897089474: 8 7 68 8 555 43 75 51 +2678692: 267 869 2 +651553: 2 2 6 2 18 1 9 352 69 5 8 +143: 92 7 30 8 6 +233481: 3 602 438 3 900 4 44 +230845835: 5 225 796 1 45 4 829 5 +616135338477: 13 868 46 1 7 6 91 479 +19341080: 48 35 4 50 1 3 567 +8588906: 478 3 6 4 93 2 8 147 7 +885519043205: 790 76 118 4 9 40 71 3 +3872: 5 3 226 482 +3514395790: 5 2 3 9 3 3 5 8 95 741 49 +53662: 55 97 1 5 97 8 42 149 +5088: 26 4 48 89 7 +359229: 1 437 12 8 29 +36437462: 7 3 49 13 936 1 4 4 +86296: 3 1 6 5 5 2 2 2 553 7 21 +131253470: 201 653 47 2 5 +5445324: 2 10 5 508 9 9 5 958 24 +60870634648: 5 806 8 72 8 4 9 472 +16988: 2 75 261 41 137 +53595: 45 936 8 6 12 2 7 9 +922311575: 184 462 315 5 +6210: 161 3 43 3 2 +23761847403: 8 1 238 9 33 7 23 6 6 7 9 +69625: 9 10 6 7 47 2 458 7 2 +27763: 3 23 9 41 1 747 8 4 3 8 8 +3052647: 5 65 438 4 647 +3381704: 59 5 1 164 9 4 206 1 3 2 +4970: 5 21 47 6 31 +118: 98 2 4 8 6 +8316014: 1 971 19 84 13 +3465: 138 5 10 32 2 1 2 528 7 +3530332260: 8 7 2 767 910 9 +12063293616: 6 4 5 62 1 2 86 1 7 1 5 16 +5536: 7 37 87 16 +1179238531713: 815 95 78 651 222 +27708: 2 7 175 5 528 +3879901: 3 746 69 51 75 1 +5067983: 5 3 3 4 154 1 12 5 3 608 +42455989: 4 9 9 30 5 7 1 794 7 8 +359560160: 5 425 56 10 41 16 +5120: 493 7 13 776 880 +87496046313: 910 9 1 1 95 5 5 4 6 315 +60686: 319 5 2 38 +106937025061: 9 276 5 827 3 250 61 1 +29347: 111 257 503 2 315 +614534: 6 8 6 3 947 4 878 +24659: 465 7 51 585 2 +2296436: 635 55 832 29 4 +6149400: 80 25 85 641 50 148 +1924040510520: 80 6 72 5 6 5 713 93 +220087571: 55 40 8 757 1 +610462400: 6 6 1 7 40 934 76 5 +3531963: 3 957 5 41 6 3 +698721408: 113 4 6 6 9 4 4 8 8 9 4 4 +5148269: 45 880 6 13 191 +628: 141 1 78 192 199 18 +103117571: 91 12 994 95 11 +1484996971: 716 768 99 697 1 +20880: 4 3 58 5 6 +7404612: 79 7 1 86 12 +30842169828: 6 168 3 1 5 1 697 4 1 87 +59759: 79 5 6 47 19 3 7 7 1 8 7 +38429118000: 91 49 91 6 4 435 809 +318576716: 3 44 1 9 815 98 47 7 94 +5897: 7 8 397 29 4 2 4 8 3 8 5 4 +4722: 46 4 82 8 614 +193939725: 6 390 296 280 528 +7908668418: 5 9 3 75 98 4 352 781 2 +1080: 6 9 96 5 525 +78879: 33 42 3 45 640 2 157 +16555109276: 8 3 2 1 6 24 9 2 9 1 346 6 +46600957875: 2 3 7 38 5 61 3 784 7 28 +619697449: 19 1 2 6 86 5 77 1 8 8 9 +17149600: 8 67 267 992 50 +90: 2 2 1 2 9 +567900: 2 59 815 6 2 6 4 9 8 7 9 +179229819: 2 56 7 298 22 +5464512: 1 411 62 80 6 6 7 9 2 8 9 +318552570: 7 325 37 14 7 67 +7281: 1 904 8 35 6 +36284: 36 263 21 +146: 86 1 60 +960991455: 9 60 17 3 4 787 442 4 9 +1636416607: 85 559 205 6 4 7 7 +7640592: 1 6 3 493 738 6 7 1 7 57 +61572395640: 6 1 85 2 1 5 5 43 9 345 8 +316803329: 70 7 6 45 1 1 974 4 6 5 3 +119040: 5 46 43 4 3 1 7 273 2 6 4 +102523960284: 854 366 3 1 3 6 8 8 6 5 4 +1796198: 914 5 3 7 791 92 89 +91670: 66 824 103 +4758: 7 59 9 4 10 498 +2932560: 12 2 1 8 7 6 64 8 1 99 60 +2466642: 24 66 642 +2516: 4 49 3 3 9 37 +39268: 8 49 60 8 +388603: 476 815 639 16 8 +286225867: 21 6 106 25 867 +111798479: 4 31 144 6 3 831 8 4 95 +4432: 1 4 17 4 85 2 4 8 +76038195: 99 3 77 68 7 42 5 527 3 +75741848: 5 40 5 8 2 9 9 1 3 8 7 91 +3223727766: 5 7 1 3 9 7 85 4 1 9 301 4 +259448: 5 147 5 85 2 198 +11318777470897: 4 8 262 41 9 412 9 95 +50547: 4 1 95 21 8 7 97 975 5 +125447831: 32 60 7 651 1 32 +3164824079999: 580 8 12 8 4 860 33 4 6 +621945: 497 283 33 9 85 1 +126774605416: 74 573 297 3 17 6 +12802698: 73 40 81 474 48 9 +6289: 5 1 57 37 49 +22886763: 68 840 67 29 9 5 8 +45506381: 408 531 49 3 70 2 9 +1086077699545: 15 29 686 9 71 545 +96330: 9 7 8 569 735 1 +26524275: 873 51 28 652 17 9 7 8 +17287261563680: 882 49 4 615 63 677 +488039: 4 8 6 3 59 69 7 4 8 8 9 95 +2937672: 82 1 2 4 6 243 394 18 +2991816576: 6 751 2 6 31 6 56 984 +442230660: 1 60 226 6 19 276 +93051972: 368 1 280 71 9 73 +1160: 7 5 131 740 211 +4941982155: 81 61 9 82 14 3 12 +36760: 5 4 5 64 655 9 4 280 4 5 +5418: 3 3 25 68 7 3 1 2 6 +86247005055: 35 1 8 636 8 6 737 29 5 +190642: 5 346 9 8 3 118 3 52 8 2 +434695950: 2 846 36 7 4 4 7 51 3 93 +1911065788: 195 980 6 578 8 +25555915: 57 3 8 73 7 11 524 38 3 +95100: 6 5 8 39 2 4 5 987 4 7 3 6 +28837000: 1 8 97 1 8 584 9 9 4 250 +505569315: 543 931 35 519 1 796 +41223: 6 687 2 +901: 21 6 4 870 +8637229: 991 585 548 75 1 +163576: 162 96 287 60 5 75 1 +962371163023: 213 860 25 83 1 5 3 15 +109350192: 7 57 1 7 9 1 405 258 4 6 +16613281652: 7 383 8 1 85 624 9 5 2 +9596305077: 6 70 5 8 7 401 2 2 6 6 5 +17875933357: 644 63 9 881 5 7 5 8 +89783: 9 6 6 2 15 96 503 +27300689: 3 5 64 1 38 5 2 7 838 9 +764541238248: 9 4 6 9 6 7 1 654 78 1 4 2 +658436: 86 66 2 270 395 4 8 3 6 +8419432: 84 1 94 18 4 8 +859023: 1 9 7 7 3 50 858 8 5 8 7 9 +14951976: 266 30 48 344 39 +59478: 38 2 212 80 +83264: 76 8 3 957 5 +239182: 8 191 31 1 2 1 6 +1108645374204: 8 6 8 4 2 388 3 2 93 20 4 +12300944: 61 5 4 1 83 5 2 5 8 8 2 5 +7204006: 2 90 4 249 145 3 65 +258603731420: 71 834 6 2 3 2 1 3 1 420 +3464130: 86 4 2 41 30 +2125224: 5 812 18 2 9 96 72 +15015078406: 175 858 78 358 49 +17380390: 49 358 9 7 9 41 4 8 8 +9550084: 18 829 8 8 4 +20665420: 9 9 7 3 92 1 2 1 580 6 3 8 +7411523885: 223 3 68 4 152 38 88 +1106464: 389 45 53 32 71 +1180722080: 478 1 245 6 5 2 20 503 +3184109157: 87 602 2 6 770 51 50 7 +113071859: 7 540 22 3 2 29 7 9 2 6 5 +868: 3 7 8 4 35 4 3 7 7 5 283 6 +2153328173529: 951 5 9 452 173 529 +6349117323: 4 62 3 81 5 6 455 174 3 +2309765691: 35 37 18 40 709 2 8 3 +7943: 87 81 26 869 1 +9289401: 7 6 581 2 342 +1562470: 3 4 252 17 182 +3575975392: 3 3 903 216 8 44 +2171436: 21 3 1 20 4 2 5 2 9 8 1 24 +46506582: 95 679 6 5 6 491 88 +136519099056: 8 975 9 571 92 81 3 +2390175: 94 611 15 48 45 5 +8295222: 768 5 8 45 6 73 8 741 +20445495: 61 85 20 785 7 +27369402341: 999 9 6 6 1 8 7 4 2 1 4 95 +15647742: 99 92 174 30 9 +19937073: 36 6 1 2 6 7 20 3 77 +217602: 6 2 1 4 5 730 2 2 552 4 2 +1077224: 78 2 408 33 7 97 diff --git a/2024/08/code.py b/2024/08/code.py new file mode 100644 index 0000000..66a88bf --- /dev/null +++ b/2024/08/code.py @@ -0,0 +1,87 @@ +import numpy as np +from pathlib import Path + + +def pairs_from_list(array): + if len(array) == 2: + return [tuple(array)] + return [(array[0], k) for k in array[1:]] + pairs_from_list(array[1:]) + + +class AntennaMap: + def __init__(self, filepath): + with open(filepath, "r") as filein: + self.map = np.array( + [[ord(c) for c in line.rstrip()] for line in filein.readlines()] + ) + self.xlen, self.ylen = self.map.shape + unifrq = np.unique(self.map) + unique_freqs = np.delete(unifrq, np.argwhere(unifrq == ord("."))) + self.nodes = set() + self.antennae = {k: np.argwhere(self.map == k) for k in unique_freqs} + + def __str__(self): + map = np.copy(self.map) + for i, j in self.nodes: + map[i, j] = ord("#") if map[i, j] == ord(".") else map[i, j] + return "\n".join(["".join([chr(c) for c in line]) for line in map]) + + def _on_map(self, coords): + x, y = coords + return (0 <= x < self.xlen) and (0 <= y < self.ylen) + + def find_antinode_pairs(self, freq): + coords = self.antennae[freq] + pairs = pairs_from_list(coords) + for x1, x2 in pairs: + u = np.subtract(x2, x1) + x3 = x2 + u + x0 = x1 - u + if self._on_map(x0): + self.nodes.add(tuple(x0)) + if self._on_map(x3): + self.nodes.add(tuple(x3)) + + def _border_distance_2d(self, coords, vect): + result = [ + self._border_distance_1d(x, u, mx) + for x, u, mx in zip(coords, vect, self.map.shape) + ] + return np.min(result) + + def _border_distance_1d(self, x, u, mx): + xb = 0 if u < 0 else mx - 1 + length = xb - x + return length // u + + def find_antinodes(self, freq): + coords = self.antennae[freq] + pairs = pairs_from_list(coords) + for x1, x2 in pairs: + u = np.subtract(x2, x1) + k0 = self._border_distance_2d(x2, -u) + k1 = self._border_distance_2d(x2, u) + for k in range(-k0, k1 + 1): + self.nodes.add(tuple(x2 + k * u)) + + def scan_prime(self): + for freq in self.antennae: + self.find_antinode_pairs(freq) + + def scan_harmonics(self): + for freq in self.antennae: + self.find_antinodes(freq) + + +if __name__ == "__main__": + filepath = Path("./example") + filepath = Path("./input") + + map = AntennaMap(filepath) + map.scan_prime() + print(map) + print(len(map.nodes)) + + map.scan_harmonics() + print(map) + print(len(map.nodes)) diff --git a/2024/08/example b/2024/08/example new file mode 100644 index 0000000..78a1e91 --- /dev/null +++ b/2024/08/example @@ -0,0 +1,12 @@ +............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............ diff --git a/2024/08/info.txt b/2024/08/info.txt new file mode 100644 index 0000000..13ddd23 --- /dev/null +++ b/2024/08/info.txt @@ -0,0 +1,120 @@ +--- Day 8: Resonant Collinearity --- + +You find yourselves on the roof of a top-secret Easter Bunny installation. + +While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable! + +Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific frequency indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example: + +............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............ + +The signal only applies its nefarious effect at specific antinodes based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them. + +So, for these two antennas with frequency a, they create the two antinodes marked with #: + +.......... +...#...... +.......... +....a..... +.......... +.....a.... +.......... +......#... +.......... +.......... + +Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two: + +.......... +...#...... +#......... +....a..... +........a. +.....a.... +..#....... +......#... +.......... +.......... + +Antennas with different frequencies don't create antinodes; A and a count as different frequencies. However, antinodes can occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital A creates no antinodes but has a lowercase-a-frequency antinode at its location: + +.......... +...#...... +#......... +....a..... +........a. +.....a.... +..#....... +......A... +.......... +.......... + +The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost A-frequency antenna: + +......#....# +...#....0... +....#0....#. +..#....0.... +....0....#.. +.#....A..... +...#........ +#......#.... +........A... +.........A.. +..........#. +..........#. + +Because the topmost A-frequency antenna overlaps with a 0-frequency antinode, there are 14 total unique locations that contain an antinode within the bounds of the map. + +Calculate the impact of the signal. How many unique locations within the bounds of the map contain an antinode? + +--- Part Two --- + +Watching over your shoulder as you work, one of The Historians asks if you took the effects of resonant harmonics into your calculations. + +Whoops! + +After updating your model, it turns out that an antinode occurs at any grid position exactly in line with at least two antennas of the same frequency, regardless of distance. This means that some of the new antinodes will occur at the position of each antenna (unless that antenna is the only one of its frequency). + +So, these three T-frequency antennas now create many antinodes: + +T....#.... +...T...... +.T....#... +.........# +..#....... +.......... +...#...... +.......... +....#..... +.......... + +In fact, the three T-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! This brings the total number of antinodes in the above example to 9. + +The original example now has 34 antinodes, including the antinodes that appear on every antenna: + +##....#....# +.#.#....0... +..#.#0....#. +..##...0.... +....0....#.. +.#...#A....# +...#..#..... +#....#.#.... +..#.....A... +....#....A.. +.#........#. +...#......## + +Calculate the impact of the signal using this updated model. How many unique locations within the bounds of the map contain an antinode? diff --git a/2024/08/input b/2024/08/input new file mode 100644 index 0000000..61767d0 --- /dev/null +++ b/2024/08/input @@ -0,0 +1,50 @@ +.............C.7..................G..0...y........ +..................7................C.............. +....................................0......W....y. +.......................................D..W....... +..........u....................................... +..................................4.......D0...j.. +.....................................D............ +................O.....C................G.......... +............F.....................C............... +......u..........F.................4.......y...... +..........X..........5....4...........1........... +..........F...........5X...................3...... +.............F.............................j.3.... +.................u..............X................. +............................7..................... +.................................................. +..........................5.....j2.........4...... +....d.....................y...................j1.. +.................................................. +............................Y.e................... +.................d...X...............J...........e +.............d.................................... +..............................Y..............1.... +.........................................Y........ +......................W......8..f...J.........3... +.......w.............J............................ +...................................U.....f......e. +.................................Of....e....t...1. +.......g..........d......s........................ +................G................f................ +.....................................O............ +...g........................T.....U............... +......................s..........T.............G.. +................................s.......8......... +.....9........g...........o...U............E...... +............g............................t....o... +...........................................6....E. +.....................s......x........6....E....... +..........w.9................x............t....... +...........9........w...........J.....6o.......... +.............................................o.... +..........S................U...................... +.......S..2..........c........T.O....t............ +.....2...S.....c...................T.............. +..................x.......................8....... +....9............................................. +...wS.....................................6....... +................2........................8........ +.................................................. +.................x....c........................E.. diff --git a/2024/09/code.py b/2024/09/code.py new file mode 100644 index 0000000..46798ee --- /dev/null +++ b/2024/09/code.py @@ -0,0 +1,85 @@ +from pathlib import Path +import numpy as np + + +class HardDrive: + def __init__(self, input, verbose=False): + self.volume = self._arrange_data(input) + self.du = sum(~np.isnan(self.volume)) + self.verbose = verbose + if verbose: + print(input) + print(self) + + def __str__(self): + a = "" + for i in self.volume: + if np.isnan(i): + a += "." + else: + a += str(int(i)) + return a + + @staticmethod + def _arrange_data(input): + lens = np.array([int(i) for i in input]) + len_mem = np.sum(lens) + vol = np.zeros(len_mem) + + i = 0 + s = 1 + d = 0 + for j in lens: + if s > 0: + vol[i : i + j] = d + d += 1 + else: + vol[i : i + j] = np.nan + s *= -1 + i += j + return vol + + @property + def reverse(self): + a = self.volume[~np.isnan(self.volume)] + return a[::-1] + + def frag_sort(self): + a = self.volume[:] + r = self.reverse[:] + t = np.isnan(self.volume) + a[t] = r[: sum(t)] + a[self.du :] = np.nan + self.volume = a + if self.verbose: + print(self) + + @property + def holes(self): + (i,) = np.where(np.isnan(self.volume)) + d = np.diff(i, prepend=0) != 1 + print(np.diff(i, prepend=0) == 1) + # TODO get hole width! + return i[d] + + def clean_sort(self): + self.holes + + @property + def checksum(self): + a = np.array(range(len(self.volume))) + i = ~np.isnan(self.volume) + return np.sum(self.volume[i] * a[i], dtype=int) + + +if __name__ == "__main__": + filepath = Path("./example") + # filepath = Path("./input") + + with open(filepath, "r") as filein: + data = filein.read().rstrip() + disk = HardDrive(data, verbose=True) + print(disk.checksum) + # disk.frag_sort() + disk.clean_sort() + print(disk.checksum) diff --git a/2024/09/example b/2024/09/example new file mode 100644 index 0000000..f96c390 --- /dev/null +++ b/2024/09/example @@ -0,0 +1 @@ +2333133121414131402 diff --git a/2024/09/info.txt b/2024/09/info.txt new file mode 100644 index 0000000..b9cbca1 --- /dev/null +++ b/2024/09/info.txt @@ -0,0 +1,72 @@ +--- Day 9: Disk Fragmenter --- + +Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. + +While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help. + +He shows you the disk map (your puzzle input) he's already generated. For example: + +2333133121414131402 + +The disk map uses a dense format to represent the layout of files and free space on the disk. The digits alternate between indicating the length of a file and the length of free space. + +So, a disk map like 12345 would represent a one-block file, two blocks of free space, a three-block file, four blocks of free space, and then a five-block file. A disk map like 90909 would represent three nine-block files in a row (with no free space between them). + +Each file on disk also has an ID number based on the order of the files as they appear before they are rearranged, starting with ID 0. So, the disk map 12345 has three files: a one-block file with ID 0, a three-block file with ID 1, and a five-block file with ID 2. Using one character for each block where digits are the file ID and . is free space, the disk map 12345 represents these individual blocks: + +0..111....22222 + +The first example above, 2333133121414131402, represents these individual blocks: + +00...111...2...333.44.5555.6666.777.888899 + +The amphipod would like to move file blocks one at a time from the end of the disk to the leftmost free space block (until there are no gaps remaining between file blocks). For the disk map 12345, the process looks like this: + +0..111....22222 +02.111....2222. +022111....222.. +0221112...22... +02211122..2.... +022111222...... + +The first example requires a few more steps: + +00...111...2...333.44.5555.6666.777.888899 +009..111...2...333.44.5555.6666.777.88889. +0099.111...2...333.44.5555.6666.777.8888.. +00998111...2...333.44.5555.6666.777.888... +009981118..2...333.44.5555.6666.777.88.... +0099811188.2...333.44.5555.6666.777.8..... +009981118882...333.44.5555.6666.777....... +0099811188827..333.44.5555.6666.77........ +00998111888277.333.44.5555.6666.7......... +009981118882777333.44.5555.6666........... +009981118882777333644.5555.666............ +00998111888277733364465555.66............. +0099811188827773336446555566.............. + +The final step of this file-compacting process is to update the filesystem checksum. To calculate the checksum, add up the result of multiplying each of these blocks' position with the file ID number it contains. The leftmost block is in position 0. If a block contains free space, skip it instead. + +Continuing the first example, the first few blocks' position multiplied by its file ID number are 0 * 0 = 0, 1 * 0 = 0, 2 * 9 = 18, 3 * 9 = 27, 4 * 8 = 32, and so on. In this example, the checksum is the sum of these, 1928. + +Compact the amphipod's hard drive using the process he requested. What is the resulting filesystem checksum? (Be careful copy/pasting the input for this puzzle; it is a single, very long line.) + +--- Part Two --- + +Upon completion, two things immediately become clear. First, the disk definitely has a lot more contiguous free space, just like the amphipod hoped. Second, the computer is running much more slowly! Maybe introducing all of that file system fragmentation was a bad idea? + +The eager amphipod already has a new plan: rather than move individual blocks, he'd like to try compacting the files on his disk by moving whole files instead. + +This time, attempt to move whole files to the leftmost span of free space blocks that could fit the file. Attempt to move each file exactly once in order of decreasing file ID number starting with the file with the highest file ID number. If there is no span of free space to the left of a file that is large enough to fit the file, the file does not move. + +The first example from above now proceeds differently: + +00...111...2...333.44.5555.6666.777.888899 +0099.111...2...333.44.5555.6666.777.8888.. +0099.1117772...333.44.5555.6666.....8888.. +0099.111777244.333....5555.6666.....8888.. +00992111777.44.333....5555.6666.....8888.. + +The process of updating the filesystem checksum is the same; now, this example's checksum would be 2858. + +Start over, now compacting the amphipod's hard drive using this new method instead. What is the resulting filesystem checksum? diff --git a/2024/09/input b/2024/09/input new file mode 100644 index 0000000..804a177 --- /dev/null +++ b/2024/09/input @@ -0,0 +1 @@ +2342355037325141317463378198937791335317242410313218262273795125985343795279819494775178541788833550485457382583412354802986269996587221394031114274539291207192239390827242297152941360429691446457534596913129468114142883398878232382768292699269885947485147579359413692885924966099379930461584316843187076875248284699889599704741917740244338628164316844844331324331871343274081985720575515857254827782436040681428948293107721897514322370167220104777146149591877912441916929298574397535349781207376296573822976417135857030187735388262249234724788906272974995423898603161777386641672476040949695907963706177295842733276657657825179817948771132293073733776699799706629348957137656935893351965501529453099823357626127317116269433496950867120579311704278589342821330474085966662216586194049956912924412498195764186335032471390497142697027132177364296267551539193773384912896552170641233781552543176172023156644671879378136305695752728409595571672571058432057943721123029207176973567154970607411979122639510201272666216703048281067707112716419582526872026256890166683778978603134161610266375382364769913921685296952601221101112749098501253284725611192661721884288173287994889173212879273803934173337865273537162999548843856586466311956143871759444818293961516158544796621525556214814788163699331491092598276257473786926508564151152792564909646796464669634114092673978338959649234513892537490891149572392194554201294261253629755308733439155931698135373828629674512145237544717869379525486968850782669944540504716103655144427534521244872972679256064228117341030434069991184759953649264992865799383282359325054248138614546728591526673262652502718733584653388564342239830641919177625841950941814345527349058784443819968224093441140957274929951934721714559725643972047942517542957987194989731958360888440766233203716259644799766669758334295228174995320804067771937854815602773693684998261343493208466289382749693951561611321302918655625294830699460573418279655835843143967268287222413144554314030995230425711443053522614713253857321469516773288321270878989248731838399787268792439696475106380216435332950667451575419623890541873678014603864686383323774132683208782569071435849752051507923282080182469592993912839627077272620702678352670813625517146317427302849452377618516313086546060712782307729798760857628507413392616531089676663962569833010947796693172595973403546534322917963606876682576331842746024944987896335688973344882382578783656998237333985801094571035397629812534726849205167356281424670664682511512656777505681251416887622396463335394593428259084816045718281681116363328313446543587206298618068603171534211465584696711503862742568707519951648473310829168339995236980808838923010872155966990615018483833516625123562723828999637579724809993479252965494428985533014478182635254337126825796198021866916106877382218273966473095218393214462503071257574395652871775395614814321568782898477853652419153984975274974947117363394917675527436262590489076543363279695221796563827364662952614445777209759927331453540383922235853127583793584298165474528784750518298676245529532851160325267957488918743459119411699541964137691593735433449398555217917764967824444762483205949739777723237484131746862373339918743622934485861269760746660323042749479334570642811985665997987832243295532718438119645256362955397611839602033702612498833523960693869929997143720959587387352934399635027112631344298267138116847795961442552771340362169729695502850997288788791854289767182654715306691199057901457691116172579586342884831847946753620645467691746287446823569849716896568136295971946229943219992392548204340157245885097758165425257159699328346595377304034567875447284471369564090329463639521907865748835993929139293808062923772913679471910702675424413606674753041587516261819846388129960801717411311949352235021533410235233742686462012939778866067877918271386425338237324408688666110866876893769438144116121477792836276374451588574789513126893942873343278814916406559442198471569883576393486693627415710699063798719558436298047526772783062107145857353698128797454588766499922186218739681694856816431679771563774428094553457121287996586441010969699159018842451629494547438828035911936119129768433239489575934264496104867239848449183916364597074181176634433813629949079334118246638378159321716155346407779648244224034984510233346606271666684819712522772146073647122847213665876609120332392655570241696124871925882738787268448418117796372566137308866429299805855973477805154811321393257269525743750563027257791692884376771326048695748943223616886811350627373736963602236398964303273541686712089799555658122556671326678425716165510399594735055552767766216942415607712742721505525945621458110437756121569609883449529915438467978252754924870335274623344466225216885837847463978925436603525774093804950957340846456918011556597914054113581347036562596248840994392947663738355236263732655833811302511674823349364318295462061124321948779339473167043964944502160416032615861918446602276766957633917766774176260724596206368804692581195428041133635975125804315548697792613672783645871548429706977137817268683856665235441489762216348774861466980879010892873221990526188166450539472156173943479139077403337686568311898818963491194153041885714943376351226352469967726517898427248685070354973922380427471224094674429283083289951741165446581528433583931898584113294479472265529355885978366544255124792213275721722558246771098247528533298703074201489918436258462276268926867136244754394461354303360812157287575297874569333394886318667277164509826417952721710104049969790602353124980988823289286431370929997763486493164409564517474792562235336256912686977292023228142954988171711341764625588566269536354246332801713519341965781946474687577958185823896397240141930949431826350862358779818637858638118737985709641175783565121169323951564418656323021694549814025264650785075717596399986238651533492673177901845964614897516166937508040667849914379227715694680429829919723136933186494392027908036588799282833996874294886756662207546122067893345722214313378293284361919738131519261854168731699233834675146535714941445313819196160303838521288412134607047419115548469931481193780826985266111628986844952115926608099749758535322314323363776166687934346848724303516767859506518157896732478843257553815674710129724385145236378206117648199746419483177401387708382941328604391659330956592751512799361663061438641739875858969731533329661366123485452286526674861265565543466772087961911667478112423588921124276851446791593479360442360661212847166121691558898147344964670779344671551191011613292328580285092906585752913973791728323993187528556605667869081201661158559433659389019669710993211501418623432958898496335572882706251373641973484485555672692338851543444223841438292463613187268676072754736747814793837799860173190105380937288226354602790874685294094794221354959347912976230511612782318974129627093775631975662317641705144118966889022115630246851741850636940184215681575179783717013799752748384646367226137923941823157223194935358542466283336872614911567197027817555264138145299489096893955525584714119977787122659404776437326641713589079553312431970264334954376879934577279802786702553271468272084324669785419793871926777148184825565496659634426102852753285736257225216259052648329406042756886518780644966765432147866887161998970814710751528987584917921297922396743998057992319804495167967983467716177399021843037386985343694397891706299525085199767807267545852951549732925596944579477643031267560784543244330748550335174256124728272537273893992907984229965933445493078668062523090488180282919974581957818615827505257924572299483454561285060801769155712218295607537432156156823218760624961496181579817718439537894865333628275733556842985479674208413418134857740529558645839379489198792486465841010207472998111792776311847902145621249866334433827578485917436235381698951592658959563385361185967776426431243274613379485514527255174185438877887318290334970582068928284529294137389566980822430229453149982132126246573501166602832688165783988972414964617157651478459377632338326249842114081623079357387704621257123189595707588122632344057374642522511266360563566853868904647259123979627125185421859782645873739384577939458404463242566301820873470614953793859557037586394294111597226593866237249368921422485926034335086162119507022471422465483322622433818728972851926552599634531419175283756176116764070409270498796306742343682693577232978219216156453387139152156563755987688249235727767317963269847628294936190191139323441384337794354215736649393523772671445629636922769336390473824425768306642423445267124242986585187838065679186795112168396431446853161946613565676797436931573488672805784823422879555657235856548392111923050471955302335609756868286132467395216743239403945772293283685371946735082739439706580131276523023953850918067997997568175165184375993831153737567535365404724297660761378322789759947175936932197163015336690426655859582553635489796267517133534934943582241589658899771385677883995131595581976625558372140433895929023154511886083268887188862384853774717537025507048281369414491388361628386178541386168518753604510633058314616516624533850764799726786845249793537954572589032287370893668829353229210218013912676585027477194526132846187478482554427137786388530476621908528792778317725699155377953505457889383959162606535126060825277578137432480968377467272752934816939883445852413217870175174685999386212869543365065765484297765587741192363746261408416187625506948445059561113739782772261803818335743558268941283498434564672575722471494276811147111706035551078465043857443873068544176416173165355752727412264251618979717465090259182353963867371727755767475381911273021129197414933998677492576823833773621451012955874813483973865473564457682542976648952924253766971321120776269486581193514732119466640346662145861955021659988218336661882785317186465189662873878187390647228891751871246898426313831795787576233246539208279418464363568691777807766799588894075782667504259712660215137405457209053781432614521797210199823582448468632963671901166587763114738453375282551132499494493598975454047868658614256952979732941721647232969724452103021543184391660969010734194352337383649145361104288898899297672203556389293329854552545271931518163297420497656892712828540609172169015638742967132353822607192671365218293315743886598411151554335132651935587512324447057335855649941852430806489778316839538203774529630627663666112612618712994382214412991612292638914614423482559447613835279233669663611848286487658555117432594114117175096809762646162632311599396418396556415172149537342851550788031383024459098785274358795723129206692507438976451896161187478101626506753778012104110717339489184803065986611352389519469848591468451288627716688261668306792203893606630462668296168151924901953979824873373742780493966205280995233766855729614744623932390362622206615172641225451799317863359658978343166346266263064563866173476952745652635471049295972408659907374663080501467584421363485514436692140824690349443755538818411524540826385554966528591912053566713986223768319412384863474649778121743134395155064603522102066341387424596546216729421143022268792641179712494436238798567425298979688632035999210296738167934803065493713496831576527376339586189589639703330829873777288388569747243446394858751455235626347978479816665795246529310423569414076122757896685145890578895959078186197237297849414669921972168257854384871269135928591952516987685431923194347387172486161825270985692815846529668655571128311834031984429469026297976845460152498643536266212467848493688385814895453686051626380642796207761134610768440614694699363421298898592455454636126506867585889681681518359984769613931863017979180836428946693857367733168157141183881321679707173513052382759412275715377411166592763945013358852569432759274927099218880982192793359608998454774394882407587478428642467242784116741178358682734148160414534443123429019851988255439122957687640339991587024354183186045937432389592266770746386976071293988509595282532335082959859259952508832946157181833832763444152872997487572354493122588884071256188632169151389216465825356745946728255419153481139964811291458206371384032811032424365367656896139321076127383646853705749877215759935498078229313127629827393225893882687368893767144358741826090357348151376674913621690429260909054251767918520133629945146464595437783478089929096462852531488742682579796785669192798383084405838325095201459132011786996557748811867788998704232844963593339878011835385551798951561787120638030747712899928821418982691593280652873214364147698392013433596813843542930875786241716375930429269135236651261394114198624708990956820903587298638889620472868149958202037618080619077394054953936321142647284182790226247613863269536895857117928566522224533859873765614825133551940528170834278406458931494866554661643609433715320941211414876463921625356419948551978167317354266964922243348554187388232954835821241707492588080639834638341936614298348149474782573741628332919234541486024205559986147558849535312143449878427331157398547213263168470682542611694302619833673743979123442351299183182616412689655336653653154336218212328366118562579463147264730977292299517239028764893609084699976493033761524633698991094583764915893231335968598858275379910707967932353968663478358417485967942718835755587968727968119131053868713338081191613359254441272308918234575378962863742678346949437915027932927216385444187385188162970791575625795819070148258268244911265226119229760404165737025451432461651691693927788979541423971443566357292823331902764406836163732321634457060492833364345343512388541744455848513567529514120777553772747325572641123959646566167443749688059404686538553986895747932405722721497587918786493777170833155666424747281319114327261889795531345927736511684845498625650306568981945215648335816579199937935725533484796307629881345926397976398806162513136844072407741129571425823123060546492659330736255585480388831576795515299674938587737264064207252138033429135211690713645981195968289389013267876406861719295246838959057411730265151126511945047188280796236245251305835197440893483364981539435755675437855482188628886835714285432383210887995515744406785446074359357205431115761406649754187353531557261293713393873267918515126614662156330765023749288449734456940555711468781221421813715989583332876706049967929465216116810815763843020747734259569997050118570102133641894552258926995345610899490166747415260123422369996335429628183466340145094948896225539265111993674903727646171556197577842692143608677222988323216941148489972683928774925558691719791367078499511672347399577986388851547333869428018343970824435141669862732733536568373555524851377552393689088813394466372794044168073559943263973908793452577549931307728438292886910905741739240394824788726952069428726253775162614852982613894647772406250381394317356766489686312144798337032501643177324998154126890933350318685614250187498413848363764234677179446336246756548681443669787987326525673906924973256217376987324973742166477298493906565185524533597379417955543462463336875409772453847837225668836679950354823617222949722396458125845536668922170531348587076492472379867573749499833302477302887886974306821369036327588444056146982745799139584517190742222308313486070771358525283718393404529757389793133617748161363127942207643807884597013473652504136239750838416545724255519873752592736624180481346997910382516181035805632133276683041536353937058829840776098492734829498691023545232581377759990984960399391422288888684938460913692187556369273243113602912616087844838349818902413757521472337369383513287405170455287251488436399512392354138819427254949399074835886391888929026608245873498877274422613523620796176124614918621108116162766395143548745705044858459376783839188677747101357642196291774455815762946679288222386312370693014594694426715481430609016726537693316809192839739865639192622936236768349136752528512361680404180528617423920412550284835478257895048243888768329216162464555955336968045447818942290623044372372951217366113132557748066603176206268832461857893647616711570131526477354137392612195426825678920586611943074537298262841759755307942532223118552676296559269576445152947123050519183749822874212944729142893268818233540313552969992751759818617857728608496239473921856761811324512135357444742716343624387892111545856759150621311989850754357547638768926993944932484876346679173338832309771505863769463195995194480665041928588299274617615505147481447188270456069169139794973908271693658294727766021296737382674797442832571272656987911912767219595961393257856486591711712349069356932808720577465219768754343755633371054483597788686968128801374568174807340379989412345695039493713355569755364485858884843265967382234872867467925763445739775886446498788285860439778866938589071716724578393874880874226385628158198451630835614114780716792202887487522694780628971887956244297869429715787117119613265535542284788348190277657626216919786831761393050163154144665131276626419883329486483801962713167562845622658267581414070735637157665379227704267904491168390966928799375177322674775198629836450968437309565385919552872217032348586686646322082193172603590244967807455282463772498283393311179383545323170238623593745253881551251697793753348377936887033501036514783514850803855659638228378917746735853562723855279937049156294291712328319295697393955712911234542534376229566654282617953226152605513689870714691864250289071626670259885307817956691663230147518311716894662703523378712661762334699915847406660276568995271984122508560455385695556695527149467267156402672479838438684747711683565274067877811254538512329451654329261159535756530893065299512208279133173148091991373187936134957634191636341775835267444632370299067203481676297439744137723739822722996627559264645517195206329287321335364132355372545777983739447767812871890932253379982276187807641543526491278212487416947175240188712536258832319353357661844296282907660829846717669636349401795525693486777735012285854931899385698327822718241528975548921316211757374437114723330983290625211617889596989878453786748757120758366872423381629115736481916415978506558998884484761909946197374416912623132645520929812732334278985366077226173322243945845763833847914744120511711841873718356682222533780503657902899317396386014896044414730875236977392658991306442169095142668851128997470782725614176763611367825459251135562423746243734904730444962712862992547344163587825246371693076726313437315893616436378689138484591993952443058946259466814715098666354912831468363136493548663442895957054799627489493714195971364442210822235373642398492997296306251984743135017833690744492133039568915622289369323643845119953119486825543555498567511578190141349248455122918224387883165111145137041986980216873633677613417937026418036663638233793325737958290287774418856458088607940883683531110191510631049285772749757239813847250141414976686737543319650761729724472924281404749228045328564555537834627379669166785743539667627921550326970683248363784435784525488708396585279299422838757566735412657262973402185246722545867205467219443515348161187487342388753591548832542512477983726757898555982663772626617549711627757457462932997656367533850829464812749644962561596731920954833799747192078789720152370664188285542383210265259859457643982443449126089646145464763459072404238228763644829665795141397789376944088821639517514488590635812475611569275324570806870673622918446911587183633328779336245288659466688999820289645188742828021149149137694488065575033168598487678838524739576768993445667543862111161567497779967986690939143148652373610119018808760212416996968696358945614438922636780707349259411311067272126579642318221993365298458416497136268402389444972201647567610998126491273125174299546336433968012109873646110515379726522699272805888123366707298108028487439239861642290472199962750199776716136191455166375875630919044652439602064357593186133188131466690167831688981933094239959983231232034111044847934367967251153227669637011571313723669235220707931699866663817391853559777171736158393598340925377192744863750182144949746388025602719582618464919207