From 9be714c9b86b5cf7acc761ec5e6e45ba002ce8d2 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Mon, 2 Dec 2024 10:18:38 +0100 Subject: [PATCH] DayTwo_1 --- 1/HistorianHysteria.ipynb | 176 ++++ 1/input.txt | 2000 ++++++++++++++++++------------------- 2/Red-NosedReports.ipynb | 187 ++++ 2/input.txt | 6 + 4 files changed, 1369 insertions(+), 1000 deletions(-) create mode 100644 2/Red-NosedReports.ipynb create mode 100644 2/input.txt diff --git a/1/HistorianHysteria.ipynb b/1/HistorianHysteria.ipynb index e69de29..16cec63 100644 --- a/1/HistorianHysteria.ipynb +++ b/1/HistorianHysteria.ipynb @@ -0,0 +1,176 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "--- Day 1: Historian Hysteria ---\n", + "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.\n", + "\n", + "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.\n", + "\n", + "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!\n", + "\n", + "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.\n", + "\n", + "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?\n", + "\n", + "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.\n", + "\n", + "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?\n", + "\n", + "For example:\n", + "\n", + "3 4\n", + "4 3\n", + "2 5\n", + "1 3\n", + "3 9\n", + "3 3\n", + "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.\n", + "\n", + "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.\n", + "\n", + "In the example list above, the pairs and distances would be as follows:\n", + "\n", + "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.\n", + "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.\n", + "The third-smallest number in both lists is 3, so the distance between them is 0.\n", + "The next numbers to pair up are 3 and 4, a distance of 1.\n", + "The fifth-smallest numbers in each list are 3 and 5, a distance of 2.\n", + "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.\n", + "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!\n", + "\n", + "Your actual left and right lists contain many location IDs. What is the total distance between your lists?\n", + "\n", + "To play, please identify yourself via one of these services:" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [], + "source": [ + "listone = []\n", + "listtwo = []" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [], + "source": [ + "with open('input.txt', 'r') as reader:\n", + " lines = reader.readlines()\n", + " for i in lines:\n", + " temp = i.split()\n", + " listone.append(int(temp[0]))\n", + " listtwo.append(int(temp[1]))" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1388114\n" + ] + } + ], + "source": [ + "\n", + "listone.sort()\n", + "listtwo.sort()\n", + "\n", + "summ = []\n", + "for a, b in zip(listone, listtwo):\n", + " summ.append(abs(a-b))\n", + "\n", + "print(sum(summ))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "--- Part Two ---\n", + "Your analysis only confirmed what everyone feared: the two lists of location IDs are indeed very different.\n", + "\n", + "Or are they?\n", + "\n", + "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.\n", + "\n", + "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.\n", + "\n", + "Here are the same example lists again:\n", + "\n", + "3 4\n", + "4 3\n", + "2 5\n", + "1 3\n", + "3 9\n", + "3 3\n", + "For these example lists, here is the process of finding the similarity score:\n", + "\n", + "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.\n", + "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.\n", + "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).\n", + "The fourth number, 1, also does not appear in the right list.\n", + "The fifth number, 3, appears in the right list three times; the similarity score increases by 9.\n", + "The last number, 3, appears in the right list three times; the similarity score again increases by 9.\n", + "So, for these example lists, the similarity score at the end of this process is 31 (9 + 4 + 0 + 0 + 9 + 9).\n", + "\n", + "Once again consider your left and right lists. What is their similarity score?\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23529853\n" + ] + } + ], + "source": [ + "occurance = []\n", + "for i in listone:\n", + " occurance.append(i * listtwo.count(i))\n", + "\n", + "print(sum(occurance))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1/input.txt b/1/input.txt index 766c833..efba5ed 100644 --- a/1/input.txt +++ b/1/input.txt @@ -1,1000 +1,1000 @@ -35446 18696 -46314 66062 -33933 83974 -83974 34443 -98207 12657 -38488 57125 -95930 81859 -52767 12657 -16477 53659 -14481 84757 -29083 51122 -36158 15438 -61387 10295 -76932 66328 -36700 83181 -90500 70317 -55528 55820 -31179 94554 -22822 16886 -23069 99080 -69000 50666 -91611 49688 -10965 12657 -62470 27096 -38922 83974 -88317 67082 -49184 78816 -46731 90213 -56390 89965 -67724 21120 -60777 88500 -38607 91051 -89620 42599 -19492 59958 -12399 89965 -14491 21092 -89224 65224 -92053 89616 -61752 33001 -14662 46961 -62308 99609 -63106 37570 -98323 89620 -10130 47868 -44468 92294 -55055 99080 -21162 23460 -62629 83614 -64760 76835 -59948 58492 -93112 81859 -19027 67250 -68050 27547 -39607 27547 -72923 77124 -59390 45817 -33001 47868 -70458 64427 -36441 47868 -44963 70577 -56327 83974 -35920 89031 -56574 16410 -19886 20797 -10538 56032 -43629 89965 -40166 54408 -71819 87037 -71239 58805 -84091 36969 -27282 83974 -61675 83974 -13092 65566 -22564 69172 -73337 83623 -65255 88498 -14204 49627 -90941 12657 -12650 65455 -39913 16886 -91204 42662 -12353 24980 -86940 43602 -45417 86117 -93805 13685 -86595 32060 -95504 49974 -49450 18696 -54656 82794 -24239 65070 -39200 94275 -45741 65455 -86169 41093 -30646 56972 -28947 45593 -27981 18232 -74967 83592 -28791 27193 -58805 69918 -41082 52767 -49770 52767 -40558 92562 -38248 72945 -51400 16886 -20599 11817 -77640 81133 -54049 56972 -82155 36807 -88848 49688 -74986 21092 -84534 83372 -52277 53938 -27375 46406 -82985 44993 -44699 83974 -56937 87037 -77717 49519 -97383 12353 -94620 17706 -93133 79684 -63717 33001 -13006 56032 -20078 55429 -68979 18696 -97191 84071 -47911 62971 -48256 56784 -34443 47868 -44941 56972 -43750 83153 -16717 42999 -36163 79265 -29877 82188 -54069 59608 -21897 70982 -46002 35871 -47632 28298 -92150 34443 -47440 90606 -21000 89334 -22797 91051 -67853 81395 -30016 59612 -65558 65566 -46885 12353 -49714 12353 -40300 27547 -97130 33789 -89917 70893 -99566 49688 -53392 56972 -92478 44580 -69059 12657 -88594 66111 -25017 51845 -66050 49129 -18086 33001 -44548 56032 -91368 26310 -90745 82691 -50489 65566 -29928 45682 -81859 89620 -74633 95869 -98553 47868 -80866 49688 -24016 20910 -36650 33001 -19561 74850 -63484 49688 -58451 18696 -29016 32060 -54718 25325 -89003 33001 -68471 11145 -88206 89620 -13290 66328 -86949 22014 -77758 88623 -75063 96681 -99425 31778 -71300 62538 -88500 11195 -78917 56972 -43065 88068 -33189 89088 -46705 83036 -56972 50663 -24844 91051 -57908 63316 -15446 88452 -76421 36179 -98232 25703 -37640 49688 -35383 44539 -11291 12353 -62140 83592 -55579 88733 -83570 87934 -76450 35834 -84820 47091 -24416 78402 -45763 65455 -82938 66922 -65397 65566 -45162 18361 -71395 72305 -72027 97029 -85465 28881 -32751 65455 -65455 80742 -79640 10727 -88492 84005 -66028 32752 -23677 43498 -22716 26101 -62036 87090 -18882 82877 -24085 91061 -97952 56032 -16125 12353 -69534 44480 -42997 33448 -45250 68695 -84290 92562 -22335 32582 -47550 99080 -36928 73869 -40790 11220 -41540 71545 -16448 67875 -44580 45593 -35045 70157 -69798 63807 -50519 97965 -69580 16886 -87702 24341 -57895 58808 -20766 27547 -74455 59612 -33358 83592 -80944 78627 -71806 29266 -88258 82877 -21771 64556 -88011 25173 -95793 49627 -95847 45593 -56747 12657 -32448 12657 -93453 50250 -72594 74557 -52172 18099 -93959 70300 -74332 38126 -79878 67746 -49680 54928 -18265 33001 -95331 59612 -18366 33001 -25504 88500 -62474 60901 -31197 29540 -66986 49688 -63340 88500 -69519 27915 -21052 52553 -72184 27193 -43404 49627 -95052 59327 -27977 83614 -13673 18696 -13363 27547 -82059 47868 -52928 82877 -55266 25800 -55292 89620 -66838 81751 -85014 62704 -18772 89391 -99322 39583 -68363 58608 -45148 58708 -63006 27193 -92687 12754 -55913 75671 -45593 65455 -79018 51305 -87110 56230 -66328 14246 -54561 53594 -56406 14740 -95001 49947 -12373 81859 -65064 16886 -17403 75896 -58690 53427 -50959 27547 -40939 52963 -50275 47946 -73990 32060 -39728 49688 -64531 74946 -44868 56972 -72719 27906 -35784 16310 -13911 26147 -45218 21092 -27025 54743 -64719 65566 -22135 12657 -13725 71262 -16787 49149 -26004 27547 -83956 25800 -20869 65750 -92705 49627 -41237 33001 -47868 54678 -46965 44772 -76833 67617 -10593 96338 -91447 12858 -41369 18696 -88036 97875 -56077 40100 -83258 73796 -17955 99080 -47587 12353 -71731 21884 -43926 76598 -26878 21142 -85135 21092 -13199 91051 -55583 72621 -72584 63423 -10908 82877 -59612 45593 -72725 95288 -22111 82877 -15422 16886 -51152 97377 -14804 61202 -62625 53427 -89653 38262 -13230 39503 -83705 39416 -88216 34340 -30601 23296 -86040 70921 -76367 32060 -17566 62842 -49688 26555 -51987 27192 -99083 16886 -50529 28284 -18618 92562 -49357 27193 -83692 27547 -34017 12353 -34588 65455 -79808 56032 -76557 83614 -52422 73787 -99664 83974 -23712 89620 -10628 79497 -35405 89633 -55143 97586 -97421 13687 -17759 32060 -94690 46885 -40501 39940 -41037 85460 -70591 40719 -64400 83974 -25588 12353 -92616 83974 -65267 12288 -21298 82152 -21216 24498 -83830 95148 -69200 34443 -92744 83974 -84255 72646 -60019 33001 -72406 89620 -80749 83614 -81952 73514 -80454 27193 -32161 15624 -96805 12657 -87229 45593 -52706 21688 -54224 33221 -59272 81859 -39664 89965 -52726 88500 -17451 53746 -53896 58280 -72032 56972 -41654 83606 -45801 76761 -59531 56972 -69619 65455 -47931 88500 -37408 15916 -46419 27677 -24027 99080 -87213 89400 -59190 71907 -91014 77947 -20262 52969 -99705 17001 -77899 98899 -66940 12657 -96845 16886 -85833 89620 -24005 72223 -70935 48677 -80570 92562 -14398 81859 -34541 83183 -28018 92562 -87037 90231 -71966 34443 -46070 83974 -28730 56032 -37205 65566 -78756 83974 -92078 88687 -84234 22235 -65644 83974 -69979 57474 -26206 40074 -10787 70635 -25443 81859 -16577 86943 -83988 11918 -12284 12657 -57347 16886 -25269 45386 -26028 52805 -28804 77340 -50690 72129 -79036 63115 -70738 71491 -66916 96652 -81977 46885 -43130 58805 -97899 98026 -50454 97303 -77142 33793 -20238 99451 -25279 49627 -37235 83614 -49627 84495 -40512 15742 -84237 18675 -57852 65767 -60277 53427 -60816 99080 -48621 62202 -48990 65455 -90883 47035 -32060 33001 -47930 56032 -53524 55589 -76420 16886 -12331 72983 -93348 48516 -21092 40456 -80416 62693 -18172 66930 -83267 47868 -56035 31836 -19129 12657 -31465 83592 -64173 33001 -74397 70918 -20717 12819 -51944 72328 -71053 27547 -80370 56032 -68857 90951 -48914 33001 -41820 53931 -31445 99080 -12669 38918 -79174 56972 -45196 22048 -43488 27193 -49986 39514 -65806 85882 -48018 89620 -86144 92562 -95852 58805 -47095 89620 -96313 45593 -39688 86998 -89088 56972 -10994 27193 -44290 45593 -32871 49668 -74126 69396 -59913 35109 -37148 83974 -56032 24108 -92348 23837 -76049 45593 -28805 74542 -35070 46272 -40283 47868 -32870 21092 -87890 11410 -85129 84836 -89021 23016 -54444 52767 -60250 15651 -82877 99080 -13101 66125 -95310 44178 -99602 87037 -39771 61194 -92562 67527 -26053 81299 -99211 52767 -31519 14876 -66988 89620 -55719 34142 -47519 37927 -81355 67645 -64580 83371 -53953 40028 -28575 23345 -88211 96106 -25538 33194 -35298 66440 -11466 12353 -33575 18696 -86250 59305 -84467 53562 -59023 91051 -81764 58973 -80503 18696 -73651 65455 -74173 65566 -59081 38453 -54695 27547 -25202 43565 -90138 53680 -87761 98899 -76616 26486 -98411 12657 -87945 89620 -69634 64725 -94813 92562 -64622 21092 -46511 18696 -49212 70971 -34375 23916 -64884 81859 -94136 95813 -89737 59612 -45383 16739 -60780 34100 -60956 56032 -27402 25216 -61698 78097 -77163 74327 -30740 83974 -78975 99080 -34208 88571 -74233 14179 -95918 47868 -74949 65566 -41203 47868 -27671 56032 -38515 20386 -82734 92813 -70727 25800 -10326 33001 -83563 45593 -46938 58588 -43092 65566 -96771 57693 -32365 21390 -65514 25800 -21151 91810 -53822 66328 -89965 49039 -97207 20005 -18794 23172 -85061 82877 -29500 93001 -86025 29962 -18550 74091 -92402 69893 -58049 16886 -47165 82877 -40002 81859 -82066 71414 -99593 12657 -95278 82877 -23474 33508 -26508 32060 -13412 78711 -58286 35717 -79549 25448 -59275 87684 -59102 83592 -59475 65455 -71391 49481 -64011 27193 -34907 27193 -96020 65566 -32676 48353 -82228 64987 -85683 33001 -84073 49627 -89790 91054 -79448 42717 -57726 66328 -30683 65566 -27124 74353 -13404 65566 -47973 32110 -75389 32060 -39880 90141 -47176 25763 -77298 75035 -36334 32060 -55391 40175 -75215 50282 -89669 27719 -36393 33001 -79118 21092 -81448 47868 -51834 49990 -40739 49688 -52754 56972 -35389 36568 -31791 30926 -44345 27193 -11231 58125 -21968 32060 -78789 12353 -81898 62528 -22004 84635 -50202 69626 -83592 51107 -58853 79346 -42190 68523 -45830 99080 -81738 12353 -99265 99469 -90691 38910 -38908 20889 -20275 89965 -24933 24939 -71243 83614 -67641 13684 -63940 34940 -16484 46405 -95114 80965 -52206 65455 -45310 68999 -76892 94531 -71763 25077 -28803 25055 -19132 65455 -62482 16017 -20185 65455 -53459 47868 -86711 18696 -25418 70965 -41208 97960 -18696 38086 -25923 21953 -90443 92562 -84272 27547 -58778 45593 -83614 10136 -46699 32890 -76064 27547 -99080 28452 -18497 12353 -60862 77196 -19752 27547 -22338 53427 -66112 32195 -41917 82202 -50594 45593 -15550 96715 -61435 88975 -96294 32060 -47560 77044 -60387 49627 -76943 45593 -78435 87312 -57089 89620 -97691 18696 -30869 76316 -51101 17127 -89100 49688 -28552 99080 -50599 21092 -62850 89620 -97312 27547 -81531 45593 -69183 54914 -88793 56972 -48548 45593 -66705 56032 -71169 16358 -55885 12353 -55064 66328 -59988 38915 -89486 45971 -66564 62229 -21432 73083 -69247 49688 -15787 12657 -91085 82877 -14618 12353 -99031 46480 -80969 91051 -68503 18696 -89919 12657 -97125 81859 -36492 34656 -50873 18696 -50741 27547 -27193 99250 -13260 89620 -70660 50852 -23872 40621 -23133 34336 -18937 49627 -84631 18350 -31466 97019 -82842 70754 -96642 16614 -99278 21092 -37578 44363 -87003 59612 -43407 43149 -73286 92643 -45369 18696 -60219 47988 -92605 12811 -80646 91257 -29493 25800 -64968 16886 -67454 56032 -39669 52921 -45812 92562 -98524 34245 -68102 13668 -33914 59590 -90204 20381 -78331 21373 -41990 17121 -98264 13737 -12657 97505 -14876 12560 -86663 13560 -81960 46045 -94521 12578 -84699 89846 -65933 89620 -69417 46940 -77051 30362 -75075 44987 -33494 56972 -49618 81859 -71385 41628 -72195 47868 -62025 65455 -23253 49627 -70062 81859 -14577 16886 -72180 61232 -92457 12657 -91879 53427 -49809 97285 -73214 49688 -63136 65455 -25107 99080 -77516 18306 -84079 45956 -68470 12935 -80077 35901 -33487 93929 -98439 81859 -25106 49627 -29578 21746 -41763 49627 -38888 82877 -21105 59612 -27547 85476 -34649 96912 -98652 37966 -26548 51315 -91140 70379 -88522 66328 -18801 81859 -88360 27197 -54575 33001 -54004 83017 -50564 99080 -19887 42385 -65566 93192 -13908 81859 -38021 51863 -53431 65566 -63143 49688 -77152 16886 -95334 94999 -99112 84555 -22226 47868 -81497 25800 -56613 89560 -32899 66913 -73926 32060 -14710 59039 -81998 56498 -51537 23626 -92298 72999 -61627 48753 -25800 33001 -89153 35814 -15490 59612 -98839 49749 -88591 27547 -47330 83974 -94242 38771 -30493 25606 -47111 97620 -76006 83974 -88435 49627 -12581 14185 -52999 82877 -64534 46741 -70617 18696 -78842 89208 -72607 51926 -44479 91090 -32783 26114 -27725 65566 -71384 17667 -75007 81596 -25465 98911 -97702 81141 -87869 32060 -85114 81859 -67686 97990 -22260 12353 -67159 32060 -97547 16886 -26163 79445 -90733 83974 -62958 47018 -87531 53073 -28421 82286 -31349 92110 -62113 17868 -59754 42706 -82004 12353 -69805 89458 -73669 77228 -36269 97413 -35228 27547 -38938 12657 -88675 89620 -90579 71041 -89858 83974 -19686 18696 -16625 49627 -91432 81859 -17607 83974 -89530 45593 -40107 56032 -28095 41567 -93573 70856 -85006 18696 -19091 45593 -82765 12657 -20545 24253 -24106 49627 -60438 88622 -27926 16886 -97985 89965 -79204 89810 -91051 83614 -75382 82877 -50290 96422 -66045 81859 -61679 35777 -46984 56988 -18043 21092 -53300 90453 -57214 78410 -11949 81859 -45225 22918 -82542 65566 -11498 27547 -44155 56972 -97659 13416 -64945 53035 -10456 52940 -66710 16886 -52752 68386 -21492 63909 -10804 70233 -53427 70763 -81459 89620 -24486 29799 -94315 88192 -99345 81859 -26426 16886 -59747 65455 -78335 28188 -76856 55257 -38024 89620 -76867 76062 -25261 27547 -21948 44580 -25796 49407 -26541 34513 -85517 29546 -51634 23929 -16886 98484 -94563 31195 -94244 82759 -19517 83614 -15629 47203 -13661 64125 -54946 63802 -69496 18696 -10488 32505 -92729 23426 -28136 32060 -55489 83964 -34355 47868 -75542 76179 -70632 99080 -29904 71317 -73989 53368 -86241 48586 -82353 46831 -78028 53147 -92984 83641 -55747 21015 -17389 18696 -94992 29411 -69555 88500 -66820 26798 -96784 92681 -19019 99080 -67383 42448 -64708 12353 -20616 92061 -22213 89965 -34850 12996 -99572 36736 -76670 92372 -11930 91013 -18321 99080 -42025 57447 -99887 75845 -95958 48242 -44579 18696 -79387 34443 -82753 27308 -93967 52098 -90819 66336 -38322 35403 -10019 12353 -78459 37576 -69905 16060 -14796 98743 -14487 17417 -79979 66300 -59836 12353 -37308 56032 -63835 88500 -30048 79432 -71914 99080 -76352 56972 -74621 56972 -33804 98899 -23449 33001 -99868 27547 -57457 83513 -44296 36718 -43642 99921 -49243 90701 -28205 27193 -98899 19172 \ No newline at end of file +62619 25903 +30326 94750 +84092 60901 +37915 71402 +15035 84878 +18777 73294 +95618 11556 +40228 14340 +64337 95628 +74895 95628 +60933 57743 +63659 71402 +96094 71097 +83473 16153 +37963 81398 +28922 62792 +33312 56198 +33041 32752 +42401 98096 +91919 15189 +90401 91974 +59102 81363 +36684 83913 +77675 26541 +20021 57743 +60735 67798 +23105 29010 +86145 20180 +34121 42958 +45549 94750 +21335 97630 +30251 83564 +98372 27653 +60916 15189 +81588 93448 +31108 43699 +57324 77707 +62333 95456 +63344 70149 +18409 84619 +39611 51457 +60844 56450 +24661 20851 +83216 54572 +26451 13071 +40779 25903 +69948 80817 +80307 79233 +74779 15189 +51254 25615 +78563 21903 +44445 11964 +19525 66306 +59383 24932 +51882 27120 +15214 94897 +25903 62440 +19142 37258 +89958 55770 +93819 95582 +92302 60901 +92207 21547 +46605 72682 +47019 87607 +91181 18344 +33427 58733 +63738 67384 +58722 92349 +68791 62680 +37498 71342 +42522 37702 +36868 17661 +93701 66457 +59077 81363 +29985 32727 +97380 39888 +91074 51996 +34578 43591 +36474 76040 +83694 30713 +23025 21910 +65352 18691 +26765 46401 +29699 58503 +22892 42958 +33183 14340 +93681 94750 +87781 44627 +73912 61890 +69862 47551 +83666 50441 +14505 93279 +76546 60901 +85046 15189 +96647 63933 +20361 60901 +54414 74008 +73807 42958 +88028 37620 +47837 67798 +39975 79734 +59258 37388 +30532 95336 +63303 99491 +29900 77971 +18886 30672 +69149 16262 +71315 12428 +92786 77707 +81870 71402 +28377 80029 +38482 83084 +42311 43457 +40133 67348 +47350 58722 +94899 39437 +80383 73056 +50777 29099 +82097 66680 +57866 94991 +93259 95336 +83163 66970 +12322 68796 +86718 60901 +62860 16276 +61538 74693 +78862 71402 +71051 79270 +65274 94750 +95081 95454 +35994 69752 +23142 21903 +41794 28870 +81143 82713 +98552 53936 +42716 27120 +31949 81363 +24961 69060 +37205 12866 +53468 93380 +56879 73099 +68473 63243 +25609 86891 +63903 58722 +42541 42958 +95908 40858 +80056 74693 +23919 68796 +88345 37620 +47504 51825 +63031 43591 +83304 92302 +44174 18382 +53110 27120 +92382 57743 +95060 74693 +20870 31509 +38624 73935 +23048 21277 +71387 51004 +94750 71744 +86172 42002 +66293 20509 +17059 42958 +67035 10373 +75394 37620 +41855 43093 +23490 70386 +14833 60901 +17857 59270 +48666 62028 +19457 15189 +97382 74244 +59739 52959 +45275 92302 +15577 57743 +87651 18920 +98358 58538 +56785 68796 +17775 94456 +68554 36320 +85702 54050 +12351 64531 +75012 73099 +24159 72040 +14167 95347 +90037 27340 +57691 43591 +47008 18691 +10950 69642 +57987 23221 +77285 25903 +54353 19109 +75869 79832 +50446 46147 +84638 42958 +17751 60901 +67211 58733 +44169 48158 +91044 38933 +79885 11964 +78386 67798 +69398 72938 +21600 84819 +50224 81272 +78056 88646 +56837 31411 +39171 61608 +78080 43591 +54257 92150 +82021 15189 +19615 98246 +24648 76873 +45477 11964 +59179 59232 +66194 25903 +40847 58733 +34375 33041 +11740 67798 +94666 55770 +68611 91621 +91769 13515 +35492 58722 +84448 92302 +56613 62766 +99254 74693 +96650 10088 +39437 51388 +33069 91054 +52418 71402 +75251 80449 +31445 36392 +71195 53910 +72666 41650 +17608 95908 +12078 45665 +17604 64904 +78291 34090 +57437 57743 +91805 96758 +99250 95908 +64757 58722 +87843 64996 +88951 45003 +74539 77911 +58846 18920 +16307 94750 +69837 95908 +76898 40815 +16205 71402 +98688 46854 +69901 42958 +53438 34139 +19832 60901 +71402 55957 +38182 59508 +75973 52291 +63146 58733 +38891 52963 +83937 42855 +13073 58733 +25736 58733 +25961 91001 +98087 36622 +62673 45577 +81720 30395 +42981 58722 +99960 94750 +89819 73483 +46042 93254 +94494 58722 +90404 16308 +88078 95908 +59505 94750 +94839 18691 +51439 60901 +45408 94213 +46301 96771 +82342 95336 +87415 50494 +68995 18920 +69097 57463 +52090 76541 +57743 71402 +92558 26149 +33393 14340 +17956 77707 +93740 44925 +84324 81363 +99452 11104 +77578 58733 +23972 67830 +95336 94750 +96712 98246 +41647 76926 +74996 47307 +31798 81363 +84956 55640 +33185 57743 +74028 83220 +12168 40375 +27300 95908 +73132 82757 +11593 37620 +76794 99477 +53045 67798 +16203 67839 +43013 30796 +21653 66822 +99785 60901 +41534 99505 +34746 98777 +91326 15189 +41238 10056 +27120 89435 +61455 55770 +32332 12560 +74212 58722 +79815 43591 +51266 24297 +29290 42582 +32564 81503 +33451 58722 +74693 44992 +90825 95908 +18434 37620 +51381 69567 +51357 80756 +41367 42958 +18034 87111 +35090 48309 +52050 19848 +31615 18691 +26163 55382 +54155 98380 +32766 95628 +66811 70762 +56835 74954 +68966 98773 +64000 80941 +17133 28149 +46113 11964 +44129 95908 +75450 11493 +33226 67397 +61957 64071 +75928 43095 +93920 67730 +65403 24083 +43381 95908 +81291 46446 +41878 68263 +92914 41085 +34436 57743 +79389 40570 +56226 23464 +79465 94750 +30601 22367 +74416 85052 +69119 20905 +78029 31117 +56600 20434 +88792 76040 +70653 15946 +26166 44783 +29517 60996 +85852 80100 +39106 11294 +77438 83568 +37856 46541 +58097 37572 +83261 77394 +71449 21903 +15327 71144 +66853 18920 +76787 51780 +62338 39437 +97231 72705 +93048 20279 +45014 58733 +48454 25802 +16977 52014 +24139 15189 +97186 68796 +63132 55770 +28951 95908 +52068 94750 +92193 25450 +94762 68225 +94439 75090 +49183 76040 +15650 72780 +43617 25654 +48000 57743 +44802 20665 +69533 40698 +99506 71402 +10188 81093 +45642 12405 +41525 95628 +63406 58722 +38086 82686 +78248 92302 +35534 25903 +40908 60096 +34570 54450 +50290 20272 +49022 76863 +69525 15189 +77707 77671 +72455 71402 +26834 55770 +68910 42924 +54344 16132 +67895 92302 +74034 55770 +29963 11964 +28687 48072 +47125 58722 +15698 23211 +25279 33041 +35856 58733 +29506 92630 +83164 58503 +25652 43591 +10150 60901 +68681 75492 +25928 62173 +90996 60901 +34150 25903 +45505 24919 +32302 16979 +70135 60901 +47220 38697 +66939 18691 +60367 74693 +46402 54059 +37333 38708 +15675 56777 +94947 64270 +92421 64575 +18644 18920 +85453 55949 +24398 25465 +51537 60901 +73029 18691 +10372 21582 +13221 60772 +96312 48448 +41962 18894 +95628 25903 +86774 67798 +97328 94768 +12739 83965 +35805 55770 +71377 51057 +27624 21704 +47608 15189 +33867 40404 +97161 68446 +20645 11768 +14224 78983 +62080 95908 +19102 75534 +63525 59254 +17179 68796 +98286 45885 +34018 97839 +99672 15422 +76115 25674 +51884 85901 +34047 27120 +29743 21903 +93768 76389 +97460 34263 +19836 94750 +83921 86722 +65076 81363 +79604 45182 +73999 95908 +51995 44729 +46824 23356 +76384 95908 +45206 95435 +48366 72348 +37898 82291 +31126 58733 +22018 83516 +12071 67798 +83202 27120 +56135 58733 +75630 37620 +14382 65093 +45237 50541 +25430 29954 +28105 70054 +67794 58722 +35237 21506 +38802 62056 +60276 31607 +35441 47957 +16202 21963 +86355 16631 +73689 21903 +69007 30198 +45510 98246 +85154 11881 +62930 58733 +70284 37620 +49335 84284 +81363 88599 +59481 25903 +45212 47786 +15302 95908 +45855 37620 +88386 92865 +11859 37620 +73264 60901 +83068 42996 +84915 76266 +17696 95628 +14367 52703 +30852 76040 +71184 78571 +42578 22158 +41197 33041 +96461 98246 +97118 60120 +77919 13391 +11964 71571 +75993 93850 +76867 23238 +22690 95908 +23262 37620 +25242 25903 +73440 44034 +98379 41045 +15645 53820 +55979 45441 +98508 64885 +34278 91871 +92424 21903 +99804 27550 +98275 39480 +77311 66522 +71457 71402 +45125 58722 +46725 31005 +11667 35829 +88568 38127 +84705 93869 +49426 58722 +95141 37826 +60901 17434 +51036 13775 +66121 55476 +99712 76291 +64183 76040 +14340 42364 +41256 42609 +88529 38809 +24137 86477 +50030 84350 +28692 39437 +76103 18691 +55768 95504 +81529 82684 +32989 68796 +62430 57117 +47161 95628 +98041 77707 +17293 60901 +26322 25201 +18691 68796 +53748 27211 +79920 61870 +13414 98246 +37753 42958 +99192 43795 +47951 78295 +65705 80132 +93270 18691 +49617 22313 +58116 68802 +41599 77917 +88070 73053 +57636 74708 +61320 55770 +28126 68211 +45326 68796 +83242 78622 +64432 95336 +66184 14776 +79662 78288 +31559 31202 +55770 37957 +23887 14766 +42104 12084 +86533 73495 +66370 77751 +90530 95628 +95401 43591 +43376 95257 +70768 58733 +12478 71571 +15957 17223 +81250 57743 +60475 10079 +40232 74136 +19774 97772 +18621 16958 +14875 76440 +90673 30928 +23096 58503 +97595 45435 +73191 42958 +81767 97406 +54334 56241 +27617 47748 +74196 73890 +83232 16958 +75027 74693 +80951 58733 +34912 42958 +85763 46782 +46474 94750 +66031 90078 +84048 71118 +94904 37620 +65760 66261 +85805 41397 +71175 16972 +48344 75703 +13102 88952 +42495 95358 +26249 18691 +19568 58733 +31959 55770 +55075 71571 +32241 88856 +94349 14340 +15189 16227 +28021 74374 +13676 33041 +59997 24406 +54305 41257 +37110 55770 +35881 32739 +21529 12177 +79138 42450 +29787 24438 +34894 68796 +21203 81363 +56933 66257 +95760 97152 +60050 94750 +41753 34287 +39341 95186 +49927 42958 +74695 31124 +57847 92741 +20288 98129 +51699 52019 +19072 68796 +82231 43640 +60534 20761 +10461 58503 +36149 27120 +96959 79965 +77827 60351 +91876 56195 +25787 60363 +86997 67798 +68922 46729 +19622 81363 +66080 91186 +27682 55770 +25942 65557 +89459 14340 +79797 74254 +96138 98246 +33238 59314 +30173 67798 +95078 68796 +54586 39437 +75238 37620 +39202 29637 +16867 19899 +82302 53887 +45302 27732 +30954 95908 +83543 98246 +54381 95336 +34144 12236 +17402 90976 +92020 71571 +62781 15189 +29546 99770 +11926 90890 +69879 68796 +76480 16106 +33328 50342 +58455 58733 +86164 14225 +33489 92807 +76961 26383 +77335 89466 +26454 94750 +67798 52555 +92671 42002 +23218 60901 +58564 34904 +19943 11014 +16341 11964 +35741 37620 +25711 95628 +70338 23595 +73099 14679 +40606 57743 +79029 84965 +40776 84207 +57543 57743 +55122 67798 +54036 89387 +34686 95336 +78969 19676 +93072 27772 +81688 14502 +18807 15639 +70774 57743 +87430 74693 +91599 26911 +37620 39437 +61886 71402 +58325 62504 +42822 33723 +67981 95908 +48046 77843 +45220 45628 +78085 33041 +46449 58722 +98918 59087 +32267 76647 +31728 27120 +15735 10521 +57336 58733 +86936 74693 +73719 50149 +84110 74693 +31202 27513 +68796 77160 +58416 69672 +57865 37620 +71850 50968 +53522 77707 +21173 42834 +92464 92615 +29744 37620 +52306 22486 +98899 16166 +22476 91919 +59967 19305 +43591 36485 +31809 63171 +79033 56343 +67656 98246 +13587 95822 +27782 42530 +19352 22300 +96569 42958 +95188 73716 +85777 27120 +76336 25264 +11596 51174 +62131 35355 +32737 87896 +21792 94314 +97535 42958 +67772 30847 +23372 10581 +91532 33811 +55873 74693 +36678 12576 +45099 73044 +43192 55240 +21903 55521 +88321 67798 +24368 39437 +79046 21903 +22881 95336 +41519 18920 +33709 68796 +72476 25903 +58512 27120 +86413 14340 +72964 16152 +96531 19099 +98791 73099 +17155 90626 +42612 27830 +55602 12838 +25290 30145 +59246 42958 +66301 29947 +36333 96445 +24171 58722 +87662 10983 +42958 71773 +58636 68421 +98695 25903 +87852 33041 +74343 57743 +39643 33041 +85380 27500 +48388 42958 +37761 77707 +97130 37620 +43580 38826 +47926 98004 +90396 18691 +45920 71402 +81997 71402 +94726 94750 +48358 27344 +71254 22993 +80275 34237 +72241 72611 +34532 68796 +55121 34876 +29318 57743 +75556 21903 +91485 21903 +58503 37620 +76040 58722 +64723 58001 +66467 95336 +53823 12613 +48859 61366 +76368 18920 +26043 94750 +60819 43935 +49793 74693 +49787 20795 +23373 58699 +69380 73099 +75462 63798 +45493 77707 +33090 98246 +40903 27639 +96473 76040 +89947 55467 +97538 76040 +94950 97842 +83847 64791 +51408 85287 +90641 25175 +59205 68796 +37106 21903 +31891 69062 +52732 21031 +16958 21903 +12830 12782 +88886 21500 +96198 96776 +10176 25136 +71571 42958 +16588 60751 +49639 94413 +94373 37620 +57909 42958 +23337 70169 +40204 10854 +51290 89920 +57936 61689 +52963 95336 +78553 55770 +28898 94685 +56962 20975 +98246 27120 +13251 31202 +12386 16958 +44211 44328 +51354 95336 +51903 84162 +74681 67073 +78792 46321 +47448 76040 +54001 41269 +83049 71402 +18666 88848 +91604 77707 +18218 74693 +70012 74693 +64340 15653 +61733 94750 +53459 25903 +89495 48179 +50543 14337 +53778 68796 +19573 76040 +48966 37491 +79009 65520 +75853 64389 +72020 55770 +85683 36279 +14091 95628 +81225 85177 +20253 99653 +83272 12892 +80793 74693 +60228 51271 +25762 30744 +45133 41216 +20563 87233 +58733 68796 +18187 58733 +27577 74693 +19450 72555 +54043 43176 +48494 42958 +88375 99208 +72864 49040 +23351 45233 +89758 20480 +11846 71402 +71123 37789 +85916 73099 +26278 42958 +45147 40390 +47700 94750 +71287 43591 +21893 95628 +30860 91205 +88771 25107 +63695 15189 +54022 78028 +18920 18691 +54215 53466 +37444 55606 +33508 79502 +51867 25903 +11633 73099 +95809 57743 +59336 58775 +92131 73399 +80096 28127 +92889 37549 +58711 16441 +56446 95908 +78562 16751 +87872 94750 +81757 64583 +94079 25109 +57657 60516 +87129 85261 +24276 41375 +58930 42002 +99351 74693 +49268 42002 +42002 64504 +81164 30052 +33506 60901 +54186 99255 +84054 85285 +63793 71402 +84019 21903 +12310 27120 +37386 33041 +72232 52481 +50872 43591 +88150 39972 +36699 31090 +11657 88797 +66278 81363 +20963 61397 +12046 55357 +81706 82079 +39853 71402 +59229 21903 +29455 80276 +14789 15466 +51944 81395 +26965 60546 +74750 55770 +80093 74559 +40585 65129 +79995 14340 +91325 69036 +36866 32940 +96216 67016 +45649 43967 +63836 21903 +57153 67798 +65895 27120 +41014 58733 +81492 95336 +55192 94646 +74304 65351 +91142 74386 +61587 43591 \ No newline at end of file diff --git a/2/Red-NosedReports.ipynb b/2/Red-NosedReports.ipynb new file mode 100644 index 0000000..215e28d --- /dev/null +++ b/2/Red-NosedReports.ipynb @@ -0,0 +1,187 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "--- Day 2: Red-Nosed Reports ---\n", + "Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office.\n", + "\n", + "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.\n", + "\n", + "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.\n", + "\n", + "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:\n", + "\n", + "7 6 4 2 1\n", + "1 2 7 8 9\n", + "9 7 6 2 1\n", + "1 3 2 4 5\n", + "8 6 4 4 1\n", + "1 3 6 7 9\n", + "This example data contains six reports each containing five levels.\n", + "\n", + "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:\n", + "\n", + "The levels are either all increasing or all decreasing.\n", + "Any two adjacent levels differ by at least one and at most three.\n", + "In the example above, the reports can be found safe or unsafe by checking those rules:\n", + "\n", + "7 6 4 2 1: Safe because the levels are all decreasing by 1 or 2.\n", + "1 2 7 8 9: Unsafe because 2 7 is an increase of 5.\n", + "9 7 6 2 1: Unsafe because 6 2 is a decrease of 4.\n", + "1 3 2 4 5: Unsafe because 1 3 is increasing but 3 2 is decreasing.\n", + "8 6 4 4 1: Unsafe because 4 4 is neither an increase or a decrease.\n", + "1 3 6 7 9: Safe because the levels are all increasing by 1, 2, or 3.\n", + "So, in this example, 2 reports are safe.\n", + "\n", + "Analyze the unusual data from the engineers. How many reports are safe?\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [], + "source": [ + "A = []\n", + "with open(\"input.txt\", \"r\") as file:\n", + " lines = file.readlines()\n", + " for i in lines:\n", + " temp = i.split()\n", + " A.append([int(i) for i in temp])" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], + "source": [ + "correct = 0\n", + "for i in A:\n", + " ok = True\n", + " for j in range(len(i)-1):\n", + " if not i[j] - i[j+1] in [1, 2, 3]:\n", + " ok = False\n", + " break\n", + " if ok:\n", + " correct += 1\n", + " ok = True\n", + " for j in range(len(i)-1):\n", + " if not i[j] - i[j+1] in [-1, -2, -3]:\n", + " ok = False\n", + " break\n", + " if ok:\n", + " correct += 1\n", + "\n", + "print(correct)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "--- Part Two ---\n", + "The engineers are surprised by the low number of safe reports until they realize they forgot to tell you about the Problem Dampener.\n", + "\n", + "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!\n", + "\n", + "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.\n", + "\n", + "More of the above example's reports are now safe:\n", + "\n", + "7 6 4 2 1: Safe without removing any level.\n", + "1 2 7 8 9: Unsafe regardless of which level is removed.\n", + "9 7 6 2 1: Unsafe regardless of which level is removed.\n", + "1 3 2 4 5: Safe by removing the second level, 3.\n", + "8 6 4 4 1: Safe by removing the third level, 4.\n", + "1 3 6 7 9: Safe without removing any level.\n", + "Thanks to the Problem Dampener, 4 reports are actually safe!\n", + "\n", + "Update your analysis by handling situations where the Problem Dampener can remove a single level from unsafe reports. How many reports are now safe?\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "correct = 0\n", + "B = []\n", + "for i in A:\n", + " for j in range(len(i) - 2):\n", + " temp = i[:]\n", + " temp.remove(i[j])\n", + " B.append(temp)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "correct = 0\n", + "for i in B:\n", + " ok = True\n", + " for j in range(len(i)-1):\n", + " if not i[j] - i[j+1] in [1, 2, 3]:\n", + " ok = False\n", + " break\n", + " if ok:\n", + " correct += 1\n", + " ok = True\n", + " for j in range(len(i)-1):\n", + " if not i[j] - i[j+1] in [-1, -2, -3]:\n", + " ok = False\n", + " break\n", + " if ok:\n", + " correct += 1\n", + "\n", + "print(correct)\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/2/input.txt b/2/input.txt new file mode 100644 index 0000000..b49c10d --- /dev/null +++ b/2/input.txt @@ -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