diff --git a/day5/input.txt b/day5/input.txt new file mode 100644 index 0000000..fcfcad4 --- /dev/null +++ b/day5/input.txt @@ -0,0 +1,1172 @@ +390522922084641-390522922084641 +267797691954052-269140721231006 +266789574484678-268261882772643 +377273288983490-381098603562564 +383785568546968-390522922084640 +424434800203714-425983158398401 +208929405962194-209255868293432 +447681431166238-448207684909755 +446023996621049-446372892320398 +305769187062458-307161144283038 +64389342895569-69860554934609 +208929405962194-209819038679090 +265467390958535-267084542247621 +208694094415477-208929405962194 +525781783433645-528554852817391 +354968420450093-358251391845618 +323852390076075-324406427477539 +510424437093674-512121467354046 +358251391845618-358251391845618 +282216316976696-287083605314129 +207551891957443-207781622704719 +448391904504918-449209414399746 +205113894695395-205706900920534 +328922731689498-329634435434254 +392670235989000-394845936687009 +374306845506756-377273288983489 +404237319762782-410674714396544 +247276236734427-249566308165186 +72071886443218-79576723741243 +174553115431086-179836654003097 +120947713354536-123259985422279 +485077272840966-490265245284648 +263575009060088-265017990624501 +325997698272238-326289099646986 +201427461577855-202173631465774 +80986662505209-85778105111591 +443873440110876-444539035773938 +333458538635235-339545578800493 +112881131967537-117216852292147 +102273476925929-109906361283085 +277902311856269-277902311856269 +37368351958521-37368351958521 +155343018730156-159726764792054 +508730903085792-510878989298154 +236989674182180-240044448159390 +209454057521882-209888300499844 +274614334811041-277902311856268 +325575538392684-325997698272238 +293669772895187-293669772895187 +112881131967537-117216852292147 +92130934834303-97697055204735 +433228095754509-438722268137448 +449892828794302-450767628485110 +202931768314217-203749789359527 +232272344057067-240044448159390 +322735391497898-323487791176751 +485077272840966-485077272840966 +138294219775724-138294219775724 +21556675956711-27784180327358 +8995741550839-9248001890687 +545071686548066-548963430176867 +504678363959796-506775126768152 +398086447555669-400057896804040 +416250605716970-420796351408603 +202173631465774-202931768314217 +546206861193078-551123906448068 +469593239957734-469593239957734 +191974425577346-198962157095525 +133025223623687-138294219775723 +210311143304277-210562542305654 +324100737891846-324406427477539 +145230706170532-145230706170532 +458184352194455-461139791747220 +16044212188557-18503127210521 +1707257707481-1974925423076 +164750302642656-164750302642656 +313188366163117-319749856185685 +330137593063569-330821572523068 +396582843151263-398779676729481 +125269086842945-127221679460045 +52316891941917-56090997422050 +122663949226644-124390634058895 +445518034832402-446023996621049 +282216316976696-287083605314129 +126918611160220-129106235986344 +498299447592244-498299447592244 +558638117283065-561170197320919 +212313395513892-219079322142946 +201264108781283-201427461577855 +152442257578436-155343018730154 +404237319762782-404237319762782 +31710156445242-37368351958521 +2131400292440-2580737836073 +333458538635235-336573642786784 +191974425577346-195810534480339 +204639602220113-205451587788162 +327660555972349-328416614309208 +323487791176751-323852390076075 +447681431166238-448391904504918 +507347258922086-509263847743598 +446023996621049-446178872305235 +475012782839776-481191044418452 +145230706170532-148980066206820 +553945989370594-558638117283063 +6621925353170-7454640330248 +124072806231785-125963335301217 +365019365701956-369966691869555 +399388599076210-401968318173309 +46467488399513-47288145895503 +4348345917585-5250817456976 +515794780659155-520934702650796 +515794780659155-520934702650796 +268477856135234-270037230907826 +264622930750095-265988302405798 +64389342895568-64389342895568 +326289099646986-327161732643525 +466563588392203-469593239957733 +5250817456976-5472618785791 +393858431996690-395837588163604 +424434800203714-431401965303283 +11537074103916-18503127210521 +252454273569571-259943188231077 +6980522851458-7454640330248 +210311143304277-210562542305654 +269741610116445-271120587025844 +854842638692-1707257707481 +344568679404850-346161460778409 +261532567188345-263056757117114 +184184664429657-189127577458031 +415069527130228-420796351408603 +209888300499844-210562542305654 +21556675956711-21556675956711 +442423757052943-442851589747869 +395329759390811-397674465623412 +56090997422052-57530048751038 +3360664019348-3706494939188 +190410494309-854842638692 +181280036035304-188035105580986 +503237002180460-505287607274345 +454780516258312-458184352194454 +363990435070257-368932521558690 +104185584697641-107004984917996 +226923019350628-226923019350628 +325997698272238-326490832639375 +164750302642657-168250601636513 +223628561773120-226923019350628 +128121593279075-130197990817187 +293669772895188-299922975236029 +204935342528590-205451587788162 +262615144231080-264195243070714 +241608337603104-247276236734426 +201427461577855-201782283929718 +442633502397442-443210740123837 +494063867126591-498299447592244 +505893266542163-508032557606985 +535577587007994-538918491687618 +95193820983474-99297446338103 +212313395513892-219079322142946 +80986662505209-88060072317448 +315311225901417-317784149243863 +524364994551217-532452074975772 +323061872047143-323852390076075 +448811982555632-448973077720697 +476325532428260-481191044418452 +255174214488104-258098579797299 +41781855227904-46467488399512 +346161460778411-349476688798054 +449209414399746-449819565200064 +433228095754508-433228095754508 +209255868293432-209819038679090 +206230766036307-206973027639647 + +316779211588336 +400163806345192 +69879324813950 +557287922690872 +543663521195223 +397967893162635 +377452201603902 +144793122464229 +536342389939988 +177034588478112 +336322868888958 +538664384069229 +542262454560122 +410521718827740 +445885799568388 +244019145900437 +311634821798223 +277055743193308 +80678821423780 +436954716287057 +314692558077643 +16926678621834 +84012021742657 +153664492714415 +250288748168380 +245775821294214 +78926014387172 +405951316440798 +24025207190287 +457721043858708 +5456441100649 +537333734746255 +216550189849598 +472021894942316 +462643162196376 +511662456024505 +522031513434899 +47397108312156 +103335561291090 +374480386539973 +476003299048427 +295525279127221 +374873649003687 +219705765688388 +173221832227581 +510395171767209 +22132214225585 +461598781626877 +541166446228370 +220086493752300 +218164820019460 +353871315750187 +121226138724642 +60561360510231 +481861271606121 +222391285883829 +289813594770422 +218402577608006 +48543024893613 +295322466519863 +1867540479837 +338311110032448 +8226914074795 +433853549156463 +385267365820384 +326439173970005 +151626429016052 +61442569349723 +530832367544095 +131336090685676 +160436942278073 +71671771688331 +263157829609584 +319055621108120 +347824185178472 +185439318514266 +265440999683082 +420135237443671 +125993143002512 +279581427627950 +541428576386336 +65921022830960 +377012153063007 +2820834023619 +356715320729525 +253654941992652 +429209304679698 +16899859764243 +119435580829680 +451668915522890 +373643826772567 +201174600006404 +121161041832822 +489352402266632 +535971779391257 +447916099574676 +422129503386679 +233096391849384 +282838984656066 +31114188647471 +214567976851374 +513720322455576 +450505904061660 +384386253339229 +107124733555642 +409860040539647 +489753897050883 +178353019149616 +511429943372494 +145339315545697 +228572614715173 +393744813687247 +28628037719436 +161205343518699 +494000599522721 +417913555834530 +141405342777167 +178613167148429 +243327179240847 +406500327561139 +133756261298069 +219632212886392 +145735485115172 +466340868146982 +236262047835129 +16157201450668 +49940565911057 +15878942992011 +460807512546956 +253615125606835 +352781775782200 +114400920162185 +213307778289563 +302435352634122 +504980758190691 +416195546561029 +258265856916676 +322033165937704 +460113747690706 +238892829444667 +181734421021394 +82964165069639 +499744278552182 +178026968250455 +252288772381243 +177785672145282 +326399660130016 +540705368880371 +114559494876045 +488640386936386 +381702654056775 +246286499295561 +214152355559371 +101105076801122 +524526945614131 +379442083638491 +430897199071131 +284524119461603 +335996468267021 +168532888895129 +330771523665567 +83197907134289 +328458551318165 +6881148149630 +95136936992896 +184441327471242 +95558034413453 +405698299453263 +485851724731871 +85471561783887 +419944953215390 +62118144765343 +394419899292863 +221285082891995 +232253126307266 +188300072626257 +268365579253843 +126040540225253 +453439495423450 +461474186936290 +447409189724464 +333993551752521 +10693669805218 +131154634146761 +81600487231108 +119066050305189 +94678072669384 +453550654692352 +459805326267394 +546643074590493 +318668525729062 +70793952346256 +193987956346021 +287796154733005 +379917075171551 +504830953305440 +397975861036137 +148026239792948 +447897634302409 +136348652885082 +171780066325375 +17421813728896 +483259321718042 +519131030063492 +467657398978714 +344967499954056 +288280468265795 +15580344297124 +113563829122398 +15776958493944 +268258272504979 +148044851559540 +51213592772342 +108222256074252 +315620743448937 +28924430146675 +268894115763065 +430815781381348 +229333794080271 +37922108270689 +7527720015286 +126265119225090 +518929484489955 +33731180171957 +58073211636783 +375179250601375 +193674331723963 +201108257357827 +485275851372789 +225353477830005 +335130126104422 +198195184354683 +312832977453127 +78339439579877 +179961408491134 +204990317514441 +221845371922153 +124694298260998 +289185853011332 +454696737114988 +435940190769428 +45161721224266 +57403620476137 +301281040922462 +506817534352345 +293023279317394 +286253283734674 +105461536577877 +374121028848159 +216837022050615 +465510543260231 +363028403227153 +127234946215541 +341547972711536 +262210235560764 +144168313006158 +7496916818870 +349263701595681 +32205534364402 +378434243781449 +419178027368320 +119968725190893 +209289996217162 +175526092615971 +6336838073234 +365003391728034 +376822697968089 +99441411607735 +54978413064720 +508690150436409 +164345612846341 +185567449640955 +189907966527716 +225374978632310 +244575937983299 +489437913964980 +351292161140234 +239687449920828 +135498790127166 +447618782045417 +480345750299364 +226970443845666 +493097122469965 +338737510891664 +5565519176821 +252232192438021 +230152303960331 +258905691439073 +14911241124772 +346021221952044 +44467414403524 +4562652111878 +75766742002461 +235694387701832 +466030226739361 +116070477179114 +525990527033067 +463344589922940 +365326888417261 +133913060557938 +192869474177760 +274298610865675 +83287646153597 +295183656364770 +46368221729953 +479238128223133 +216628777897672 +127947701745615 +85887005778840 +229729402448839 +191768818556660 +405062465317938 +173506668090795 +330334104971083 +460521470719411 +120746697326558 +159788752047708 +494741744792109 +23984498903598 +397871832702246 +487015253001275 +205284213287216 +555724146874464 +209536454934311 +494010387902916 +173480185340518 +361924939708737 +260075661794502 +24870892216392 +193318906316960 +222690216029203 +441362733688136 +399950475400453 +449361215691799 +82745635026356 +396267464812380 +517609934002430 +259756204543350 +272745120413968 +512076575965283 +86424015538376 +209083673639525 +273701357810802 +498429671579287 +428375146651100 +208651042841111 +133477202370734 +496184648189362 +242169276686569 +532288748172038 +149660779875345 +222383081383086 +192981822869392 +347895385370210 +411888083164333 +226423710841966 +239779731398899 +67888851713767 +314461140260348 +537827219023322 +20750376957469 +393892893129597 +85222159824798 +190104421781997 +443355830142471 +275520514625837 +79977574747841 +519262088682514 +356758602051775 +363146043779415 +362432866795023 +466534007255322 +125668102433823 +68482964613339 +507581346539782 +46247567078093 +376306364721889 +239547086719441 +226938139983849 +135772744679397 +168467395362255 +95105513622489 +370739946421325 +552662655461844 +174734500247354 +481084223114747 +128359641340847 +57691136287382 +11408982530336 +229668501106132 +448300063491091 +397388673847131 +159640062786136 +281730949540644 +510614786467374 +59142701563036 +387675959480182 +3756230689934 +400729836560157 +375383139373635 +192997043716570 +367515633720057 +439024317602588 +258187082001468 +65918756745436 +267237331396095 +95520469017646 +364816347229572 +364381052099663 +251475751233427 +367273708501393 +324233440381229 +354199859835080 +227024478198282 +141998209516888 +89861745120157 +23566184338903 +69291252082932 +138373223315107 +132854920594051 +538934793847560 +203360381845633 +493719656396628 +461171874534322 +109953118953684 +388640784796536 +398231879073672 +501102037886890 +128379647262610 +171164304742750 +196185759509909 +417375246235391 +358944717227138 +208740108430020 +304196359968572 +89769032150718 +200669346006702 +244264874457412 +25463975188546 +170554374981680 +31183386200091 +204062991855561 +257161867090631 +434986793169006 +146822652869390 +290357217757923 +469859507483520 +147897230622925 +76267675746534 +355515029150991 +123872738535891 +230737020818301 +109916787383773 +320062655784530 +211843263837699 +288836270844493 +489905095780717 +316057079171983 +541434948835394 +442958879478533 +66381499787225 +524860598773798 +44234530720624 +131183188760376 +85967602121250 +219816832521316 +212283077766659 +315506423854190 +534222812537350 +541534726302394 +494830336268485 +34471996808512 +493858301029912 +99885961677122 +126469199652498 +36143576795434 +48404756867174 +335948226691265 +523791611786136 +162249066099193 +206658717227514 +167365766203394 +224329654966742 +185469887696999 +266192842040163 +166269914432139 +425672262566608 +463430983154905 +101140394508865 +47919313576323 +476858998357681 +417825132968957 +238433862797855 +481476166871721 +354967046606988 +259755734411698 +282412933800767 +117659287896040 +418980756218509 +370445510001236 +126777330421911 +301449015257374 +535227483262934 +8355641319208 +290778431427202 +58962545555841 +506746680183839 +405990572620676 +287481206036861 +199725792270690 +129315603038319 +230854894569656 +185206374486590 +195522290246908 +241231542330572 +109625157573552 +215321278923164 +187171312041426 +406845288031080 +116714414252532 +66650393603580 +211850546430570 +416687569365943 +181211559973515 +105959236464597 +384234784465147 +432810168382062 +402171676893184 +385559744528129 +204021123427881 +495806566675831 +121995522847366 +414198548524092 +269447675716398 +278375036334196 +543869590274034 +461590980649533 +135341100361527 +452805703362701 +562225846692465 +110568341833065 +455326173484321 +405684179715566 +403852504063638 +560252255390698 +150046788300777 +546229537972174 +421835043398 +525524600337421 +22515679926630 +397752122893761 +446543651242693 +67224031595550 +113458754544748 +333982720598654 +349885396006599 +233754012462844 +482059419081124 +380382820497073 +340225555200969 +175373694029651 +136836691489749 +109535153952846 +554558977200079 +353360765055677 +228941081091252 +458327051079126 +87585858044868 +51642541721338 +257208281980970 +431924549195878 +329101349985356 +29486706799054 +498825498183484 +517355233912319 +330289286988977 +82886027243298 +482736429636764 +55544955157045 +131381112115546 +396349977949413 +557779347503749 +94014138432120 +268618133178138 +381478981627983 +211981311577213 +56390688012865 +359150846329923 +380135471533930 +90146898129019 +535454957848285 +446524601964592 +282200324272917 +111476442141965 +550030353696905 +159841027754884 +90838069869989 +247672288513 +207404088280033 +433524452757307 +515270492443245 +108954900294383 +203942561723770 +315611324536250 +37875434431190 +266471063510666 +215163579565624 +190480914848779 +163073753804226 +311117927899650 +13725955496471 +418214601780840 +260421913391236 +308555708688690 +227829583347654 +480665919681656 +147489866104848 +519940057529625 +356053380518855 +61115434408814 +183120366599812 +343775805586327 +469590746378942 +558177271099402 +13371890703825 +486590460668097 +215430130266878 +123354857157605 +327156625215239 +11165541630857 +271368028539755 +68875412218471 +386476732107342 +346594479236398 +45382742347189 +317625209364517 +388070556307289 +298536533336290 +420523272103088 +562760471524880 +237659409447920 +157664482349464 +519892572604050 +397002974657526 +24700732601303 +357129820785446 +23645634067727 +219515152394031 +367485010768780 +455551948103474 +153873243581688 +44701411970218 +105114137703687 +50085194569593 +356132090361967 +195369538226646 +75796488034583 +305123212502760 +42502740854772 +331079520213102 +147284032807752 +41171762251378 +209164317305386 +317264639837561 +46570178966237 +1653694685468 +380121241895131 +371175676458867 +237603394221151 +506187662634225 +200883638613911 +64483216272276 +494906837785955 +506098896548996 +421920548342220 +61566155556428 +407799172654008 +224545194257340 +125084787649793 +307167376048647 +437993833166693 +130555709614249 +451324643515534 +446064861701232 +243732697579446 +180010809910164 +551728924379413 +309692627733205 +117974925107239 +54911294348194 +306305576829903 +436021685947668 +312513843533014 +42276012583597 +499430135041787 +182990345359589 +167896863555912 +357034609109746 +114101242744248 +301027763180134 +258735305429669 +130077747253945 +164602141293834 +261458241598943 +318615411217909 +450911506156252 +256547676533830 +229180327476298 +38897556069067 +101261023111018 +137589770483827 +64102949289131 +114651526825250 +143520208108631 +309366338259327 +479952588993989 +69219546748181 +290933770844150 +326475976132824 +291635049987525 +493001283589041 +116581281812321 +484151228899859 +522822464742437 +484872499709436 +17436519514015 +49173713587945 +355404896993971 +388324075713011 +546589203681281 +427701867478941 +27387426073499 +85130026544318 +495855926546220 +547117110672474 +260390344895689 +140721502804919 +294548231384929 +245303895043920 +330874654050573 +151562009268074 +438246692516387 +513711060194714 +225994094182069 +512134076968384 +296201775632531 +377551583176576 +46161323475535 +8560786229985 +103604402136546 +173374133263566 +128699824994732 +468128488991696 +558040470425895 +56417242998017 +33563990255019 +467296009484322 +531654566405350 +521498700630120 +556655663173553 +503135437053258 +130821752837050 +222245909605374 +19473764639209 +151363487194885 +301951297267214 +538936017216098 +89158741521889 +126039061937097 +88404843697146 +494208263475468 +286660227034580 +329549453167005 +4232069406467 +302536337494693 +498977539548395 +556014509607925 +33829579408692 +408258945539220 +478394741822018 +528092030717002 +7456887288317 +116037619884192 +45316469609770 +548078950191167 +507103051300814 +511099522430458 +178211314969741 +22195096770115 +347391225207011 +182298961431122 +260438768812892 +139352560394750 +426370177335561 +315063145940123 +183663960364236 +171466437902786 +474002008125750 +458653980492751 +250145034759497 +513173233502838 +476460513551161 +24523436672189 +95447163443705 +34355619400035 +147657609929382 +249604941524059 +232315340295192 +222417195484379 +405975890006016 +223935418808951 +434433375431309 +258979823101052 +386435193208246 +527279298081487 +296491700589501 +340811191491813 +275998286833130 +509082933533801 +5784557163191 +6369391313111 +274712645104397 +2981400112767 +535001599813154 +180504150061393 +180035527938157 +536293787708388 +342298250585868 +312183049966044 +55909969457273 +182863476509444 +88285814267184 +348023360361536 +550224033861336 +280461249365634 +438238930415679 +263454353669829 +20958267683885 +112259549775657 +385126263104565 +119374942524006 +475648784087890 +41500437527261 +28082876517195 +73666997006084 +308666289743012 +454645337834162 +299428254603883 +543168714407039 +265678041628584 +480767540011231 +338169238542750 +85406351591788 +482458540471001 +41519542924087 +195737942899569 +251975057171450 +155629269147307 +502807140043210 +522124341993833 +78118759030588 +547349972158540 +321459580183670 +49718263522410 +518594018514224 +429345920697095 +66945590164540 +334322598571066 +116399579366068 +479607831328633 +522257127358151 +414395649930038 +152711650112028 +357330545609022 +208423447451991 +451669370321188 +422034964043122 +388247571309583 +463621261858408 +9192926286081 +274680388871971 +353921656329939 +217118729098510 +144410874105563 +495177742252396 +376471657545107 +275409290830286 +493774613918650 +356060728085310 +190381105531121 +213990933730671 +165349451430539 +528619286719314 +26883326107568 +84719236131744 +241997435641177 +142693435991390 +147646839922187 +227360478653442 +11758676007994 +448519721435711 +347832010986887 +288001690833811 +556110683768523 +423041410120776 +105997694232207 +493886849121523 +48258062857886 +252688105227080 +354545225031573 +194912788687724 +470686778663803 +544271351911838 +375388277669758 +26215369673487 +267595299374491 +242882682337502 +409179922773392 +141493123637100 +268884494646026 +549696641353128 +562051790880926 +166935619633747 +330267642201892 +352897155176158 +49162428484256 +450557260329008 +431718882989615 +392629099947303 +292067105598116 +259461512162119 +480182378884376 +178938184061111 +348772706553982 +55989477649202 +318321325829264 +323255215311554 +476168091855355 +150355218480749 +98844989239870 +325453508906202 +291487778210920 +459090207973304 +85555514644319 +141375716774971 +559815045227576 +166353264788641 +190783570538639 +203365859552709 +49158128871396 +176283542525653 +317370083784399 +440943815226155 +168541667554591 +172956375739445 +163053296592597 +80545182606569 +164406118649332 +419361560297208 +509332451390731 +399181585343112 +510876510778854 +463276098019239 +274955097364122 +528627213299706 +531731301989107 +35537397759267 +499009367783012 +430177480132064 +323202168531685 +178785205234084 +215963582645180 +95616691530099 +304243140709166 +341239036574427 +499473813618375 +425270091822920 +405479919640533 +347162637334028 +368895706671868 +213563410482523 +47048686484056 +433678598314767 +143967500508042 +511197386598837 +335784024541389 +375483778050946 +231270291977172 +129447971349640 +90349053267368 +215096348421389 +151674135039361 +409787574567957 +429342436899335 +210527368928586 +293864611727404 +443650823550254 +397637938454746 +220118406604906 +496234243880396 diff --git a/day5/part1.py b/day5/part1.py new file mode 100644 index 0000000..e2c90ec --- /dev/null +++ b/day5/part1.py @@ -0,0 +1,27 @@ +FILE = "input.txt" + +def main(): + freshRanges = [] + indgredients = [] + complete = False + for line in open(FILE): + if line == "\n": + complete = True + continue + if not complete: + freshRanges.append(line.strip().split("-")) + else: + indgredients.append(line.strip()) + freshRanges = [ + range(int(start), int(stop)+1) for (start, stop) in freshRanges + ] + indgredients = [ int(x) for x in indgredients ] + return len([ + indgredient + for indgredient in indgredients + if any(indgredient in r for r in freshRanges) + ]) + + +if __name__ == "__main__": + print(main()) diff --git a/day5/part2.py b/day5/part2.py new file mode 100644 index 0000000..5ba9ca2 --- /dev/null +++ b/day5/part2.py @@ -0,0 +1,22 @@ +FILE = "input.txt" + +def main(): + ranges = [] + for line in open(FILE): + if line == "\n": break + ranges.append(line.strip().split("-")) + ranges = sorted([ + (int(start), int(stop)+1) for (start, stop) in ranges + ], key=lambda x: x[0]) + condensed = [ranges[0]] + for r in ranges: + end = condensed[-1][1] + if r[0] <= end < r[1]: + condensed[-1] = (condensed[-1][0], r[1]) + elif end < r[0]: + condensed.append(r) + return sum(len(range(r[0], r[1])) for r in condensed) + + +if __name__ == "__main__": + print(main()) diff --git a/day5/test.txt b/day5/test.txt new file mode 100644 index 0000000..2e9078d --- /dev/null +++ b/day5/test.txt @@ -0,0 +1,11 @@ +3-5 +10-14 +16-20 +12-18 + +1 +5 +8 +11 +17 +32