From 2d5ce9ade1bf504f822ba0e0d3443425cda79889 Mon Sep 17 00:00:00 2001 From: d4rkr41n Date: Tue, 3 Dec 2024 16:18:24 -0600 Subject: [PATCH] Added 2024 and day 1-3 solves in python --- 2024/day01/README.md | 112 ++++ 2024/day01/input.txt | 1000 +++++++++++++++++++++++++++++++++ 2024/day01/solutions/part1.py | 19 + 2024/day01/solutions/part2.py | 25 + 2024/day02/README.md | 87 +++ 2024/day02/input.txt | 1000 +++++++++++++++++++++++++++++++++ 2024/day02/solutions/part1.py | 31 + 2024/day02/solutions/part2.py | 51 ++ 2024/day03/README.md | 70 +++ 2024/day03/input.txt | 6 + 2024/day03/solutions/part1.py | 17 + 2024/day03/solutions/part2.py | 23 + 12 files changed, 2441 insertions(+) create mode 100644 2024/day01/README.md create mode 100644 2024/day01/input.txt create mode 100644 2024/day01/solutions/part1.py create mode 100644 2024/day01/solutions/part2.py create mode 100644 2024/day02/README.md create mode 100644 2024/day02/input.txt create mode 100644 2024/day02/solutions/part1.py create mode 100644 2024/day02/solutions/part2.py create mode 100644 2024/day03/README.md create mode 100644 2024/day03/input.txt create mode 100644 2024/day03/solutions/part1.py create mode 100644 2024/day03/solutions/part2.py diff --git a/2024/day01/README.md b/2024/day01/README.md new file mode 100644 index 0000000..773404b --- /dev/null +++ b/2024/day01/README.md @@ -0,0 +1,112 @@ +Part 1: `2378066` + +Part 2: `18934359` + +[--- 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?* + + +] \ No newline at end of file diff --git a/2024/day01/input.txt b/2024/day01/input.txt new file mode 100644 index 0000000..dc26802 --- /dev/null +++ b/2024/day01/input.txt @@ -0,0 +1,1000 @@ +18102 93258 +34171 50404 +48236 60718 +10441 41669 +63428 45329 +42451 56834 +74881 39407 +32801 36101 +52771 79895 +41513 78731 +81076 52363 +87623 35520 +15259 96330 +57319 78241 +42758 41144 +80744 20357 +28199 55267 +22505 35520 +74707 74819 +67725 96130 +13883 35520 +87486 55267 +25070 30977 +10199 74819 +91803 75066 +60122 78266 +17884 61488 +41073 81666 +24778 15223 +46587 87276 +75477 82771 +78585 59630 +23143 20028 +67975 13674 +33304 70802 +19939 50051 +35520 52616 +73263 19938 +89352 99541 +65187 80938 +41347 35520 +64416 57744 +86648 22827 +91435 47131 +96712 38412 +89053 76476 +68596 31155 +22661 30518 +87094 22104 +10403 46003 +41029 68410 +62486 54054 +24752 47138 +59331 80259 +83839 84471 +19771 87508 +68258 73947 +69907 93126 +36611 87565 +69633 35520 +19461 20361 +43869 86799 +88115 13167 +27925 21142 +75724 33150 +14715 66772 +46237 88588 +22390 57154 +90584 66789 +89982 55267 +98196 93258 +83394 28441 +68840 50490 +21728 36730 +83742 60945 +43346 38412 +79097 84471 +13016 35520 +28401 41164 +18245 81634 +99352 39461 +33202 36444 +88303 14489 +95205 90462 +80929 97718 +18847 78535 +36538 10273 +40204 76019 +52395 80344 +62145 55267 +29945 74391 +99218 14416 +92009 42686 +83998 36730 +50338 81796 +43724 90026 +86537 33172 +89079 44444 +32728 41669 +60742 67245 +35894 42369 +66329 16357 +42434 19057 +65046 13593 +41778 42363 +62183 46290 +37564 10310 +46436 94358 +58111 74819 +13914 85272 +67992 46429 +42766 46993 +97620 79909 +12930 36101 +14208 62020 +41890 36730 +81680 21444 +84864 64563 +29905 72690 +35753 52398 +73868 35520 +17253 29006 +72538 88588 +77189 89503 +81736 18206 +33322 31658 +48157 79144 +28398 45304 +51735 83365 +42009 59880 +25466 41416 +52459 99199 +57747 36730 +12226 12617 +41445 33884 +15088 42664 +21076 99403 +24923 36730 +47057 87695 +14281 76662 +58163 75603 +41046 88588 +25315 52616 +88847 31193 +25550 35520 +37785 54965 +42166 81663 +36739 55267 +13289 58788 +95744 62866 +23230 41669 +89299 88513 +94591 57796 +19517 78347 +38689 71550 +55241 41669 +80752 85442 +24799 84471 +13063 55267 +27395 80539 +78086 41669 +49641 13167 +60112 63395 +57026 15781 +34007 29172 +49274 72405 +14926 96924 +54717 58045 +16315 22728 +90753 82631 +99446 13167 +51171 81263 +65577 51430 +59152 40932 +98558 41284 +60772 88588 +89469 93258 +78257 51498 +17794 63128 +17963 99564 +10250 12980 +11455 64655 +89464 78241 +68825 20389 +18793 81458 +78236 41669 +54490 94531 +16188 51392 +17889 41669 +88466 55267 +30083 84471 +83012 57306 +70675 81796 +13694 84854 +58909 38592 +40234 94238 +51671 81883 +91196 49891 +86378 92193 +81435 83848 +52846 38940 +96254 85424 +28810 35155 +57295 68573 +56262 94606 +70230 29354 +22599 10175 +42130 30343 +52701 99403 +62915 12166 +76676 88588 +92756 55926 +85607 84471 +59730 67890 +32152 56550 +83584 12212 +91305 52052 +92411 62866 +30000 24317 +48046 39809 +53235 93258 +58381 30343 +81243 39857 +46414 37480 +14203 19491 +94671 53889 +25932 74714 +15761 95661 +41032 87276 +95383 12977 +63041 37164 +62397 38420 +31632 80344 +73259 63756 +39665 53750 +80475 32801 +71036 88588 +72272 79144 +60444 94808 +62938 98520 +91946 39934 +65936 81849 +46418 56506 +75068 97162 +39001 52616 +41161 30343 +15026 35598 +42469 41669 +56940 80344 +14981 79323 +18795 70311 +51498 79144 +18298 39857 +57977 95908 +99404 90175 +16709 94746 +52847 17022 +19595 32739 +75552 54475 +56206 73676 +21473 79204 +92226 37522 +77631 41409 +32460 39212 +68228 89367 +93156 51665 +43009 54778 +14468 63363 +38918 43492 +63144 83443 +64474 99403 +59151 68155 +74740 84352 +46043 66174 +19176 79144 +80639 36730 +12346 18866 +32789 35520 +30312 13167 +90241 34021 +61418 95707 +52839 52960 +59507 11557 +51774 80344 +72851 31658 +21231 52129 +17825 67968 +48685 80344 +90363 14286 +32135 81656 +89692 93229 +71792 84471 +24754 91630 +15559 17945 +73777 62866 +73826 93258 +61029 10131 +21893 79844 +72680 80344 +54635 80344 +46537 96585 +28015 51978 +80768 99403 +52593 31658 +15701 83366 +97543 45838 +33327 55267 +60326 10669 +71666 68499 +68900 91751 +27686 40337 +39616 62866 +51033 37907 +25015 14676 +41682 19585 +79008 36730 +49472 47063 +98674 62202 +33282 84471 +59585 75619 +86450 58477 +14432 87276 +67623 18866 +84033 69700 +13957 40073 +55400 21005 +13167 36730 +34835 15933 +71718 58623 +95411 97681 +57118 94831 +41944 62866 +88120 62866 +11752 32137 +85462 36211 +85424 46228 +79713 80344 +16019 62866 +17655 38412 +26672 17352 +82553 76385 +23188 71537 +56490 39857 +46951 13167 +85961 13877 +51560 77830 +94957 52616 +27650 74995 +70629 73120 +25129 32171 +62148 48774 +44331 87276 +69734 37018 +21661 51261 +13612 82993 +90689 13167 +92312 86533 +98598 80344 +68752 41669 +30190 35520 +36730 50595 +52267 64296 +59707 65310 +80349 62885 +63683 45682 +74727 82966 +86012 81529 +39964 88805 +16119 69720 +33146 70138 +90376 97651 +22904 98429 +87159 29634 +23078 18154 +23361 32845 +71970 63128 +10411 92866 +31178 88588 +50980 27848 +45078 77661 +91447 42358 +71418 32868 +76636 78241 +30598 93258 +28434 38738 +40660 79275 +62848 99403 +28084 38612 +12699 59071 +59263 81796 +26439 62866 +17391 78241 +93530 45014 +45542 97173 +69388 13423 +80066 28361 +63149 95510 +27861 81796 +62609 28829 +78241 64755 +98783 53082 +21987 31658 +31758 18211 +21749 79144 +70377 52464 +65877 97679 +74993 57174 +53846 78241 +67812 39783 +32323 63362 +18461 91739 +38165 31920 +80422 39857 +43219 31658 +84785 30343 +54985 88562 +18275 62866 +54638 78780 +76547 55267 +15874 41010 +86965 36101 +97038 74819 +13828 44487 +21733 79144 +84471 16719 +26596 15857 +16529 28650 +25443 35348 +15059 43502 +81770 36730 +81309 78241 +35589 69602 +94630 35179 +53197 76827 +29523 66364 +46055 30993 +85203 60814 +39329 53071 +18663 32233 +50108 99922 +41019 98673 +89169 76809 +93556 52782 +69891 54164 +40270 51225 +82965 46304 +22455 40010 +41669 32801 +71630 15002 +48390 61558 +44783 78241 +59867 32801 +36112 31658 +81101 91237 +54551 96109 +20993 92021 +50680 38412 +63128 84471 +94509 80344 +10577 99239 +25724 84471 +17317 20799 +39300 76645 +76421 67643 +43817 20959 +75711 58027 +34480 35520 +64585 64739 +64685 99403 +43062 58999 +81760 88588 +63083 40045 +39425 36730 +17622 80859 +64617 36051 +59190 85424 +81175 97509 +93869 51498 +62866 61413 +26396 71626 +87276 98001 +79144 48463 +23812 31658 +31923 47911 +87102 81796 +40295 85346 +92002 66371 +62557 65288 +73197 53046 +68891 80787 +39756 37172 +19915 60878 +43089 32558 +30343 31658 +50332 66707 +26000 58109 +67720 82142 +41227 56943 +97647 47831 +76020 38412 +40485 84471 +16962 53016 +30066 28740 +31118 54102 +41928 99913 +82656 38412 +94155 34933 +52515 48131 +48519 45948 +64922 51902 +73451 81796 +31917 93734 +96992 56765 +60790 48526 +68218 75199 +80344 59642 +94057 47998 +74830 99403 +70462 56217 +76371 18624 +56899 90796 +92898 66333 +34979 72161 +37736 80344 +41607 32801 +48181 41716 +72333 26215 +13666 78112 +91781 85424 +77373 83784 +94719 94693 +65491 41669 +88464 47980 +98595 56821 +16665 57249 +42861 81712 +38767 65492 +31642 39581 +54565 86820 +51346 74706 +38258 81796 +35980 77859 +13015 61175 +79811 14561 +29887 12736 +48972 31658 +43907 40337 +15478 45373 +97895 52030 +93779 15247 +19906 88588 +69778 98196 +66203 63897 +91035 39857 +27450 63128 +11710 77533 +61760 31658 +50614 74819 +89099 87276 +75125 46470 +55904 39857 +76167 37911 +94908 47677 +58478 18866 +20475 37504 +21737 13167 +90464 99403 +12941 84669 +48793 62866 +60186 84471 +11894 39857 +55293 21637 +33993 76974 +47080 64256 +73306 62866 +95473 74936 +35272 59929 +20187 36730 +48764 59657 +65430 16092 +79522 28419 +98586 21238 +11131 97814 +15190 32801 +14978 39857 +83286 78490 +40748 81839 +25325 20040 +24813 58230 +52110 79030 +75599 95523 +23138 63833 +63416 65152 +13853 98184 +60874 80344 +32281 88588 +80353 72102 +24683 84471 +42421 38412 +75909 86850 +22940 36074 +80544 96507 +62292 58866 +98462 38182 +46560 56050 +87289 79144 +88955 15573 +70992 25439 +81256 38412 +28446 29484 +83121 95224 +16108 74352 +34016 37646 +55211 29561 +20806 87737 +17271 99403 +35249 76966 +25159 67894 +40337 58440 +60006 32338 +60866 38412 +66540 93258 +90000 58211 +57957 38113 +54883 80382 +65202 41669 +56318 22865 +43827 39813 +81395 40970 +69790 86084 +17754 55267 +92786 31658 +98085 88588 +50334 48963 +35482 58393 +32883 70992 +62378 14433 +99609 73135 +35356 36730 +78375 68903 +37024 13132 +24204 27308 +72637 38412 +17428 58766 +80886 18866 +66117 59583 +77402 72213 +66620 23574 +37470 26120 +56642 97207 +16039 99994 +23520 59100 +39995 75647 +31430 77373 +59277 16018 +77197 21617 +93312 84197 +81972 60483 +99910 79880 +83510 34604 +52934 99403 +60313 32544 +86206 62733 +32957 53708 +18748 59570 +34408 63137 +64561 95075 +89324 88588 +86562 99403 +34014 98669 +52477 54060 +82112 91468 +46837 51376 +42855 89033 +76285 10788 +48498 11016 +87628 95461 +25039 23870 +44726 84471 +36316 17593 +55475 12512 +40885 61324 +55982 41669 +28353 93258 +90070 87664 +92571 50972 +64040 77373 +66045 44321 +76075 47585 +69898 35520 +31897 78241 +45288 77373 +61402 40079 +43939 79476 +83915 87612 +51714 70302 +55728 61718 +19212 48853 +50471 15323 +11253 36730 +36282 61657 +99765 88588 +40255 84064 +65591 31658 +88588 30358 +53096 62672 +32485 52616 +90637 35520 +23957 55267 +15301 74819 +99304 38412 +42581 99633 +89403 78241 +88697 46405 +23646 81942 +82798 41669 +19417 72825 +99035 54991 +99372 77622 +49134 11067 +41732 49561 +69058 51302 +85817 52817 +80628 47979 +98869 18345 +21540 44446 +36075 62399 +74841 16533 +29826 68948 +74966 33155 +76789 33664 +42909 76884 +61686 93258 +65851 98787 +38529 64090 +64968 58698 +99647 70935 +49851 13167 +88523 38412 +92200 35520 +21926 55267 +85918 78241 +35092 80344 +39857 33948 +80393 59217 +97911 43227 +90571 35520 +48736 83686 +77924 63128 +18866 80344 +21299 74597 +81796 45742 +93562 96860 +89376 36730 +68027 75225 +13032 79144 +28892 57468 +96012 72691 +96357 90025 +93590 76769 +39169 81796 +69505 83140 +27406 79144 +45575 25412 +10640 69420 +42859 67773 +54319 76647 +36900 89641 +16622 73504 +55267 10781 +60719 75932 +63099 36730 +14798 31658 +89944 22601 +40221 55267 +75498 35601 +91475 36563 +23362 39524 +56739 81796 +57452 80344 +60950 97510 +78516 99403 +27941 62443 +27521 66529 +33707 88588 +93324 91799 +57954 78745 +10142 96525 +93400 79144 +10246 51708 +96780 80879 +90160 28886 +75452 68015 +51405 30788 +30558 43844 +80443 56573 +53073 55181 +23213 60714 +86395 98419 +26118 38412 +77828 81796 +83431 19529 +66085 56790 +87013 80344 +78095 27229 +92609 32801 +97658 96068 +97452 49425 +63195 95504 +22526 79144 +40153 79144 +77603 88145 +21804 26067 +70021 27010 +39030 20686 +44696 30343 +98142 54162 +18276 69052 +61036 14279 +89542 91528 +36218 99403 +59135 87980 +44366 61548 +73468 40559 +30939 26766 +66589 83054 +39929 63975 +25239 79144 +74819 40299 +77393 87276 +89793 74480 +70491 56646 +13636 99403 +58152 87276 +30693 19897 +31134 61607 +12324 35941 +67104 22474 +89552 84471 +96869 36730 +61641 42507 +92835 28786 +51442 41669 +40162 84338 +92491 16076 +11753 35520 +95247 79627 +11256 30343 +93258 41669 +24504 25813 +85713 41965 +19158 81796 +50458 41669 +48386 22205 +68720 90932 +36101 79144 +57165 78241 +22469 31658 +99737 14211 +58884 65158 +29461 98196 +86864 72295 +91962 77373 +93672 51538 +89453 83913 +86350 90636 +42288 98263 +17267 18583 +30518 55555 +76868 62866 +55662 44542 +31658 98196 +99589 31658 +64736 36101 +16281 62886 +32687 66131 +77273 83572 +52616 71835 +35719 12817 +87282 36101 +49495 17763 +41116 56436 +65977 31658 +87148 66523 +71950 99639 +93432 41570 +47256 24165 +60388 58593 +52721 87348 +46321 27970 +31533 64362 +82098 35520 +60520 98196 +62425 65803 +90692 57775 +29160 99403 +28072 65721 +29207 40337 +96928 11960 +88074 55022 +11262 31658 +70439 12630 +46426 40192 +97124 96336 +97733 79144 +60902 82128 +20406 18866 +49465 24075 +92723 84471 +82785 49899 +85690 84471 +46301 60801 +70543 39158 +77397 13167 +78434 89992 +43358 22650 +38412 60568 +54633 45527 +27215 93385 +98736 65619 +12981 48333 +79201 61358 +71849 25687 +27785 40337 +57013 13427 +99403 88588 +22632 26830 +12033 77373 +66675 16445 +23066 67354 +80100 31674 +77822 43658 +70694 18628 +38583 97566 +29014 39095 +71974 78640 +44442 94472 +89670 92693 +58205 52583 +26610 32340 +50111 36267 +81769 55267 +80727 15549 +54969 41669 +88744 81796 +66642 43640 +38035 81796 +86110 74184 +74806 38412 +26849 66673 +27007 93396 +80555 78794 +64197 32236 +88661 18331 +16011 32801 +18265 19847 +73365 46289 +71259 84471 +53163 80344 +67421 42238 +61567 39797 +78176 12791 +68680 99109 +83969 59805 +99427 65563 +64286 88588 +69259 49401 +65989 60112 +74866 55267 +91571 70365 +61137 72545 +86810 99342 +91215 74819 +57984 84471 +64054 45167 +25371 93258 +56931 97531 +42448 58600 +77910 41669 +27234 23987 +55971 67247 +53910 23754 +59015 16842 +36568 18866 +93228 92940 +38858 21883 +37570 41669 +43634 48654 +61671 36109 +14455 39324 +69564 61102 +75007 36730 +83030 35520 +27889 41669 +90946 41125 +12614 70263 +61381 18549 +90763 45873 +13117 44089 +13363 84471 diff --git a/2024/day01/solutions/part1.py b/2024/day01/solutions/part1.py new file mode 100644 index 0000000..1855a54 --- /dev/null +++ b/2024/day01/solutions/part1.py @@ -0,0 +1,19 @@ +with open("../input.txt", "r") as fp: + inputs = fp.readlines() + +arr1 = [] +arr2 = [] + +for line in inputs: + tmp = list(filter(None, line.strip().split(' '))) + arr1.append(int(tmp[0])) + arr2.append(int(tmp[1])) + +arr1.sort() +arr2.sort() + +sum = 0 +for a, b in zip(arr1, arr2): + sum += abs(a - b) + +print(sum) \ No newline at end of file diff --git a/2024/day01/solutions/part2.py b/2024/day01/solutions/part2.py new file mode 100644 index 0000000..277e1cd --- /dev/null +++ b/2024/day01/solutions/part2.py @@ -0,0 +1,25 @@ +with open("../input.txt", "r") as fp: + inputs = fp.readlines() + +numberMap = {} +arr1 = [] +arr2 = [] + +for line in inputs: + tmp = list(filter(None, line.strip().split(' '))) + arr1.append(int(tmp[0])) + arr2.append(int(tmp[1])) + +# Map the number counts +for b in arr2: + if b not in numberMap: + numberMap[b] = 1 + else: + numberMap[b] += 1 + +# Calculate similarity score +sim = 0 +for a in arr1: + sim += a * numberMap.get(a, 0) + +print(sim) \ No newline at end of file diff --git a/2024/day02/README.md b/2024/day02/README.md new file mode 100644 index 0000000..2208934 --- /dev/null +++ b/2024/day02/README.md @@ -0,0 +1,87 @@ +Part 1: `383` + +Part 2: `436` + +[--- 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](/2015/day/19) 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?* + + +] \ No newline at end of file diff --git a/2024/day02/input.txt b/2024/day02/input.txt new file mode 100644 index 0000000..8634bd2 --- /dev/null +++ b/2024/day02/input.txt @@ -0,0 +1,1000 @@ +62 65 67 70 73 76 75 +68 71 73 76 78 78 +77 80 81 82 86 +44 47 48 51 53 58 +51 53 56 57 59 56 57 60 +68 70 71 69 72 74 71 +59 61 63 66 64 66 66 +55 56 55 58 61 63 64 68 +3 4 5 8 11 9 10 17 +16 18 18 21 22 +70 71 73 73 74 76 78 75 +16 17 20 20 23 23 +10 12 12 15 16 17 21 +50 53 56 56 63 +25 26 29 33 36 +52 54 56 57 60 64 66 63 +59 60 63 66 70 73 73 +42 43 45 47 51 54 58 +69 71 72 73 75 79 86 +13 16 17 24 25 28 31 33 +9 10 17 19 16 +6 7 8 15 18 18 +17 18 24 27 31 +20 21 23 30 36 +27 24 25 26 28 31 34 +29 26 28 30 31 34 33 +86 83 84 86 87 89 91 91 +81 79 80 83 85 89 +56 55 57 59 66 +49 48 46 47 49 +77 76 77 76 74 +42 41 44 43 46 46 +86 85 86 85 88 92 +16 13 14 11 16 +34 32 32 35 36 39 41 +36 34 35 36 36 38 35 +8 6 8 8 10 13 13 +17 15 15 18 21 25 +18 17 17 18 25 +85 84 86 88 89 93 96 +37 36 40 41 38 +25 22 24 28 29 29 +70 68 71 74 78 82 +16 13 14 15 17 21 27 +58 57 62 63 65 66 68 +84 81 84 85 90 88 +67 66 68 74 75 78 78 +68 66 73 76 80 +38 35 41 43 45 46 52 +63 63 64 67 69 70 71 74 +28 28 31 33 31 +43 43 44 47 48 49 52 52 +68 68 69 72 74 75 79 +60 60 62 65 67 70 76 +38 38 37 38 40 +18 18 21 22 25 23 22 +19 19 16 17 19 20 20 +24 24 22 25 29 +38 38 35 38 43 +14 14 14 16 18 20 +55 55 55 56 53 +32 32 35 35 38 41 41 +14 14 15 15 16 20 +18 18 18 19 20 27 +42 42 45 49 52 54 56 +19 19 23 26 27 24 +71 71 73 76 80 83 85 85 +35 35 38 42 46 +25 25 29 32 37 +28 28 30 35 37 38 40 41 +33 33 38 39 38 +69 69 72 79 79 +8 8 13 14 15 18 22 +40 40 42 47 53 +83 87 89 90 91 +18 22 25 27 28 30 32 31 +47 51 54 57 60 60 +66 70 72 74 78 +24 28 31 33 40 +30 34 33 34 36 +65 69 67 70 72 74 73 +72 76 77 80 83 80 80 +54 58 61 58 62 +59 63 65 66 65 66 72 +28 32 32 34 35 38 41 +16 20 21 23 23 22 +48 52 52 55 58 58 +17 21 21 24 25 29 +19 23 24 25 25 28 33 +39 43 44 47 51 53 54 +4 8 10 14 16 17 18 17 +7 11 12 15 19 22 22 +70 74 77 78 80 84 88 +60 64 67 70 74 76 81 +47 51 58 59 60 62 64 +9 13 14 16 22 19 +21 25 32 33 35 35 +78 82 89 91 95 +15 19 26 29 36 +53 58 59 61 64 66 +52 59 60 62 63 64 66 65 +60 67 70 71 71 +67 72 75 76 79 81 85 +19 25 26 28 30 37 +13 19 21 18 20 +10 16 19 22 24 26 23 21 +37 42 41 44 46 46 +53 60 63 64 62 64 68 +48 54 55 53 59 +49 54 57 57 60 63 65 +27 34 35 35 38 41 38 +37 42 45 48 49 51 51 51 +68 75 78 78 80 84 +36 41 43 43 49 +36 42 45 46 50 52 +24 31 35 36 35 +3 10 13 14 18 21 21 +25 32 34 37 41 45 +51 57 58 60 64 71 +10 17 19 21 23 25 32 34 +41 46 48 51 54 60 58 +7 12 15 17 23 25 27 27 +11 18 19 25 29 +56 63 64 67 70 75 80 +22 21 18 17 16 14 15 +86 83 81 78 77 76 73 73 +90 88 85 82 81 78 75 71 +88 86 85 82 79 76 70 +90 88 87 88 86 +35 34 33 32 29 26 27 30 +95 94 93 90 92 91 91 +32 29 28 25 28 26 23 19 +62 61 59 58 61 59 56 51 +32 29 29 28 26 +47 46 45 44 44 46 +84 82 79 77 74 74 74 +16 14 13 11 10 10 9 5 +73 71 68 68 62 +42 39 35 32 29 26 24 +98 95 94 92 91 87 86 89 +83 82 78 77 76 74 74 +83 80 76 73 69 +25 23 19 18 15 12 6 +69 68 66 60 58 +15 14 8 5 2 4 +55 52 50 48 46 39 37 37 +42 41 40 39 37 31 27 +90 88 86 84 78 72 +37 39 36 33 31 29 +65 67 64 62 64 +57 59 56 54 51 51 +49 52 51 49 46 45 43 39 +47 49 46 45 42 36 +55 58 56 54 55 53 52 51 +29 32 29 30 29 31 +95 98 97 96 97 97 +36 39 36 39 37 33 +79 81 79 77 80 73 +55 57 56 56 54 52 51 +27 30 28 25 25 22 19 21 +61 64 62 62 61 61 +51 53 50 48 46 46 45 41 +28 31 30 30 27 25 20 +27 29 25 22 19 +52 54 53 49 51 +31 33 31 29 28 24 21 21 +29 30 26 23 21 20 16 +59 61 59 55 53 48 +17 18 17 14 12 9 4 3 +67 70 68 63 65 +42 45 43 42 36 36 +34 36 35 29 27 25 21 +62 64 63 62 56 53 51 46 +62 62 59 56 55 +93 93 90 87 86 85 83 85 +74 74 71 68 67 66 66 +31 31 28 25 22 18 +40 40 39 36 34 32 25 +16 16 14 17 16 15 13 11 +18 18 15 12 13 12 14 +77 77 75 77 76 76 +53 53 54 51 48 44 +81 81 84 82 79 76 74 67 +74 74 71 71 68 66 65 64 +4 4 4 1 2 +24 24 21 21 20 20 +69 69 66 64 64 63 62 58 +64 64 61 61 59 57 52 +28 28 25 23 19 16 13 10 +22 22 20 16 14 13 15 +68 68 64 63 62 62 +64 64 62 58 55 52 49 45 +42 42 38 37 36 31 +51 51 50 49 46 40 38 +77 77 71 69 68 67 65 68 +25 25 24 19 17 16 15 15 +99 99 98 93 90 86 +82 82 76 74 72 65 +91 87 86 83 81 80 79 78 +55 51 50 47 44 42 40 42 +56 52 51 48 46 43 41 41 +72 68 66 63 62 59 55 +56 52 51 50 48 47 44 37 +27 23 21 23 22 +10 6 4 6 7 +66 62 65 62 59 57 57 +76 72 69 71 69 65 +45 41 42 41 39 32 +28 24 24 21 20 18 +27 23 22 21 21 20 17 18 +41 37 35 32 32 31 31 +89 85 82 79 79 76 75 71 +19 15 12 9 7 7 2 +54 50 47 43 42 41 +32 28 24 22 23 +51 47 43 42 41 40 37 37 +41 37 36 32 31 27 +97 93 89 87 85 82 81 76 +66 62 59 58 52 49 +65 61 60 57 51 53 +99 95 88 87 87 +88 84 82 81 75 74 71 67 +76 72 66 63 62 60 55 +46 41 38 36 33 31 28 +82 75 72 69 71 +58 53 52 49 49 +53 46 45 42 38 +68 62 61 58 57 55 50 +66 60 58 56 57 56 54 +57 51 48 46 43 46 45 46 +65 60 58 56 57 55 55 +73 68 69 67 63 +29 24 23 24 18 +34 28 26 24 21 19 19 17 +51 46 45 45 46 +15 8 5 3 2 2 2 +56 51 50 48 48 47 43 +57 51 49 48 48 42 +81 76 73 69 68 +92 86 83 82 78 81 +56 51 49 45 42 40 40 +91 84 80 77 76 72 +44 39 37 33 30 25 +64 57 55 54 51 44 41 38 +32 27 24 18 17 16 14 17 +64 58 51 49 48 45 45 +72 66 64 59 57 53 +83 78 72 70 68 67 60 +47 48 50 52 55 52 +64 67 70 71 72 72 +76 77 80 83 84 87 90 94 +77 79 82 85 86 87 88 93 +44 47 46 47 49 +15 17 20 18 20 18 +22 24 27 28 30 29 29 +20 22 24 21 25 +84 85 88 87 90 96 +18 19 20 22 24 24 27 29 +23 24 24 26 27 29 28 +24 25 25 28 28 +50 53 53 55 56 60 +27 28 29 30 30 32 39 +48 49 52 53 54 58 60 63 +16 17 20 24 27 24 +5 7 8 10 12 16 16 +80 81 84 85 86 87 91 95 +10 11 14 18 24 +48 51 53 58 59 62 64 66 +23 24 25 28 33 30 +30 33 34 35 41 42 43 43 +8 10 11 13 14 20 24 +28 30 31 36 39 42 48 +61 59 61 62 65 67 69 +73 70 72 73 71 +90 88 89 91 93 93 +15 14 17 19 20 22 24 28 +46 45 47 50 52 53 58 +70 67 69 66 69 +66 65 67 65 68 69 70 68 +8 7 5 6 9 11 11 +5 3 1 2 4 8 +93 92 90 92 93 99 +14 12 12 14 16 +16 13 13 14 16 15 +23 22 22 24 27 28 29 29 +34 33 33 34 37 41 +11 9 11 11 12 13 15 20 +28 25 27 31 32 34 +63 62 66 68 70 67 +35 34 37 38 42 42 +10 8 12 13 16 19 23 +42 39 43 44 46 52 +84 81 83 90 93 +56 55 61 64 61 +63 60 62 63 68 70 71 71 +83 80 82 83 88 92 +71 69 75 77 84 +69 69 70 72 73 76 +38 38 39 40 41 43 40 +6 6 8 10 11 13 13 +46 46 49 52 55 56 60 +24 24 25 27 29 31 32 37 +23 23 24 27 28 29 26 27 +82 82 83 86 83 84 82 +48 48 51 54 55 52 52 +88 88 90 89 91 94 98 +11 11 14 17 15 16 23 +38 38 40 40 43 +35 35 38 40 40 38 +26 26 27 27 27 +1 1 1 3 7 +1 1 4 4 7 10 11 18 +83 83 87 89 91 93 +37 37 40 41 42 46 49 46 +9 9 10 14 15 18 18 +67 67 69 71 74 77 81 85 +62 62 66 67 69 75 +20 20 21 23 29 32 33 36 +4 4 10 13 15 16 15 +44 44 45 52 53 53 +80 80 87 88 89 93 +13 13 14 16 22 29 +25 29 31 32 34 35 +86 90 92 94 95 92 +28 32 35 37 39 42 44 44 +26 30 31 32 35 39 +54 58 61 62 63 65 72 +72 76 79 81 82 79 81 83 +49 53 56 58 60 63 60 57 +66 70 72 69 69 +84 88 85 86 90 +85 89 91 94 95 92 98 +8 12 13 13 14 16 19 +85 89 92 92 91 +74 78 79 81 82 84 84 84 +57 61 61 64 66 70 +36 40 40 42 44 51 +2 6 8 9 12 16 17 18 +26 30 31 35 36 35 +50 54 58 61 64 64 +47 51 52 54 58 59 63 +67 71 73 77 83 +7 11 18 20 21 23 +66 70 73 80 77 +50 54 59 61 64 67 67 +76 80 81 82 83 88 90 94 +68 72 73 80 82 84 91 +18 23 26 27 29 30 +67 74 77 78 75 +18 24 25 27 27 +57 64 67 68 69 73 +8 13 15 16 18 19 21 27 +68 74 72 73 76 78 79 80 +17 22 19 22 19 +72 79 78 80 80 +42 47 44 45 48 52 +20 27 28 27 32 +44 51 54 54 56 57 60 +43 49 52 55 55 56 58 55 +63 70 71 71 74 75 77 77 +17 22 25 27 30 30 34 +18 24 27 27 29 30 32 39 +56 61 64 68 71 74 +48 55 59 60 61 58 +13 19 22 25 29 31 31 +35 40 41 42 45 49 53 +24 31 34 35 37 41 46 +62 69 70 73 78 81 83 +47 52 54 59 62 65 68 67 +16 23 24 27 29 36 38 38 +57 62 63 65 72 73 75 79 +68 73 74 79 82 87 +23 21 18 15 12 11 12 +86 85 82 79 77 77 +24 23 20 19 17 13 +89 87 86 84 81 78 72 +10 9 7 4 2 5 4 3 +74 73 71 72 75 +92 90 88 86 83 86 83 83 +83 81 80 82 78 +33 32 31 33 32 27 +21 20 18 15 15 12 10 7 +21 20 17 15 14 12 12 14 +51 48 46 43 43 40 39 39 +46 43 43 41 40 36 +71 68 67 64 63 63 56 +37 35 32 28 27 26 23 +42 41 37 36 34 33 30 32 +44 41 40 38 34 34 +25 24 22 18 17 14 10 +81 79 77 76 72 69 68 62 +36 34 29 28 27 24 21 +21 20 18 16 9 12 +74 72 65 64 62 62 +70 67 64 62 56 54 50 +89 88 82 80 77 74 73 66 +79 81 78 77 75 +20 23 20 19 17 19 +78 79 78 75 74 72 72 +86 88 87 84 83 80 79 75 +98 99 98 97 95 93 86 +16 18 17 18 16 +21 23 21 24 25 +28 29 26 25 24 26 26 +46 48 45 48 44 +27 29 26 23 25 23 17 +17 18 17 17 16 15 +85 86 83 82 82 79 82 +88 91 91 88 88 +90 91 91 88 86 84 81 77 +43 45 43 43 40 34 +18 20 17 15 14 11 7 6 +18 19 18 15 13 9 8 10 +95 97 93 90 90 +89 92 91 90 86 84 83 79 +95 96 92 89 87 85 80 +29 32 29 23 21 +21 22 19 17 11 9 12 +87 88 85 83 81 76 76 +57 60 54 51 49 45 +85 87 81 80 77 76 73 67 +30 30 29 26 24 21 20 +65 65 64 63 60 59 60 +49 49 48 47 46 45 45 +56 56 53 52 51 47 +82 82 80 77 75 68 +47 47 48 45 44 +81 81 82 79 82 +36 36 39 37 37 +49 49 47 45 43 42 45 41 +88 88 87 90 85 +54 54 52 52 51 +89 89 89 87 84 83 86 +33 33 31 31 28 25 25 +58 58 57 54 54 52 51 47 +89 89 86 86 85 78 +19 19 17 14 11 7 4 1 +68 68 67 63 64 +78 78 74 71 70 69 69 +56 56 54 50 46 +23 23 20 18 14 12 5 +50 50 49 48 47 46 40 37 +40 40 37 34 28 31 +88 88 87 82 80 77 75 75 +59 59 56 55 48 44 +46 46 43 38 31 +83 79 76 75 72 70 +67 63 62 59 56 53 52 55 +94 90 89 87 87 +46 42 41 38 36 33 29 +48 44 42 41 39 37 35 29 +68 64 65 64 61 59 +59 55 53 56 58 +66 62 59 61 59 59 +35 31 32 31 29 25 +90 86 87 85 82 80 77 72 +68 64 62 60 60 58 57 55 +26 22 21 18 18 17 18 +44 40 39 39 39 +53 49 46 44 44 40 +63 59 58 56 56 54 48 +93 89 85 84 81 +96 92 89 88 86 82 79 81 +22 18 17 13 13 +77 73 69 67 63 +91 87 84 83 79 76 75 70 +98 94 91 85 84 81 +14 10 9 3 5 +90 86 81 78 75 73 73 +31 27 24 22 19 18 13 9 +83 79 72 70 64 +83 76 75 72 69 66 64 61 +48 41 39 38 35 34 37 +73 68 66 65 62 60 58 58 +94 89 88 86 82 +65 58 55 52 50 47 42 +43 36 35 34 32 30 33 32 +59 54 55 53 50 52 +30 23 21 19 22 22 +10 5 4 3 6 2 +60 53 51 48 46 49 42 +14 9 9 7 5 +27 21 18 17 16 16 19 +94 89 86 83 83 80 80 +37 31 31 28 24 +52 47 45 42 40 40 35 +36 31 30 28 24 22 +35 30 28 25 22 20 16 18 +84 78 75 71 71 +77 71 68 64 60 +24 17 16 15 13 9 7 1 +31 25 18 15 12 +47 42 35 32 31 30 32 +38 31 28 26 20 20 +96 90 89 86 80 79 78 74 +30 24 23 21 16 9 +77 77 82 84 87 89 91 89 +13 13 12 14 16 20 +69 64 63 59 57 54 51 51 +82 87 88 90 93 95 95 +85 79 76 75 76 74 77 +60 64 67 73 79 +86 86 85 79 75 +74 68 67 61 59 +61 57 54 53 53 52 51 44 +79 84 81 83 85 90 +80 80 76 74 73 70 70 +30 31 31 29 26 23 26 +35 36 39 42 40 +38 38 41 41 44 41 +88 91 90 89 87 85 82 78 +32 30 28 27 21 21 +89 89 86 84 81 84 83 78 +40 44 48 49 50 52 55 56 +92 89 91 91 88 +80 86 89 95 94 +49 50 50 47 42 +23 28 31 34 40 +39 37 35 37 31 +25 28 26 23 21 22 19 17 +44 38 37 39 37 33 +88 90 86 83 78 +77 79 83 85 88 95 +60 63 61 64 60 +70 64 67 64 61 60 +38 45 48 51 54 57 59 57 +58 56 53 56 52 +23 21 23 25 26 27 27 +66 60 59 57 56 56 54 57 +49 49 49 46 44 39 +40 35 33 31 26 +65 63 70 73 73 +38 31 26 25 20 +43 39 36 32 29 23 +56 54 52 50 50 47 45 39 +58 55 58 59 61 58 59 64 +47 45 43 45 45 +81 81 78 77 75 71 64 +48 42 41 38 39 36 33 33 +78 77 83 85 89 +14 17 15 14 11 9 +62 58 57 51 50 47 43 +95 92 95 96 95 +62 65 66 70 73 75 75 +32 33 33 31 30 +94 93 92 87 83 +16 16 19 24 27 28 30 32 +60 62 60 57 55 56 51 +70 73 71 74 73 72 72 +9 8 11 18 20 23 22 +74 69 67 65 63 57 54 54 +14 15 13 11 12 13 +26 30 32 30 28 +32 32 34 33 33 +4 8 10 13 11 14 18 +25 25 18 16 14 13 12 12 +63 59 58 54 53 +40 43 40 39 38 32 26 +49 49 51 55 59 +23 23 16 14 13 10 7 2 +84 80 76 74 71 70 69 65 +76 73 71 68 66 65 59 +75 70 68 65 61 +15 9 6 5 7 1 +45 41 38 36 33 28 27 +49 55 57 57 63 +29 33 36 38 39 45 +49 48 49 52 56 63 +40 43 46 52 55 56 +18 14 11 8 8 6 +42 48 49 51 50 52 49 +39 45 44 46 48 48 +69 73 73 74 74 +95 98 95 94 93 89 88 88 +13 10 13 17 18 20 21 21 +52 49 46 43 37 36 29 +5 6 9 11 12 15 19 +31 32 35 37 43 46 48 48 +47 47 50 52 53 54 55 +38 38 39 45 50 +47 45 40 39 36 +82 85 88 90 88 92 +36 36 38 35 32 +67 61 61 59 56 53 53 +79 84 88 90 92 94 95 93 +74 78 79 82 84 88 90 94 +14 18 21 19 22 25 26 31 +87 83 80 79 78 76 78 73 +90 84 81 79 76 74 74 72 +56 60 64 66 69 74 +3 7 9 12 15 17 20 19 +29 32 29 28 26 24 18 16 +66 62 60 60 58 56 52 +62 66 69 71 74 74 +53 53 52 49 48 45 44 47 +33 37 38 41 44 45 50 53 +40 44 49 52 54 57 57 +8 6 13 16 18 20 25 +7 3 1 1 4 +23 24 21 20 19 22 +77 80 78 73 72 74 +10 10 7 8 11 13 15 +49 49 56 58 61 61 +51 47 45 48 47 43 +67 67 66 65 66 64 63 64 +97 90 89 86 84 84 +16 20 23 26 31 35 +64 66 65 64 62 60 59 54 +17 24 30 32 35 +99 93 90 88 84 80 +33 37 38 37 38 41 +7 12 13 17 20 22 23 23 +88 84 81 76 74 69 +6 10 13 17 19 18 +30 34 36 38 42 +77 77 74 72 71 69 66 61 +88 88 84 81 78 +47 44 42 39 37 +13 10 9 6 4 1 +37 38 41 44 45 46 +66 64 61 59 57 56 +38 35 32 29 28 25 24 21 +31 32 35 38 41 42 43 +50 49 46 44 41 39 +37 39 40 41 43 44 47 48 +58 55 53 52 49 46 43 +70 73 76 79 80 81 +43 41 38 36 33 32 29 +40 37 35 34 33 +22 21 18 15 14 13 12 9 +26 25 22 21 18 +23 21 20 19 16 15 12 +98 96 95 94 91 +67 70 72 75 77 79 80 82 +92 90 87 84 81 +73 70 69 67 65 63 60 59 +24 27 28 30 33 36 39 42 +18 15 13 11 10 8 7 +82 79 77 76 73 71 69 66 +2 4 6 8 10 +44 42 39 36 33 30 +16 13 11 9 7 4 +45 46 47 48 50 53 +20 19 18 17 16 15 12 +34 32 29 28 25 +74 76 78 81 82 83 86 +17 19 22 24 26 29 31 33 +80 83 84 86 88 90 92 94 +60 63 65 67 69 70 73 74 +55 56 58 59 61 +34 35 36 38 39 40 42 45 +74 77 80 81 82 +40 37 35 32 31 29 27 25 +16 15 14 11 10 +29 27 24 21 19 +48 51 54 56 59 62 +42 44 46 49 51 52 +95 94 93 91 88 +52 54 57 60 63 +54 57 60 63 64 66 69 +39 42 45 46 49 52 +73 72 70 68 66 65 62 59 +47 49 52 54 57 58 59 +7 9 12 15 16 19 20 21 +14 15 18 19 22 24 +46 49 51 54 57 +50 47 46 44 41 38 35 +70 67 66 64 62 59 57 +34 33 31 30 28 27 26 23 +76 79 82 83 86 89 92 +53 51 49 47 46 45 +17 19 21 24 25 +65 62 59 57 55 52 51 48 +88 87 86 83 81 80 79 77 +61 59 58 56 53 51 +42 45 48 49 51 54 56 +58 60 61 62 64 +74 71 69 68 65 62 60 +21 20 17 14 13 11 8 +43 45 46 47 50 53 54 +13 16 18 19 22 23 25 +19 18 17 15 14 11 9 +47 49 51 52 53 54 55 56 +93 92 90 89 88 86 83 80 +88 89 90 91 93 94 95 98 +16 13 11 8 5 +41 39 36 34 33 32 29 27 +59 58 57 55 52 49 +73 76 77 78 81 84 85 87 +68 69 71 72 75 77 79 +14 12 10 7 6 +57 56 55 53 51 50 47 +98 96 93 92 89 87 +49 48 46 44 42 40 +41 43 46 48 50 +64 61 58 57 56 53 52 +12 10 9 8 6 4 +46 48 49 52 55 +59 62 65 66 67 70 73 +26 29 30 31 33 36 +50 47 46 43 41 40 39 38 +15 16 19 22 23 26 28 +12 13 14 17 20 22 23 26 +66 65 63 60 57 54 +44 46 48 51 52 +7 8 11 12 15 18 20 21 +26 28 29 31 32 33 +91 90 89 86 84 83 80 78 +93 92 91 90 89 87 +33 32 31 30 28 27 26 +68 69 70 73 76 +24 21 18 16 14 11 9 7 +5 8 9 11 12 +66 65 62 61 60 57 55 53 +68 65 63 60 59 58 55 +81 79 77 75 74 72 +43 42 40 39 37 36 +84 82 80 78 77 +88 85 83 82 81 79 78 76 +21 24 26 28 30 32 33 35 +15 16 18 19 21 23 26 +18 17 14 11 8 7 +52 53 56 59 60 63 65 67 +33 34 35 38 39 40 +61 62 63 65 66 +23 21 19 16 13 +3 6 8 10 12 +80 77 76 74 72 70 69 66 +29 26 23 20 18 +59 58 55 54 52 50 +51 54 57 59 60 62 63 +33 35 36 39 40 43 44 +34 32 31 29 27 26 +65 64 61 60 57 +31 30 27 24 21 19 18 16 +18 19 20 21 24 +3 6 8 10 13 14 +56 55 53 52 50 49 +90 88 87 84 82 +15 18 19 22 25 +96 95 94 91 90 88 +14 11 9 7 5 4 1 +26 28 31 33 36 37 39 +51 49 47 46 44 41 +85 83 82 81 78 77 76 +43 40 38 36 33 +71 70 69 67 65 63 61 +40 41 43 45 48 51 +55 52 50 49 47 45 42 40 +79 78 76 75 73 71 +39 38 37 35 32 +83 86 88 90 91 +70 68 67 64 63 61 58 55 +98 95 92 90 89 88 87 85 +59 60 62 64 67 70 71 74 +99 98 97 95 92 89 87 +70 72 75 76 78 79 80 +85 88 89 91 93 95 +62 60 58 55 53 51 49 47 +34 33 32 31 28 25 24 23 +87 84 83 82 79 +35 34 33 30 29 26 +54 57 58 61 64 65 +49 50 51 53 55 56 +82 80 79 76 74 +66 68 70 71 73 76 77 78 +44 47 49 50 52 53 55 58 +34 35 36 38 40 42 +73 76 77 78 80 81 +98 95 94 91 90 +45 46 48 51 52 +21 20 18 16 15 12 10 +25 22 19 18 17 14 12 10 +56 57 59 60 61 64 66 +34 35 38 40 42 44 47 +98 97 96 94 93 92 90 +44 47 50 52 53 55 57 +91 90 89 87 86 83 +33 30 27 24 23 21 19 +36 38 39 40 43 +89 88 85 83 81 80 +61 64 67 68 70 71 73 +2 4 5 6 8 10 +48 50 52 55 57 58 +19 17 15 12 9 6 4 +55 58 61 63 66 67 69 72 +47 50 51 53 56 59 +66 64 61 58 57 54 51 50 +72 73 75 77 78 81 82 +7 9 12 14 15 16 17 +30 31 32 35 37 40 42 44 +13 14 15 17 19 22 +83 84 86 87 89 92 93 +19 16 13 10 7 5 3 2 +27 29 30 32 34 +27 30 33 34 35 38 40 +44 46 47 48 50 +73 71 70 69 68 66 64 63 +52 49 48 47 44 +33 32 30 27 24 22 19 17 +95 94 91 89 88 87 +34 35 37 39 41 43 45 +20 19 17 16 13 +30 28 27 25 24 21 19 +11 14 15 17 20 23 +58 56 54 52 50 +30 33 34 35 38 +32 30 27 25 22 20 18 15 +37 40 42 45 46 +38 35 32 29 26 25 +19 17 15 12 10 8 6 +7 8 9 11 13 +92 90 89 88 86 +28 26 25 22 21 19 18 +84 82 79 77 74 72 70 +86 83 81 79 77 74 +86 87 89 90 91 94 97 +31 28 25 22 21 +32 29 26 23 22 19 17 +89 90 92 93 95 +57 60 62 63 64 +76 73 72 69 66 +97 95 93 90 87 84 +1 2 5 6 8 +19 17 14 13 11 +39 38 35 33 30 +83 81 79 78 77 +43 42 41 38 36 35 33 30 +82 80 77 76 73 71 68 +90 88 86 85 84 83 +21 24 27 29 31 33 35 36 +50 53 54 56 58 60 63 +58 55 53 50 48 46 45 +72 75 76 79 80 83 85 +78 77 76 74 73 70 67 +83 80 79 78 75 72 +59 57 56 54 52 49 47 +73 71 69 68 66 65 62 +72 69 66 64 62 +54 55 56 58 60 +88 87 84 83 81 79 76 +46 45 44 43 40 38 +42 39 38 37 34 33 +13 16 18 19 22 25 28 29 +43 44 47 49 51 +6 8 9 12 14 15 17 +67 70 72 74 75 76 79 80 +76 75 73 72 71 70 +44 46 48 50 53 56 +29 31 32 33 36 39 42 43 +15 18 19 20 22 23 26 28 +95 94 91 89 87 85 82 +49 47 45 43 40 +51 54 56 57 60 63 +68 71 74 75 76 +26 28 31 32 35 37 38 39 +33 35 36 37 39 41 44 +96 95 94 93 92 +54 57 58 60 62 65 68 69 +10 13 15 18 20 22 +57 60 63 64 67 69 71 74 +36 37 39 40 43 45 +79 81 84 87 90 92 +89 88 87 85 82 79 76 +64 62 60 59 56 +20 17 16 14 13 12 +39 40 42 44 46 49 52 +97 96 94 91 90 87 84 +19 18 15 14 11 10 +76 78 80 81 82 +41 43 46 49 52 55 57 +24 22 19 18 15 14 11 +52 51 50 47 44 41 40 +20 23 26 27 28 31 33 +84 81 78 77 74 +47 50 53 55 57 60 +51 54 55 58 61 64 65 66 +37 40 41 44 46 49 51 52 +23 24 25 27 28 +79 78 75 74 72 +49 50 53 54 57 58 60 +49 52 55 58 60 61 63 +33 31 30 29 26 25 22 21 +17 14 11 9 7 4 +79 81 84 87 89 91 94 +89 86 83 81 80 +90 88 87 85 82 80 77 +58 59 60 62 65 66 67 +57 56 53 52 49 48 46 +12 15 17 20 22 25 26 29 +34 37 39 42 45 48 51 +14 15 18 21 24 +64 63 61 58 56 55 52 +78 75 73 72 70 69 68 +77 78 81 84 87 +26 24 21 20 19 17 +37 40 43 44 46 +56 59 60 62 64 65 +75 78 80 81 83 85 87 +82 79 77 76 73 71 70 +37 40 43 46 48 +65 64 62 59 56 +81 80 79 77 76 75 73 +68 71 72 73 75 76 79 80 +28 25 22 19 17 +27 24 21 19 17 16 +52 49 47 46 44 +57 54 53 50 49 +72 71 70 68 67 64 +25 26 29 32 34 36 39 +85 88 89 90 91 93 95 +21 24 25 28 31 34 +35 33 30 28 27 26 24 +11 9 7 5 2 +10 11 14 15 16 17 18 +76 79 81 84 85 +43 46 47 48 49 +26 27 30 31 32 33 +13 15 16 19 21 23 24 +45 48 50 53 54 +94 92 90 87 86 85 84 +59 56 53 50 49 +28 26 25 22 20 17 16 15 +50 49 48 47 44 +58 57 56 54 53 51 49 +44 46 48 50 53 54 56 +63 64 66 68 70 71 72 74 +92 91 90 87 86 83 +18 16 14 13 12 11 +60 63 64 67 68 +30 27 26 24 21 18 +77 80 82 85 87 88 91 +78 75 74 73 70 67 65 +10 13 14 16 17 20 21 23 +46 44 41 40 39 36 +88 87 85 82 81 79 76 73 +42 44 46 49 50 53 54 57 +55 52 49 46 45 42 41 40 +87 84 82 81 78 76 73 71 +62 65 67 69 71 74 +35 36 39 42 43 45 46 +59 58 55 53 51 50 +22 19 18 17 15 +76 77 80 81 84 +48 47 45 44 41 39 +69 67 64 63 61 59 57 55 +91 90 87 85 84 81 +39 36 33 31 30 27 24 21 +79 82 83 84 85 86 +96 93 92 89 88 86 +15 14 12 9 8 6 4 +76 74 73 70 69 67 +34 32 30 27 25 24 +62 65 68 70 72 +26 28 29 30 33 36 37 40 +61 64 65 66 67 68 +19 20 22 24 26 29 30 31 +80 83 84 87 89 +96 95 92 89 87 86 83 80 +96 95 93 90 89 87 85 84 +48 50 53 56 57 58 61 62 +27 29 32 33 36 38 41 42 +78 80 82 83 85 87 90 93 +67 64 62 59 58 57 56 55 +69 71 73 76 78 +57 55 53 51 48 45 42 41 +18 19 21 22 25 28 30 31 +86 83 81 79 77 76 +32 29 28 25 23 22 20 19 +58 60 61 62 63 +66 65 63 62 60 57 56 +48 49 50 53 54 55 58 60 +74 71 70 67 64 62 61 +65 62 59 56 53 51 +66 68 69 71 74 77 +67 69 71 73 75 76 77 80 +13 15 18 20 21 +40 43 44 45 46 47 +42 41 39 37 34 32 +13 11 10 9 6 4 +48 51 54 57 59 62 65 +64 62 60 59 58 55 +47 44 43 42 41 +82 84 86 89 90 92 +83 85 86 88 91 93 +53 55 57 60 62 64 +19 17 16 15 12 9 6 +79 77 75 73 71 69 67 65 +74 77 78 81 84 86 +54 53 50 47 46 43 +98 95 94 93 91 88 +94 91 89 86 85 83 +98 97 96 94 93 91 90 88 +85 82 80 79 76 +81 83 86 87 90 93 96 +74 77 78 80 82 +29 27 26 24 22 19 +24 26 27 30 33 34 37 39 +17 19 20 23 25 28 +76 74 71 69 67 diff --git a/2024/day02/solutions/part1.py b/2024/day02/solutions/part1.py new file mode 100644 index 0000000..601a8f6 --- /dev/null +++ b/2024/day02/solutions/part1.py @@ -0,0 +1,31 @@ +with open("../input.txt", "r") as fp: + inputs = [list(map(int, line.rstrip().split())) for line in fp] + +safe = 0 + +for line in inputs: + increase = 0 + decrease = 0 + unsafe = False + for i, a in enumerate(line[:-1]): + b = line[i+1] + + # Check for difference of 1-3 + if abs(a-b) > 3 or abs(a-b) < 1: + unsafe = True + break + + # Watch for increase/decrease + if a < b: + increase += 1 + else: + decrease += 1 + + if increase != 0 and decrease != 0: + unsafe = True + break + + if not unsafe: + safe += 1 + +print(safe) \ No newline at end of file diff --git a/2024/day02/solutions/part2.py b/2024/day02/solutions/part2.py new file mode 100644 index 0000000..e2c7222 --- /dev/null +++ b/2024/day02/solutions/part2.py @@ -0,0 +1,51 @@ +with open("../input.txt", "r") as fp: + inputs = [list(map(int, line.rstrip().split())) for line in fp] + +def is_safe(line, rec=True): + increase = 0 + decrease = 0 + + for i, a in enumerate(line[:-1]): + b = line[i+1] + + # Check for difference of 1-3 + if abs(a-b) > 3 or abs(a-b) < 1: + if rec: + case_0 = line[:] + case_0.pop(0) + case_1 = line[:] + case_1.pop(i) + case_2 = line[:] + case_2.pop(i+1) + if is_safe(case_0, False) or is_safe(case_1, False) or is_safe(case_2, False): + return True + + return False + + # Watch for increase/decrease + if a < b: + increase += 1 + else: + decrease += 1 + + if increase != 0 and decrease != 0: + if rec: + case_0 = line[:] + case_0.pop(0) + case_1 = line[:] + case_1.pop(i) + case_2 = line[:] + case_2.pop(i+1) + if is_safe(case_0, False) or is_safe(case_1, False) or is_safe(case_2, False): + return True + + return False + + return True + +safe = 0 +for line in inputs: + if is_safe(line): + safe += 1 + +print(safe) \ No newline at end of file diff --git a/2024/day03/README.md b/2024/day03/README.md new file mode 100644 index 0000000..eadf58f --- /dev/null +++ b/2024/day03/README.md @@ -0,0 +1,70 @@ +Part 1: `174561379` + +Part 2: `106921067` + +[--- 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](/2020/day/2). 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: + + + +``` +x*mul(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: + + + +``` +x*mul(2,4)*&mul[3,7]!^*don't()*_mul(5,5)+mul(32,64](mul(11,8)un*do()*?*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?* + + +] \ No newline at end of file diff --git a/2024/day03/input.txt b/2024/day03/input.txt new file mode 100644 index 0000000..3762ef9 --- /dev/null +++ b/2024/day03/input.txt @@ -0,0 +1,6 @@ +why()}''(!how()$~mul(420,484) ]}}mul(218,461),]/select()mul(93,56)';$-;*#$mul(162,415)mul(556,374)when()~when()<[select()^<(@mul(561,946);mul(97,699)select()+%when()~who():mul(387,15)>mul(927,207)~>~when()*who()'do()mul(454,740)when()%from(),~@%]from()mul(54,688)mul(338,694)what()select()~!< <;+/mul(373,536)&+mul(505,931)why()[mul(457,381) >/ mul(800,67)why()~what()[mul(807,815)&$who()mul(667,529)&how(843,372)what()mul(636,823)?*who()mul(960,331)where()?mul(648,668)how()/who()why()!'mul(649,819)[~:how()&what()]{mul(857,238)%-mul(603,559)mul(511,89):mul(888,328)*how()$/}]mul(177,966)who(777,724)why();:;mul(211,756)]:}+mul(297,394)>^how();$[mul(603,264)mul(794,883)when()why()~&select()from())mul(446,859) & ;:>?*what()/mul(388,763);},?when()do()where())<->what()mul(974,397)+why()select()#@mul(137,814)@when()why()when(697,786)mul(897,431)^}}&mul(74,810)?<&~] '&$]mul(49,565)(>where())]/mul(926,812)mul(842,573) how()-mul(126,526) @mul(818,934)?select()}^what()who()from()}mul(240,118)!from()^@?what()mul(77,983)+$what()mul(736,950)$&%?why()select();mul(213,409)where()*&*what():>~when()when()mul(87,245)$^ what()]&#select()mul(558,637)why()!mul(695,929[;*)+??mul(896,494)when())who()select()^>+how(641,113)mul(374,932);^?:where()>mul(780,265)^#;+when()}}mul(218,272)@$#mul(892,55)[what()?~{'when()}mul(527,984) {>?-'+-:-don't()select()#;/?]''!mul(56,714)/why()>mul(819,178)*~[+}],mul(793,717)from(75,849)~-,+($/,mul(719,587)where()#:@;*$+#?mul(919,859)who()+what(), @;>mul(89,488)where()?from()#$mul(680,657)mul(619,642)?[+don't()$:]{select()$what()@mul(619,164)}!select()mul(528,754)mul(199,830)how()where()+from()/~$who()(mul(49,273(mul(32,974)do()*select()]mul(42,960)%@?:[##::mul(802,384)]{##where())what()[mul(610,271)how()#@>what()where()don't()'&)>mul%?mul(449,76)when()%[<{^mul(944,356)what()(*;<{$<~mul(476,918){who(){-mul(124,698);?who()who(610,775)what()'&mul(579,336)why()<{'mul(953,943):%mul(651,439)/who(870,472)from()select()( -] $mul(16,267)mul(865,452)!select()who(){)$%$mul(888,41)],when(737,918)[#@#'mul(655,759)}/$(?#do()when()how()mul(160,406)]$mul(392,433)([;!##^from()mul(56,722)what()*#%select()(>#mul(554,881)'mul(355,774)&/mul!~*)mul(32,426)where()[how()how()mul(160,991)(where()when()who()^{/why()mul(638,720)how()]]when()mul(617,160select()mul(728,694)+{why()mul(173,600)mul(846,617)?mul(630,82)select(450,31)mul(443,274){; ]when()-(#mul(274,844));];mul(69,98)how()(>#-select()%mul(121,360)!^! :<~why()#'mul(662,319):&%%%/;where(58,840)how()mul(140,256)#<$!when()how() <!(who()do()}!&?#(>why()~mul(914,702);who(222,816)how(){(&('^;mul(881,879)who()mul(930,525)when(),when()mul(882what()&from():where()select(){>?&mul(535,202)/[~'[?#<^mul(195,514)#!mul(69,391)!,why()[,#~!,select()mul(732,760'[^?-^]>mul(52,825)when()(^where()]select()@do()#why()mul(287,62),who() &why()mul(24,517)#) from()what()mul(411,475)what()who()~$&mul(963}*&^,what()mul(162,897)!@~~@mul(985,450):%}-$where())when()mul(164,716)mul(211,564);mul(886,158)where()% '~select()@select())mul(215,209)%from(){select()who()mul(310,717/^$why(414,216)#&,why()select()@mul(765,613)where()^#}#@when()who()@why()mul(320,608)*mul(572,911)do())>:&%;mul(172how())%when()+@%@<%[mul(279,942)%#*;('#mul(838,154)/?what()when()&;@%^mul(65,418)why(307,491)mul(252,964)#mul(428,463)@from()mul(463,946){&where(649,23)+&who()$?),mul(545,536)#how()$?do()?mul(799,451)->%@what()!~mul(685,980)why()<<{!,)[mul(542,862)?),]>mul(702,259)who()^@mul(563,554)}%:}]}-$how()mul(819,791)#do()#:[:(what()how()}&mul(753,669)<{] do() /where()~where()%*(mul(561,517)~@where(82,621)~&mul(21,397)%mul(585,719)]!$where())!^when()who()who(587,725)mul(694,254)'-[+>{:;mul(650,398)select()%mul(549,891)$: #-how())}}from()don't()what()#mul(90,910)mul(903,233)mul(547,208)[-:mul(368,116)what()>*{}select()mul(579,530)&?!/^mul(982,408))~;how()&mul(68,361)when()where() %)from()mul(830,253how(),mul(316,679)('/mul(147,773))what()')^+?mul(365,155)#}(who()mul(141,657,]@mul(437,176)where()':*%'')mul(420,497) +?)why(473,359)mul(550,773)why()who()%why()>;;)mul(47]{?mul(686,382)]&]%-)+&mul(540,547)how()mul(21,121)$[-/@mul(894,561)^why()~!''mul(76,341)&#why() mul(867,180)]@[@select()&why()^)mul(328,567)why()mul(500,955)mul(602,93)! #who()*~mul(395,822)?when()~[when():&what()from()mul(26,996)how()?from()[who()[how();,what()mul(127,564)+how()]>*)mul(326,149)}*mul(741,743)what()/-,where()select()$-mul(571,104)~mul(557,104)from()/]^&>how(){[don't()>#mul(243,161)what()mul(784,800)when()>%%^?]mul(969,40)what()$#why(201,806)+mul(287,102)mul(581,311)select()'who()@{^+why()mul(598,245))/?;${who(972,431)mul(766,217)select():}from()/when()/mul(746,688)?}@(<*what()mul{%#;from())from()why()mul(723,608)*]@{who()what()how():where()*mul(726,41)select();:what()~'how();~how()mul(352,571)>);from()]%don't())how()what()*]])who()what()mul(104,291)}:'why()where()what()<)!mul(294,381)[!~!@'mul(617,169)select()mul(597,322)@+:'<%@select()?from()mul(751,110)$^what(),?('who(375,411)mul(487,642)!$mul(602%?who()who()*why(517,725)who()%from()+mul(611,293)?where()who()*what()mul(572,491)%#^why()@why(559,20)mul(147,928@(how()$when();?{{;where()mul(235,699)]/don't()~>& mul(522,362)how()select()how()/,mul(808,332){@>mul(382,736)from()/%{mul(763,385)-&![+[-[mul(493,959)}$,what()%/}:mul(999,264)#:'what(923,646)how()mul,(({( !)^mul(774,947)mul(825,424)'when()&who(),?{'!:mul(645,624)({$}mul(755,196)how(256,304),^+mul(78,987)]mul(155,256)~mul(643,546)when()@;^&!%#mul(464,137)&{mul(549,85):#]}from()^where()from()from()*mul(471,24~$when()when()how(),mul(824,94)how()where()why() /&from()?mul(232,49)' *mul(587,107)[{why()[from()%when(17,197);]+mul(728,869)what()how():mul(85,612):)#;where(),>mul(992,351)mul(149,626)*;}]mul(185,920)mul(258,257)'how()]@select():( how()>mul(891,488)}when()${~how()mul(69,62)/;do()$;?how(548,712)%mul(163,414)&~do()$:where()select()*why()*/#,mul(245,774) ^where(458,665)] --what()mulwho())~'^?^don't()){}#&<]~mul(894,110)/mul(28,62)%^&*'?what()%select()mul(490,609)[do())$when()@{$] mul(446,48)}when()+:(>'[mul(975,915)mul(282,257)}mul(504,101)what()$)$select()mul(799,76)~/mul(157,178):%why()who() $>+mul(136,339)'-;[>mul(424,206)(-what()-why()#$mul(855,735)when()%]?when())#~*)mul(422,548)mul(403,999)'&( ')select()mul(262,876)&'&}^]what()'~mul(304,364)&)when(472,742)mul(923,176)mul(431,469) #;why(){?mul(330,297)mul(328,720,!from()who()how()[mul(92,961)where()>;mul(157,314-&{:>~{&^?mul(91,266)$~:[mul(875,759)?<$when()%,&[#mul(214,511)where()mul%,)@how()@ ]how()#&mul(506,250)how()from(){,,?]]&(mul(67,306) ^-do()mul(87,147) +#!/usr/bin/perl&~?mul(433,7)^select()don't()($who()>->{mul(572,795)>#}what()mul(428,863)#~mul(408,652)from()when() why()+/#@select()[mul(940,728)who()[how()mul(246,59) ;}+mul(498,374),:mul(489,557)mul(737,804)where()?@#&@where(623,413)!mul(328,754)~'?mul(612who():^$(mul(72,123)',&++who(208,919)mul(18&mul(575,80)when(835,393)why()when()select()mul(362,743>$from(95,887)%>&[;do()$]from()&-what(),who()@)mul:#why()?[':?~ ^mul(633,858)&where()where())#^-from(252,913)mul(126,973)%from()>- %mul(670,112)<%{from();)(mul(386,975)][#-@mul&)where()who(),mul(790,566)mul(542,715))mul(264,826',mul(935,548)how(),why()}(}mul(164,558)})select()who()@select()(mul(165,31)?>?;,~+*<$mul(341,516)%/mul(147%when()why(611,793)]mul(162,61)when()+how()'%why(409,154)mul(571,437)mul(522,596)/how()select()how(29,352)why()what():mul(467,537),how()]*^,%mul(974,626)~ $when()*select()+mul(424,960)from()(what() &;from()how() mul(332,298)+![where();select();from()(mul(613,817)^#when():;~;:)mul(632,893)how()>mul(211,720)how()!*+)]from()what(){mul(833,547);( /how(473,744)mul(614,72)~~#@select()how(),mul(324,924)~#'-;}?/mul(679,438)#@how()!mul(261,94)where()#~~mul(531,950),select()/+^>mul(387,794)$:{who()%!}mul(732,253)&why()mul(464,965)/mul(970,460) select()~mul(130,649)#mul(594,237)mul(715,98)mul(949,543)mul(341,112)$:mul(802,786)'who()%(*[>why(){how()mul(991,224)%mul(187,549)mul(780,836)from()!';!{&[mul(650,459)/]];select()#$select()^mul(273}># what()[(how()(mul(520,113)mul(616,814)mul(759,564)#}, /+)$)/mul;:^%~@mul(716,211)%who()what(),($mul(347,498)*-*&&mul(46,914)+;])>?mul(119,463)?%*-^+-*mul(281,195)*}mul(286,732#@,@when()*&:*>mul(945,971)-?mul(187,286)}how()^(how()where()don't()mul(156,64)},[why()?-/ when()mul(113,825)?)select()&?when(){mul(13,265)?~^,#how()mul(66,66)[{$ @?^^*mul(132,363)*}',-)what()/mul(373,957)when()mul(319,15)-%select()([+<:what()do()/$;)-]:@why();mul(597,465)-from()who()?how()where(){mul(836,692);[?,+<)mul(635,341)^;;why()+!(]mul(279,997):*'(^? mul(823,590))*'mul(822,370)?'-][what()*mul(953,604)mul(535,413),when()${+~)mul(484,759)mul(871,854)* {]>how(712,670),mul(373,823)+when()*{],#mul(159,820)[#^when()%&when()mul(799,36)+mul(315,321)&,when()%-]mul(548,25)select()&{why()from(197,262)]#?mul(358,469);'}mul(281,747)#why()mul(190,780);-/where()>mul(353,297)*why()[select()mulwhen()why()mul(578,187)*(mul(414,374)^~{when()mul(203,987)* when() (-#mul(441,105)from()+/mul(358,845));:where()from(308,392)){mul(886,76)@mul(675,177)where()when()]mul(380,191)when()('from()(select():mul(430,140);/select()how()mul(619,859)%#mul(606,253)/@*mul(40,538)>*]mul(989,612)!mul(765how(273,470)[why(630,394)what()how()what()mul(290,587)what()''?select()>>mul(916,886):($#);}};mul(743,103)/?&#what(713,97) when()-don't()^mul(164,643)+%$'mul(615,169)select():from(203,20);:&<( mul(643,22)when()+}({+from()mul(864,803)what(143,291)why()?select()who(596,912),]&do()where(18,622)*what()mul mul(668,272):how() when()(([*(mul(490,117)how()^ &don't()what()@where(){&mul(431,252),##>^%mul(928,524) +mul(508,343)mul(14,808))/&mul(247,330)@'{mul(759,514)%?[from()']why()what(886,988)-mul(777,371[^ ;,why()do()mul(378,492) ,+!)from(410,175)where()mul(799,619)mul]:{$select()@,;!mul(535,785)where()from()'$*who(740,392)where()(mul(140,345)}-who(823,81)}%mul(183,163)/mul(950,595)~{:%from()>from()when()why(86,638)mul(730,655$^{-}-,mul(938,511)$who(){}~'$mul(659,791)#^mul(339,535) %:@why()}mul(57,448)who()')mul(863,872)<(*select()why() ),mul(121,155) '~~~select()how()when()$%mul(732>^;select()mul(913,601)]select()]@when()[(>>mul(697,273)} /don't()%mul(757,595);$@$>where())mul(818,23)>$~mul(649,864),{how() ;*[where():mul(342,657)^~select()]-mul(694,462)%]what()<};mul(697,789)who()[mul(578,235)who()mul(186,328)mul(554,733)!>#){;@mul(138,929)mul(25,167)from()]%from(417,645)(when()where() ',mul(361,155+mul(203,77)where()];mul(839-+mul(328,209)? when():*mul(686,850)-mul(604,374) ?#mul(68,860)>?(%^],select(709,64)?when()mul(548,321),) !>how()select()mul :+>how()%^@~@%mul(276,13)mul(692,25)$]from()/> mul(366,243)'*~}#select(){mul(691,190)!how()!#}~%do()<+what()&'~,+)mul(370,234) from(),mul(712,897){$#mul(579,611))/['mul(840,718){&^(mul(641,81))*how(934,603)[&'how()^*mul(938,975)],{:%mul(747,483)#/}$^~why()mul(817,775)%}select() mul(273,96)mul(734,544)([##-where()mul(541,401$(}{,select()why(66,543)!mul(997,378)>how()!!;+))[mul(857,880)when()where()where()how(417,939)how(): mul(22where()/mul(938,942)>[[>how(), mul(552,726)mul(139what()from()why()mul(753,798)why()['+!!where(332,736)where():mul(465,371){}from(){]}[?where(860,482)mul(423,396)mul(677,239);^<]{{#what()mul(341,814)from()]-$#]^{ don't(){;who()}$mul(303,894){mul(100,628)]mul(481,789)^,mul(420,12)#]select()@&do()(mul(866,134)why();when(73,8)where()mul(971,422)mul(425,573)do()what()@{}#*mul(794,302(~from()%mul(777,75)-%%[when()select()mul(22,151),when()mul(983,529){?from()+[)*[what()[mul(4,608)mul(979,779@>what()$mul(138,543)mul(646,239)'mul(393-who()&!%who()where()mul(986,403)$],)<[mul(981,986)how()(select()!]mul(744,394)when()!*from()&why()how()mul(93,727)$what(506,382)[?~(who()<$mul(424,603)[&}?&why()]%mul(297,910);who(702,130)}select()who()(> +mul(860,951)$when()*who()[#+mul(431,588)how()+/:(%)>from()mul(8,460)(/:@!why()+mul(556,634)@?how()}@}}/^!mul(588,147)from()&when()@mul(499,831) +};who()!why(300,973);[@};mul(475,184)'+what()'how()mul(696,749)how()from()what()mul(294,115)@who()#[mul(409,579)?select(94,587)%)-~mul(541,209)^who()from()-who()}(-mul(612,20){[why()+* $#from():mul(727,495)/>mul(174,985)mul(563?%[how())(from()${;,mul(420,889){mul(350,415)%&??>{mul(408,995)(% $(why()+who()**mul(460,467),@}#(^*~>)mul(133,225)&/mul(587,173);/mul>+why()<,@-~[~!mul(622,327)$]how() @where()who():mul+*~-$>/ (where()mul(684,509)^,why()}$!mul(929,986)$+[]- $;mul(119,51)- who(){#)mul(50,335)*;>?^select()<-mul(660,21)when(),mul(585,125)(mul(583,688){/why()>why()!mul-)^where(317,550)]when();who(877,651)!mul(77,828)~^@from()where()mul(901,180)%from();what()())mul(359,130)mul(732,295)>:<<^mul(686,46)from(){:?mul(744#(}how()from()#'when()'mul(375,566)*mul(177,377),what(205,216)mulmul(511,997)}?how()where() select(294,364)how()]mul(975,7!-how()&?)mul(21,362)^&from()~mul(718,676)mul(87,923)}{,mul(988,768)]*<)?(!mul(198,629)#'/+select()mul(330,891);:where(701,805)where()/*/&)>mul(745,580*#mul(70,983)-who()#how())mul(283,218)mul(920,709)[from()^mul(447,444)<)]?select()mul(514,715)why()^from()({mul(616,746) #&how()where()>&&mul(819,532)+select()+mul(203,692)%(:(]+^#mul(75,664)}?%mul(506,516)'mul(967,985),mul(252,812)$'&+@!mul(69,311)!-}'~![mul(748,794):why()^>who()/mul(355,985)#?#mul(150,45)%{/[mul(249,182)##don't(),'?$~how()';mul(286,220)(~}:[:mul(297,443)mul(35,888)^@@from()why() $;;mul(417,143)when()mul(910,829)@mul(715,749) {~where()#*,/,mul(565,17);->mul(576,280)what()[from()[@mul(184,166)from(401,94) mul(569,96)-%{#{*when()mul(994,408)@}*mul(443,685)<-]}~mul(372,670)@};mul(376,74)mul(457,809))]mul(442,658)>)mul(503,506)mul(66,112)how()+!how()]select()who())mul(87,307)+[(mul(621,443)(:how()+:>don't()why()!how()>how()mul(674,840)what()mul(795,512)-mul(401,54)+/@+{!mul(691,931)?what()++[when()mul(442,585))~when()+-when()'select()mul(842,765)mul(62,265)(&who();who()(when()mul(194,966)*(,?mul(894,538)what()+]@&? mul(183,809); >%~what(840,775)who();when()mul(660,286)mul(355,338)>from()where()-$/from();,)mul(562,357)how()^mul(897,481)]why()mul(75,576)when()$]from()mul(509,51)(why()mul(910,246)/mul(325,400)+,+/[who()mul(303,777)when()&)/when():,/,mul(701,365)why():&mul(789,577)<&mul(620,292)what()@*-{ diff --git a/2024/day03/solutions/part1.py b/2024/day03/solutions/part1.py new file mode 100644 index 0000000..7e279ab --- /dev/null +++ b/2024/day03/solutions/part1.py @@ -0,0 +1,17 @@ +import re + +with open("../input.txt", "r") as fp: + inputs = [line.rstrip() for line in fp] + +def mul(a,b): + return a*b + +mul_reg = re.compile(r"mul\([0-9]{1,3},[0-9]{1,3}\)") + +sum = 0 +for line in inputs: + result = re.findall(mul_reg, line) + for group in result: + sum += eval(group) + +print(sum) \ No newline at end of file diff --git a/2024/day03/solutions/part2.py b/2024/day03/solutions/part2.py new file mode 100644 index 0000000..26b268b --- /dev/null +++ b/2024/day03/solutions/part2.py @@ -0,0 +1,23 @@ +import re + +with open("../input.txt", "r") as fp: + inputs = [line.rstrip() for line in fp] + +def mul(a,b): + return a*b + +mul_reg = re.compile(r"mul\([0-9]{1,3},[0-9]{1,3}\)|do\(\)|don\'t\(\)") + +sum = 0 +do = True +for line in inputs: + result = re.findall(mul_reg, line) + for group in result: + if "don't" in group: + do = False + elif "do" in group: + do = True + elif "mul" in group and do: + sum += eval(group) + +print(sum) \ No newline at end of file