From ae8a2eb85ad355be298810d09ee5c8a986d59d13 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Thu, 10 Dec 2020 17:45:13 +0100 Subject: [PATCH] Add day 9 --- d09.py | 32 ++ d09_input.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ d09_output.txt | 2 + 3 files changed, 1034 insertions(+) create mode 100755 d09.py create mode 100644 d09_input.txt create mode 100644 d09_output.txt diff --git a/d09.py b/d09.py new file mode 100755 index 0000000..f047020 --- /dev/null +++ b/d09.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +from sys import argv + +i = [int(x.strip()) for x in open(argv[1])] + +pre = 25 +if len(argv) > 2: + pre = int(argv[2]) + +for x in range(pre, len(i)): + n = i[x] + for y in i[x-pre:x]: + if n-y in i[x-pre:x]: + break + else: + print(n) + for y in range(len(i)): + p = y + c = 0 + while p < len(i): + c += i[p] + if c == n: + r = i[y:p+1] + print(min(r)+max(r)) + break + if c > n: + break + p += 1 + if c == n: + break + break diff --git a/d09_input.txt b/d09_input.txt new file mode 100644 index 0000000..ead4f19 --- /dev/null +++ b/d09_input.txt @@ -0,0 +1,1000 @@ +11 +6 +42 +19 +23 +20 +26 +4 +2 +36 +35 +41 +18 +38 +28 +1 +48 +5 +17 +10 +32 +15 +46 +50 +24 +3 +7 +6 +8 +68 +83 +23 +11 +16 +4 +36 +9 +78 +12 +29 +13 +25 +42 +14 +84 +10 +17 +15 +18 +28 +19 +21 +20 +22 +35 +24 +45 +30 +67 +50 +23 +40 +27 +26 +31 +38 +33 +25 +42 +29 +32 +34 +57 +41 +70 +43 +44 +46 +65 +75 +47 +48 +89 +49 +51 +61 +60 +52 +54 +56 +99 +86 +90 +72 +104 +77 +78 +84 +85 +95 +87 +109 +132 +126 +96 +108 +101 +129 +233 +103 +106 +172 +153 +110 +128 +175 +149 +150 +155 +165 +161 +181 +222 +180 +242 +422 +238 +403 +204 +258 +209 +207 +213 +528 +216 +635 +303 +260 +259 +304 +482 +299 +693 +342 +326 +361 +435 +384 +467 +429 +607 +844 +420 +842 +474 +422 +762 +558 +475 +476 +564 +519 +620 +660 +625 +1100 +641 +668 +837 +745 +781 +804 +903 +1167 +851 +895 +894 +1587 +950 +1034 +897 +951 +1039 +994 +1221 +1083 +1285 +1245 +1429 +1472 +1309 +2061 +1413 +1695 +1933 +2423 +1698 +2172 +1745 +1985 +3242 +2738 +1847 +1848 +1891 +2239 +1945 +2328 +2077 +2304 +2368 +2530 +3490 +3170 +3260 +3004 +3108 +3111 +3393 +4313 +3876 +3443 +3592 +3593 +3695 +3738 +3739 +3968 +3793 +3836 +6901 +4249 +4381 +4445 +5476 +4898 +5534 +7871 +6447 +6112 +6836 +6219 +10428 +7132 +7035 +9857 +7629 +7185 +7288 +7477 +9272 +7532 +7761 +8042 +15962 +8630 +8694 +9279 +15391 +11981 +13011 +11646 +12331 +16304 +14124 +13404 +13254 +15049 +14167 +15293 +14473 +22034 +19178 +16756 +16107 +22515 +16391 +21025 +41212 +17324 +35498 +17973 +20925 +23627 +23977 +24657 +24900 +66112 +27571 +27421 +26658 +27727 +29460 +28640 +29766 +30580 +32498 +33147 +32863 +35297 +34364 +37316 +38249 +38898 +44895 +41600 +41950 +44552 +57155 +48634 +49557 +100476 +61022 +60590 +54079 +54385 +89653 +58100 +62629 +67227 +74813 +70463 +67511 +102190 +83550 +124017 +118177 +80498 +172562 +112063 +91507 +99105 +108464 +98191 +129198 +103636 +160127 +112179 +181160 +112485 +117014 +120729 +125327 +130140 +224664 +166320 +137974 +254988 +172005 +164048 +195143 +178689 +192561 +367051 +189698 +190612 +197296 +298162 +315872 +215815 +242341 +229193 +394504 +354826 +552122 +250869 +263301 +255467 +268114 +304294 +856416 +526831 +414346 +336053 +342737 +385755 +369301 +426489 +380310 +386994 +465410 +448165 +740581 +585078 +458156 +648424 +480062 +506336 +518768 +518983 +514170 +523581 +559761 +572408 +640347 +678790 +705354 +729731 +1212755 +712038 +749611 +756295 +905977 +999045 +1275063 +906321 +962335 +1104061 +938218 +964492 +986398 +994232 +1066097 +1037751 +1033153 +1384144 +1083342 +1638505 +1284446 +1319137 +1839637 +1441769 +1461649 +1468333 +2096182 +1787362 +2030589 +2121093 +2024149 +1844539 +1870813 +1900553 +2501486 +1902710 +2248938 +1980630 +2027385 +4054738 +3299767 +2317599 +2845793 +2525111 +2603583 +2726215 +4065232 +2903418 +3717271 +2929982 +4438692 +3631901 +3658175 +3715352 +4051534 +4427821 +4008015 +4276323 +3881183 +6900531 +3883340 +5975774 +5327152 +4552496 +5656197 +4842710 +8257134 +6609555 +5128694 +5329798 +6995214 +7206305 +7357803 +7541515 +13604769 +7598692 +17236670 +9180228 +7596535 +10656950 +7764523 +24261719 +8157506 +12670209 +8435836 +16021657 +9395206 +9681190 +9882294 +9971404 +17277725 +10458492 +12325012 +12334999 +12536103 +27934675 +21716331 +17240097 +15138050 +17646817 +15195227 +20089535 +15361058 +16991741 +17838696 +17552712 +40470778 +16593342 +22296416 +30163708 +19076396 +19366610 +19563484 +22418397 +38708072 +24861115 +22783504 +55699813 +27473049 +34437454 +30333277 +54069130 +30499108 +32747939 +30556285 +31788569 +31954400 +32352799 +33585083 +34146054 +35669738 +38889758 +35959952 +38443006 +43937511 +38639880 +71456011 +56003480 +45201901 +50256553 +47644619 +53116781 +57806326 +57972157 +60832385 +60889562 +64141368 +61055393 +70231575 +77529638 +63742969 +94640476 +93932109 +89139412 +69815792 +83841781 +74402958 +116169518 +77082886 +102781248 +86284499 +92846520 +105616776 +120072345 +97901172 +144897174 +111088938 +115778483 +118861719 +121721947 +166922616 +194475303 +179912487 +191833281 +162662312 +133558761 +144218750 +146898678 +151485844 +158244739 +189065747 +358755897 +163367385 +169929406 +231181673 +329584928 +295690970 +203517948 +208990110 +288791125 +229950657 +232810885 +331398331 +240583666 +255280708 +277777511 +285044605 +307586135 +280457439 +291117428 +291803500 +442589648 +298384522 +328174145 +321612124 +433468605 +491541530 +569581011 +504681080 +847358522 +473394551 +649786269 +653010455 +764201772 +462761542 +470534323 +488091593 +741054740 +1183644388 +533058219 +562822116 +755578928 +571574867 +572260939 +590188022 +613415624 +626558667 +961486144 +784373666 +1216746689 +896230147 +1040115334 +933295865 +936156093 +943928874 +950853135 +1980948461 +958625916 +1033356439 +1211589063 +2173075207 +1508417032 +1189380783 +1968018054 +1153010138 +1134396983 +1143835806 +1184990491 +1720529759 +2070553076 +1869451958 +1410932333 +1884149000 +1717669531 +1847083282 +1829526012 +1877224739 +1880084967 +1887009228 +1894782009 +1909479051 +2982536150 +1991982355 +3712512114 +2278232789 +2600313116 +4155457528 +1930745883 +2287407121 +2296845944 +5589736853 +2328826297 +2595922824 +3128601864 +3258015615 +3240458345 +3295081333 +3547195543 +3789564018 +3709610979 +3774866976 +4158317756 +7084645351 +3781791237 +7877143974 +3840224934 +6006456923 +3922728238 +4208978672 +4218153004 +4227591827 +4259572180 +4526668707 +4584253065 +6553096948 +6169051231 +7504060005 +5724524688 +7163186583 +7098240549 +6535539678 +7697595214 +8366893641 +7491402216 +8041363417 +10164774679 +7622016171 +7704519475 +8802406069 +10938465483 +10458267916 +9933503360 +13228584693 +12268955244 +8445744831 +11062208385 +8786240887 +9110921772 +10308777753 +11893575919 +13873570706 +12260064366 +12822765237 +13633780227 +14157555849 +16071413116 +15113418387 +15532765633 +15195921691 +15326535646 +16067761002 +16150264306 +16490760362 +17248150900 +17231985718 +17556666603 +17897162659 +18754522584 +29701541229 +19419699525 +27791336076 +27089497610 +25082829603 +30364331068 +24153640285 +60065872297 +28018686928 +28960315873 +32562173478 +29270974236 +55108184538 +30309340078 +30522457337 +34904786890 +33706930909 +33398415206 +49121240754 +33722746080 +34788652321 +48261493727 +35453829262 +36651685243 +43837352187 +43573339810 +58231290109 +49236469888 +92958592941 +52172327213 +53113956158 +62667246782 +63865102763 +56979002801 +145130920154 +62871513556 +62977905145 +60831797415 +84025122209 +63920872543 +79291181449 +112998112358 +176983715150 +68511398401 +104405137225 +94882975352 +72105514505 +137139078367 +80225025053 +93073822075 +106240586592 +107467759997 +101408797101 +113004124628 +167383042370 +110092958959 +117810800216 +250143202995 +119850516357 +167072384007 +125849418701 +126898777688 +289987839778 +132432270944 +197478959300 +151396695954 +140616912906 +148736423454 +165179336580 +152330539558 +193229149681 +173298847128 +274707644229 +181633822154 +194482619176 +312293419392 +273049183850 +211501756060 +266466331607 +227903759175 +229943475316 +237661316573 +320127927369 +297611607524 +252748196389 +258281689645 +316576032534 +281168694398 +426104340183 +300133119408 +376116441330 +289353336360 +346813158734 +380234298733 +462802516552 +354932669282 +367781466304 +646700630340 +393135578214 +405984375236 +439405515235 +441445231376 +584876144598 +518830010971 +457847234491 +467604791889 +490409512962 +558414809053 +684386029828 +570522030758 +747200570851 +581301813806 +657285135728 +773765841540 +589486455768 +636166495094 +865643169705 +701745828016 +735166968015 +858190979266 +722714135586 +799119953450 +832541093449 +834580809590 +1028891971003 +1028369265249 +1266030581822 +948256747453 +925452026380 +1413842907255 +958014304851 +1048824322015 +1320552524922 +1539316118657 +1371333463109 +1776092541854 +1293451630822 +1225652950862 +1588357305291 +1660618994395 +1501809664799 +1424459963602 +1580905114852 +1457881103601 +1521834089036 +1555255229035 +1724571979830 +2550633986814 +2251465935673 +1997081069468 +1873708773833 +1883466331231 +1906271052304 +1974276348395 +2006838626866 +2183667255713 +2342275952837 +3057064893834 +3496110437431 +4275205966644 +2683534054463 +3405300420267 +2650112914464 +4057376029546 +2926269628401 +2882341067203 +2946294052638 +3305477094682 +3077089318071 +4867201310176 +3857742679626 +3598280753663 +5740598948297 +3757175105064 +3779979826137 +3880547400699 +6187818161885 +3913109679170 +3981114975261 +6362541988516 +4525943208550 +5333646968927 +6507855594090 +5532453981667 +5828635119841 +5565875121666 +5576382542865 +10354578328391 +7134465347617 +5808610695604 +5959430385274 +6023383370709 +6382566412753 +7637722505763 +8406490609249 +10420965273260 +7355455858727 +8283118313614 +7894224654431 +7660527226836 +7793657079869 +12745108401269 +9246756648097 +10102325751415 +9859590177477 +10549326579259 +10866100950594 +14242548698888 +11098329103333 +17740048257178 +23489305346985 +13982873152114 +11831994066313 +13378839229436 +28838377360511 +11982813755983 +14306501684323 +18827455882509 +24791875278147 +15149112938596 +20725691128071 +17904782437986 +15454184306705 +17653247257346 +16907283874933 +17040413727966 +20651652330674 +19106346825574 +22848914706577 +27599638434655 +21964430053927 +40791885936436 +22930323169646 +23081142859316 +23814807822296 +25210833295749 +40665017602454 +25361652985419 +26289315440306 +27131926694579 +29023227483949 +29455614622919 +32802360195942 +30603297245301 +33053895376582 +34693660985312 +32361468181638 +32494598034671 +33947697602899 +36013630700507 +58164013181361 +52385937792565 +41070776879501 +44813344760504 +44894753223573 +55984218546228 +70174997745923 +62509509999501 +46895950681612 +50572486281168 +52342759990328 +51650968425725 +54817267608338 +53421242134885 diff --git a/d09_output.txt b/d09_output.txt new file mode 100644 index 0000000..229932a --- /dev/null +++ b/d09_output.txt @@ -0,0 +1,2 @@ +1930745883 +268878261