diff --git a/5/Elements.txt b/5/Elements.txt new file mode 100644 index 0000000..dfaa29a --- /dev/null +++ b/5/Elements.txt @@ -0,0 +1,159 @@ +0 +500000 +1000000 +1500000 +2000000 +2500000 +3000000 +3500000 +4000000 +4500000 +5000000 +5500000 +6000000 +6500000 +7000000 +7500000 +8000000 +8500000 +9000000 +9500000 +10000000 +10500000 +11000000 +11500000 +12000000 +12500000 +13000000 +13500000 +14000000 +14500000 +15000000 +15500000 +16000000 +16500000 +17000000 +17500000 +18000000 +18500000 +19000000 +19500000 +20000000 +20500000 +21000000 +21500000 +22000000 +22500000 +23000000 +23500000 +24000000 +24500000 +25000000 +25500000 +26000000 +26500000 +27000000 +27500000 +28000000 +28500000 +29000000 +29500000 +30000000 +30500000 +31000000 +31500000 +32000000 +32500000 +33000000 +33500000 +34000000 +34500000 +35000000 +35500000 +36000000 +36500000 +37000000 +37500000 +38000000 +38500000 +39000000 +39500000 +40000000 +40500000 +41000000 +41500000 +42000000 +42500000 +43000000 +43500000 +44000000 +44500000 +45000000 +45500000 +46000000 +46500000 +47000000 +47500000 +48000000 +48500000 +49000000 +49500000 +50000000 +50500000 +51000000 +51500000 +52000000 +52500000 +53000000 +53500000 +54000000 +54500000 +55000000 +55500000 +56000000 +56500000 +57000000 +57500000 +58000000 +58500000 +59000000 +59500000 +60000000 +60500000 +61000000 +61500000 +62000000 +62500000 +63000000 +63500000 +64000000 +64500000 +65000000 +65500000 +66000000 +66500000 +67000000 +67500000 +68000000 +68500000 +69000000 +69500000 +70000000 +70500000 +71000000 +71500000 +72000000 +72500000 +73000000 +73500000 +74000000 +74500000 +75000000 +75500000 +76000000 +76500000 +77000000 +77500000 +78000000 +78500000 +79000000 diff --git a/5/IfYouGiveASeedAFertilizer.ipynb b/5/IfYouGiveASeedAFertilizer.ipynb index c82b425..ffeceaa 100644 --- a/5/IfYouGiveASeedAFertilizer.ipynb +++ b/5/IfYouGiveASeedAFertilizer.ipynb @@ -214,19 +214,20 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 105, "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (3599436891.py, line 64)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Cell \u001b[1;32mIn[9], line 64\u001b[1;36m\u001b[0m\n\u001b[1;33m if a.map[round][]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + "name": "stdout", + "output_type": "stream", + "text": [ + "79004094\n" ] } ], "source": [ + "#It is NOT an optimised solution, but it gets the job done!\n", + "\n", "seedlist = []\n", "almanac = []\n", "\n", @@ -268,6 +269,23 @@ " return obj.map[index][0] + space\n", " \n", "\n", + "def findseed(num):\n", + " for i in range(len(almanac)-1, -1, -1):\n", + " for j in range(len(almanac[i].map)):\n", + " if num < almanac[i].map[0][0]:\n", + " break\n", + " if almanac[i].map[j][0] <= num and almanac[i].map[j][0] + almanac[i].map[j][2] > num:\n", + " num = almanac[i].map[j][1] + (num - almanac[i].map[j][0])\n", + " break\n", + "\n", + " for i in seedranges:\n", + " if i[0] <= num and i[0] + i[1] > num:\n", + " return True\n", + " else:\n", + " return False\n", + "\n", + "\n", + "\n", "with open(\"almanac.txt\", 'r') as reader:\n", " seedlist = reader.readline()\n", " maper = []\n", @@ -286,16 +304,29 @@ "seedlist = [eval(i) for i in seedlist.replace(\"seeds:\", '').split()]\n", "seedranges = [[seedlist[i], seedlist[i+1]] for i in range(0, len(seedlist), 2)]\n", "\n", - "while True:\n", - " round = 0\n", - " value = 0\n", - " for a in range(almanac[len(almanac)]):\n", - " pass\n", - " \n", - " \n", - " \n", + "round = 0\n", + "value = 0\n", + "index = 0\n", + "value = 0\n", "\n", - "print(seedranges)\n" + "with open(\"Elements.txt\", 'a') as writer:\n", + " while True:\n", + " if value % 500000 == 0:\n", + " writer.write(str(value) + \"\\n\")\n", + " if value > almanac[len(almanac)-1].map[index][0] + almanac[len(almanac)-1].map[index][2] and index < len(almanac[len(almanac)-1].map)-1:\n", + " index += 1\n", + " if findseed(value):\n", + " break\n", + " value += 1 \n", + "\n", + "print(value)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "79004094 ~22 min" ] } ], diff --git a/5/almanac.txt b/5/almanac.txt index 64accf6..364c05c 100644 --- a/5/almanac.txt +++ b/5/almanac.txt @@ -1,34 +1,251 @@ -seeds: 79 14 55 13 +seeds: 28965817 302170009 1752849261 48290258 804904201 243492043 2150339939 385349830 1267802202 350474859 2566296746 17565716 3543571814 291402104 447111316 279196488 3227221259 47952959 1828835733 9607836 seed-to-soil map: -50 98 2 -52 50 48 +3680121696 1920754815 614845600 +1920754815 3846369604 448597692 +193356576 570761634 505124585 +2369352507 2535600415 31531965 +2400884472 2567132380 1279237224 +0 459278395 111483239 +698481161 97868205 361410190 +1059891351 0 15994868 +111483239 15994868 81873337 soil-to-fertilizer map: -0 15 37 -37 52 2 -39 0 15 +1633669237 1273301814 72865265 +2398515176 2671190790 99210785 +2397916384 3018946373 598792 +4034325916 3061716397 20017393 +3298612516 3793795301 14249501 +4030007411 3051046904 2833129 +1906984482 224872691 14620134 +864506893 1590633724 149044542 +1029530319 442871336 36727018 +1921604616 770934113 68546178 +3560536321 3114405501 28822192 +1019762634 1263534129 9767685 +3852235341 3579014714 60339892 +2385228698 1577946038 12687686 +2234322470 239492825 150906228 +0 170310676 54562015 +3208946111 3808044802 89666405 +1209615399 839480291 424053838 +4032840540 4041982568 1485376 +2497725961 2174737461 293042810 +2002543511 1346167079 231778959 +3312862017 3475611771 103402943 +318739997 1739678266 354749094 +1013551435 3012735174 6211199 +4014277153 4160859076 15730258 +3589358513 3143227693 230682158 +1990150794 2467780271 12392717 +3051046904 3081733790 32671711 +3820040671 3761600631 32194670 +148429321 0 170310676 +673489091 2480172988 191017802 +1066257337 627576051 143358062 +2790768771 2770401575 242333599 +3091554979 4043467944 117391132 +3416264960 3897711207 144271361 +3912575233 3373909851 101701920 +4072291714 3639354606 104297620 +3083718615 3053880033 7836364 +54562015 3019545165 13557205 +1759006785 479598354 147977697 +68119220 2094427360 80310101 +1706534502 390399053 52472283 +4054343309 3743652226 17948405 fertilizer-to-water map: -49 53 8 -0 11 42 -42 0 7 -57 7 4 +0 1095885172 129797665 +2661548513 1044284418 17872363 +3282164642 3678907615 214830258 +1440687421 2218635146 325889720 +3496994900 4208791298 25912548 +3253828209 4136945159 5561683 +1797056017 864689597 109403664 +3259389892 4186016548 22774750 +2578517508 1225682837 83031005 +3193832718 3618912124 59995491 +3695649169 3214450646 211194594 +820325042 974093261 70191157 +1284591017 1074888739 20996433 +2929761569 3893737873 85668135 +1305587450 2605461705 73959171 +2168339930 1062156781 12731958 +2465234843 2135490203 52666067 +3522907448 4108091872 882860 +3523790308 4255675252 39292044 +2517900910 1308713842 60616598 +3563082352 3176039879 38410767 +3015429704 3979406008 128685864 +1913427402 2131043562 4446641 +2235159285 1419841841 190190495 +3673886186 4108974732 21762983 +891504291 1610032336 393086726 +3927815169 3425645240 193266884 +4121082053 3002154636 173885243 +2084864581 2004107154 83475349 +1917874043 557612753 69524983 +890516199 2003119062 988092 +766355924 2551492587 53969118 +1379546621 0 61140800 +3187625274 4130737715 6207444 +528804063 627137736 237551861 +1987399026 230411125 97465555 +1906459681 2544524866 6967721 +2184647884 1369330440 50511401 +2425349780 2091158499 39885063 +2181071888 2087582503 3575996 +3144115568 4142506842 43509706 +1766577141 2188156270 30478876 +359533738 61140800 169270325 +129797665 327876680 229736073 +3906843763 4234703846 20971406 +3601493119 2929761569 72393067 water-to-light map: -88 18 7 -18 25 70 +2375927917 1595026882 126334140 +1307603095 818620477 43777869 +2050676589 1855896418 112224406 +3618302244 2909504698 119958941 +3078570200 3088215627 6211083 +3084781283 3094426710 141266337 +524666822 53020621 149058240 +673725062 862398346 147671362 +2364320682 2577001713 11607235 +1941578413 1584221500 10805382 +2162900995 2536766467 40235246 +162015400 237365123 4480592 +821396424 241845715 141336168 +166495992 1138498800 212882164 +4277433486 4220367555 17533810 +3226047620 2229635217 307131250 +2909428734 1968120824 34606070 +1885573816 3954749082 56004597 +2711875933 2868267590 41237108 +0 726306378 92314099 +2944034804 1721361022 134535396 +1584221500 3392008740 301352316 +962732592 34415039 18605582 +2235705153 2101019688 128615529 +4252936467 4237901365 24497019 +92314099 202078861 35286262 +981338174 400041457 326264921 +379378156 1010069708 128429092 +3591930858 3693361056 26371386 +3785017329 3719732442 235016640 +2502262057 4010753679 209613876 +3533178870 3029463639 58751988 +3738261185 2821511446 46756144 +4020033969 2806534555 14976891 +1952383795 2002726894 98292794 +127600361 0 34415039 +2753113041 3235693047 156315693 +507807248 383181883 16859574 +2203136241 4262398384 32568912 +4035010860 2588608948 217925607 light-to-temperature map: -45 77 23 -81 45 19 -68 64 13 +2137189745 1335050925 100355790 +639139367 2440321747 987829 +1663612748 1778059435 153830272 +1122754252 1950103191 82536600 +1929621334 1199531530 135519395 +1286703174 2032639791 207137687 +245313533 981575774 217955756 +2597564380 2824691125 293777778 +895004176 331442633 25226735 +1493840861 236388681 616173 +1494457034 764560381 107637728 +1817443020 1435406715 112178314 +1205290852 356669368 33552643 +474799702 0 164339665 +2341054397 2260378974 100255179 +1043066658 2360634153 79687594 +125852143 390222011 119461390 +3924383937 3130691909 13614218 +2467721984 3747288823 76649669 +2065140729 164339665 72049016 +920230911 1673437172 104622263 +640127196 509683401 254876980 +1024853174 1931889707 18213484 +2331983314 2251307891 9071083 +2237545535 237004854 94437779 +3912160931 3118468903 12223006 +1238843495 933716095 47859679 +3326002417 3517222025 230066798 +3556069215 3144306127 241363224 +3797432439 4180238804 114728492 +1602094762 872198109 61517986 +2544371653 4127046077 53192727 +2891342158 3823938492 303107585 +463269289 2239777478 11530413 +3194449743 3385669351 131552674 +3937998155 2467721984 356969141 +0 1547585029 125852143 temperature-to-humidity map: -0 69 1 -1 0 69 +2687600833 2313887435 187105587 +3281196981 2291603041 22284394 +1771250828 1899269239 314167725 +784031720 478456148 306959384 +2605226464 1771250828 58348072 +2085418553 3793564740 111907603 +1090991104 785415532 575136195 +3437652344 1829598900 69670339 +2874706420 2500993022 389039942 +3303481375 3905472343 134170969 +305575572 0 478456148 +3263746362 2890032964 17450619 +2527060387 2213436964 78166077 +2428623843 3695128196 98436544 +2663574536 4270940999 24026297 +3507322683 2907483583 787644613 +2197326156 4039643312 231297687 +0 1360551727 305575572 humidity-to-location map: -60 56 37 -56 93 4 +1919184105 1156349110 51114849 +4031284281 3411510751 25609498 +0 171183359 79004094 +1253227229 2072782209 122019778 +4056893779 3437120249 136289693 +3402931364 4156827458 101778985 +84557792 1207463959 134801591 +635909965 1371746366 266495395 +4029464617 4127764171 1819664 +4193183472 2857352625 101783824 +1375247007 2200355685 41445634 +1996492203 0 171183359 +3601595563 3699895117 427869054 +2218993186 1133540977 22808133 +3217192942 2959136449 140385316 +2987922009 4258606443 9236491 +2628749093 2543337773 86365212 +2167675562 369831582 51317624 +3504710349 2446452559 96885214 +902405360 421149206 108869392 +3357578258 2811999519 45353106 +1196458443 1638241761 56768786 +1178674352 693035436 17784091 +1970298954 530018598 26193249 +2868723842 3099521765 91954544 +1522874936 895259169 18612073 +2841599480 4267842934 27124362 +1880563756 1695010547 38620349 +1011274752 913871242 137918784 +219359383 556211847 136823589 +1785350971 250187453 95212785 +2960678386 4129583835 27243623 +540622614 1977494858 95287351 +356182972 710819527 184439642 +1498443592 345400238 24431344 +1416692641 1051790026 81750951 +1541487009 1733630896 243863962 +79004094 2194801987 5553698 +1149193536 1342265550 29480816 +2997158500 3191476309 220034442 +2715114305 3573409942 126485175 +2446452559 2629702985 182296534