diff --git a/day20/Cargo.lock b/day20/Cargo.lock new file mode 100644 index 0000000..a18135b --- /dev/null +++ b/day20/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day20" +version = "0.1.0" diff --git a/day20/Cargo.toml b/day20/Cargo.toml new file mode 100644 index 0000000..9a5d286 --- /dev/null +++ b/day20/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day20" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/day20/example.txt b/day20/example.txt new file mode 100644 index 0000000..b5cde74 --- /dev/null +++ b/day20/example.txt @@ -0,0 +1,3 @@ +5-8 +0-2 +4-7 diff --git a/day20/input.txt b/day20/input.txt new file mode 100644 index 0000000..5d610d2 --- /dev/null +++ b/day20/input.txt @@ -0,0 +1,1075 @@ +919958672-920375477 +886049087-888249849 +3081919777-3120089489 +3572627395-3574552561 +836482418-838229201 +263121538-272552145 +2200941699-2233030206 +1040503809-1045446028 +572499708-573647695 +210716214-211293712 +1823940147-1824909695 +1149819671-1156515606 +840301-1235975 +2558444346-2576431266 +2040683306-2041858539 +1975148767-1977230893 +2166012490-2167330392 +1596820122-1601199846 +9268483-16516681 +762845167-764208916 +491224876-502978523 +2996305430-3009110922 +1259256154-1277414627 +2708692622-2708776113 +1271826-1332885 +234312659-287364011 +1891353819-1909427500 +1250425927-1252102712 +712126467-738072279 +2346714338-2353248097 +368386742-376492058 +2595775995-2609250839 +3249548103-3254114560 +1171161802-1179472906 +2662861723-2664752393 +4226877819-4249349414 +1171956409-1187221562 +2040702351-2042549632 +3005011421-3016763477 +3049487563-3057117302 +1390331165-1418430204 +3444570202-3444918246 +599184528-605377741 +1898226266-1908321650 +1955861436-1969705833 +2076481761-2090246287 +1006916840-1010566810 +613512955-614082560 +2849590578-2854583463 +2500148918-2540490100 +766777203-767986997 +2036765615-2054806433 +0-570348 +782518371-793780030 +2981632335-2991403697 +608634320-609195891 +2799896767-2812558917 +542043185-552137852 +1530404914-1554572745 +2903817017-2910671988 +3185056610-3225483854 +895116568-895609151 +1453819363-1470928753 +1985320259-1994359477 +1586805729-1589803465 +1790018082-1793258622 +421030691-421421239 +4083430033-4092955099 +4078550906-4086571620 +1774638092-1775165491 +3443794431-3445552263 +3281794732-3282850875 +414189653-415187366 +2786183056-2786679734 +1704708049-1711273105 +2687962477-2698581448 +773112822-811481642 +3332904945-3339521304 +1653580668-1653944901 +863886036-878607728 +3076161451-3079987747 +4028994310-4047521530 +2303902334-2309928643 +580202292-582682451 +2906079394-2916864561 +739620008-745728146 +1477191312-1490369546 +2459725694-2474929853 +729255230-738440779 +152684848-153985817 +2239460190-2239764102 +2331229504-2335380514 +1737864727-1749958630 +1710045205-1711102752 +3757929008-3765007076 +3574745509-3587637342 +727092738-757087667 +2019646628-2030055883 +3671200174-3682872232 +3665992374-3694406080 +883676059-887580416 +739171344-743796747 +2879918343-2880066490 +219040011-225300405 +673282863-700633678 +457882242-481742294 +3602063370-3604064843 +766108682-768198393 +848022151-855623937 +1456900622-1460285226 +4092955100-4109128950 +321511916-324779463 +2468523382-2471310729 +3792407202-3809553735 +4263407121-4263937926 +1018453690-1031041397 +3180026908-3223871562 +881304389-889612814 +565810022-590637548 +4087243996-4098055618 +3270438557-3280994163 +1935608735-1951604049 +1482613558-1486337820 +1269701642-1284808866 +1210576716-1233667284 +2620605343-2629043545 +1235976-1247936 +1977697644-2009416090 +2252784587-2281249580 +4021536841-4023845854 +2390314639-2402972555 +1428569722-1441920758 +1336743275-1389113237 +13869828-17673579 +1152629751-1175301553 +3212150200-3215152050 +2914727786-2940790232 +3884662352-3920316034 +1611962576-1623628537 +2964648570-2968671896 +3713817130-3718949943 +2355617886-2361060846 +616323464-649242774 +3134103534-3146161087 +2471504682-2479805363 +58313349-62783431 +2393771477-2425915916 +1553584752-1577429017 +2068776349-2072393018 +1616273579-1648571217 +1512323946-1514195401 +4249349415-4272117350 +4017595640-4031728913 +984645753-989202021 +120928241-133335483 +597451711-613277654 +3166559097-3172554596 +2195876833-2200730605 +1513356807-1514097873 +2629477281-2634660232 +2103419953-2109561598 +3950691855-3960688114 +1937920532-1955861434 +412825169-415862399 +905332542-905368514 +3048973286-3052133383 +2835772950-2853521757 +2440843144-2447965477 +117857301-122622467 +2215500516-2229433925 +3869271213-3876331955 +3971564940-3981028640 +122783969-124222949 +2238796221-2241090010 +4230789937-4236216806 +72469721-80485400 +157956834-177539020 +1001868367-1022933221 +531346716-535800982 +2674615709-2681260511 +3068068535-3074258107 +3024072175-3049487562 +626982176-631880126 +1424574598-1477191310 +2389338520-2401661211 +3865409535-3873575787 +2879885431-2881134353 +3501311417-3508561587 +3181928035-3192395648 +3757948212-3766348913 +3505295277-3511126627 +2708354865-2708958437 +260037456-269626281 +3134122300-3161435120 +1655262120-1664078071 +2339372067-2355730037 +1599883547-1603404972 +1341000672-1352865304 +2435291483-2439275592 +2117441647-2149005656 +2495544020-2531236388 +2241474621-2241925797 +2171561649-2177518628 +2016778351-2020117971 +674334235-689176957 +1237444983-1240733102 +423736256-484333208 +2678998258-2689959478 +1049579051-1066601730 +3228010435-3231077891 +1479467785-1481855689 +1191413679-1233983400 +963871402-965606825 +4285287243-4288786728 +2020404660-2021576267 +3741118751-3749931895 +2664050391-2672501834 +4169137315-4180765403 +3398613397-3418388252 +1662107139-1662250384 +376492060-380166404 +2197619430-2200634236 +380129056-382218781 +1583447306-1586917154 +2624710171-2629771212 +188232199-190690165 +307962373-309216573 +1774683835-1775224802 +95941801-110043168 +2014143246-2016521074 +1595385924-1600946759 +3367357836-3391083589 +2014329812-2018970418 +3177513962-3185056609 +801405633-818068471 +393595030-403607717 +3604788004-3633457973 +2309928644-2339372065 +1347670437-1354854968 +4078413247-4084150143 +3237129747-3237898184 +552137853-562145553 +1749981886-1754015457 +140822352-177549446 +150868127-158471825 +2664078469-2665782880 +138379555-174196996 +1844240113-1857140018 +1738417898-1748281427 +4211709815-4219805167 +4050836260-4074987008 +2488182628-2529355499 +3985904604-3998601062 +1433485383-1448748166 +3558878-25272659 +3511395110-3557494247 +223730075-228907744 +2929775253-2934063613 +2194324129-2213929005 +2595335523-2599243817 +1513774833-1514979593 +613277655-616323462 +2480737374-2485903343 +1449508591-1459758600 +2516662925-2531925993 +115537924-118665030 +4056786000-4061052756 +1318323290-1336713130 +1614373707-1632815031 +2383050362-2389590079 +759244361-760710863 +3290346518-3313874649 +2716432931-2721619483 +1922749993-1952910417 +922605392-932510384 +523816528-537519771 +1484262004-1489954474 +503073339-516455120 +305528670-307111419 +3707818839-3716556331 +2663384833-2669009075 +48746414-50801832 +118511788-122640674 +227368214-228657225 +3953072761-3953825516 +905365751-905421440 +2540490102-2573494189 +3643429389-3650654019 +4149931652-4193975732 +313118253-340521373 +3261439228-3281154892 +2070124972-2071179931 +700633680-727092737 +91690221-99842543 +1097715949-1109844944 +1429958901-1436530001 +1246890-1270527 +3743985128-3748090231 +3865046802-3873169775 +1937954230-1952573847 +3134365979-3177513960 +4055031699-4078413245 +753115-1178173 +3697888600-3710345692 +719771261-727636317 +945489773-963871400 +2732319078-2738022918 +254021494-265396216 +2978173337-2987930229 +309430394-368386741 +3442959348-3444769572 +4248098236-4264453405 +2784904562-2786396677 +1599354835-1607242064 +1536729680-1572775699 +17209310-18438952 +2904674818-2922659247 +1884830159-1890391783 +248539176-289094148 +3929356674-3950691853 +4049598844-4050311077 +2549359290-2566764418 +3616212951-3626654186 +1095689326-1109644876 +3518441393-3548117781 +3419217410-3440096817 +757175634-758994865 +2032361884-2057663094 +2362359924-2393771476 +1001798307-1023306654 +1461175551-1463384689 +1031041399-1066029357 +3624067100-3628021032 +2017460934-2019646627 +3570966560-3593099348 +3078109383-3078811400 +1418430206-1424574597 +2355730038-2361101252 +1491361234-1513199350 +4193975733-4201193307 +1251709996-1259256152 +2654038821-2664705116 +1005850118-1026053494 +1460192259-1460718449 +542470927-549863622 +685814546-689409969 +1480285211-1483071801 +3351576507-3352518913 +3042881592-3051496518 +2786679736-2811230463 +1249936448-1251709995 +3634862952-3638503663 +3185862037-3196089815 +2381108074-2400445432 +1280445270-1298455537 +965560762-979946049 +1116649919-1119290057 +1917368447-1937920531 +2479742088-2480737372 +1460335519-1460793877 +4215045782-4221246273 +381659976-395968391 +2693132426-2701482986 +536818335-546377387 +575522578-582051128 +2742321308-2746049394 +1932720092-1935825110 +1879893672-1880152125 +3593099350-3609761427 +2464292868-2470034902 +1460935544-1463157484 +1460420032-1461040413 +3047171382-3050716703 +2109561599-2148943732 +3710919757-3720152833 +979946050-988650310 +923369150-941119970 +189392563-194620107 +3514674937-3543292726 +2875100611-2876901416 +1629125069-1644001002 +2610265805-2612238193 +1554572746-1583447304 +1349814062-1354343100 +660945146-673282862 +1662248019-1662556939 +3405386409-3417048514 +594461086-597451709 +2294747077-2303880518 +3059173008-3072667429 +770866766-776039245 +3813045575-3822523935 +3562480032-3583229296 +1269743-1271825 +799587164-806331579 +2784337083-2785200779 +3018019063-3022276172 +1086759005-1089750473 +3571572592-3589931378 +2753573327-2753763935 +1324553333-1328070704 +1490369547-1491361232 +2709012792-2753573326 +3451398370-3489184228 +1900954994-1908394114 +721774069-725655304 +3350689772-3353103266 +984931987-992374334 +80978845-84846450 +4127800031-4129923177 +2911276508-2939462441 +1599813934-1603103099 +4272117352-4294967295 +2427988477-2452714500 +2575871415-2579070417 +1389113239-1389458514 +3130923721-3134365978 +4053000231-4057446845 +1751951907-1762238339 +2969729411-3018019062 +3260871824-3271285135 +1713942125-1728051036 +1654256753-1689101931 +1322198789-1325452214 +83822230-84865823 +2360607543-2362359922 +1263361003-1268973145 +3902045368-3919169470 +9841989-13318551 +1042727853-1061353613 +4061279643-4063917492 +1332886-9841988 +92631600-94214081 +3120089490-3130923719 +53957875-63631593 +2564273908-2566530082 +1298455539-1318323289 +3898127307-3899710445 +3440096819-3441214739 +1667233233-1679545407 +3839803010-3840172249 +167522689-177490438 +1973767213-1977212609 +1653752027-1654256751 +2560761531-2562338870 +3023010358-3025596623 +410415501-418577539 +2614801841-2624710170 +2466413007-2473353681 +2369678794-2425239607 +2811230464-2828275806 +388430604-397807139 +210214266-211142903 +2312023511-2333872221 +3897166405-3899664481 +3211762835-3215049496 +887133231-895425237 +80441722-91132134 +2899093288-2904674817 +426963823-488547824 +4092641942-4099446960 +3405068680-3407062134 +3186263586-3211036527 +2228421401-2232149856 +4216505099-4225004005 +772830180-788606794 +1354575944-1358038428 +4128714132-4132136025 +2562066551-2565053435 +2876901418-2885500164 +4262330011-4263761379 +1126517156-1126900268 +2664705117-2674615707 +1495495006-1500141583 +1675974549-1680020283 +911146716-911491118 +1513361977-1514871519 +833606660-845044392 +511721289-523816526 +1698902067-1704751953 +547970383-558959846 +1253117340-1254512195 +3328075685-3336714742 +1514074211-1520757292 +4201193309-4208391340 +3670866880-3682677016 +2754576414-2768549178 +2584041314-2612914966 +2057663096-2076481760 +4022317860-4025916733 +3986886176-4007484015 +2628212581-2634330538 +3981028642-3986886175 +4080614111-4081044998 +862172989-881304387 +1075087777-1116649918 +3291895348-3329976868 +92360416-100651726 +3235786737-3242325054 +3350026803-3363347388 +4127213179-4129104233 +3856619984-3857580751 +3755976349-3757442799 +4287925986-4292925569 +649242775-655886463 +2559206019-2561839618 +2030055885-2032361883 +3282850877-3320723776 +2753763937-2781400796 +2579070419-2607574413 +1233983401-1249936446 +911405841-911736154 +1689101932-1698902065 +3710345693-3740381787 +916825898-921505823 +2038835617-2043687497 +2628928569-2654038819 +1045177383-1062348836 +3212094890-3215025891 +2164160803-2174859798 +45433962-53957874 +2663025946-2664660122 +1814448891-1816092144 +3254559753-3257436897 +905328157-905336610 +1728051037-1774598042 +1869520011-1884830157 +3659141192-3671598243 +2203120049-2231794968 +4201826682-4215045781 +3564170160-3573391826 +1100928207-1112528672 +2823420443-2824472623 +2174389884-2181062007 +2940790234-2964648569 +1838879879-1869520010 +3452631678-3477502033 +263908-753114 +535632883-552744447 +2009416092-2018024428 +3735341271-3741118749 +3827099344-3856619983 +153310140-163311014 +3596386948-3631175751 +419189361-421171264 +1816092145-1838879877 +3480305554-3489096914 +2067785518-2070627917 +110043170-120928240 +4024474193-4040721431 +352810968-368486270 +1774598044-1775142443 +3496680749-3501311415 +942113873-945867676 +3351011081-3359853880 +1126252746-1126559055 +2165526577-2166302471 +4078739202-4089380204 +742817750-746113325 +3839064820-3839856735 +608806800-611277892 +3067734415-3074116730 +1353691487-1356981818 +1126900269-1149819669 +3049796717-3055958122 +169225584-183424173 +228125042-228702038 +999280270-1001798306 +221761448-222524989 +1449566391-1457893136 +1495191304-1497549140 +2491380465-2504458849 +2452714501-2455410422 +133335485-169225583 +1175301554-1191413677 +502978524-519420807 +414439271-418550533 +3074258108-3078404828 +3303306618-3328075684 +2612914967-2614801839 +241397133-278224588 +119956085-127964735 +3403372367-3405922261 +3682677017-3697888598 +3638459517-3638928728 +4109128952-4123947031 +1487038249-1488458546 +2885500165-2895836920 +1890344370-1896983501 +3400818091-3406562180 +4123947032-4149931650 +2183407200-2213981671 +84865824-108765719 +889612815-914180374 +2710709303-2743170954 +3351470383-3355382237 +2985187880-2989505675 +3654819897-3659141190 +3442651796-3443784096 +2844004299-2865002986 +3514184260-3525145308 +1969705834-2003565223 +3837556616-3839081560 +1251664687-1255113781 +2781400797-2784833256 +183424175-208460901 +3442036028-3445116806 +941119971-945711689 +3883792156-3884662350 +1389513874-1390223705 +208530403-213037216 +1794005425-1802862059 +582051129-597401406 +3374180593-3390094143 +2355445079-2358433947 +2041606161-2042087296 +3801571300-3827099342 +4233915338-4257384899 +228907745-234312657 +3836683583-3841906921 +1710571829-1713743478 +3839076587-3846435147 +2848431873-2875100610 +2974049641-2987481562 +1800074562-1804493989 +805427340-833606658 +1047166559-1052753986 +421717370-423736254 +2168918566-2175507452 +3986240152-3992888554 +4075509095-4076041544 +287364012-296288707 +2657426809-2671053375 +418577540-422067537 +3389250605-3392645892 +2879707597-2879983459 +2237472253-2244213153 +63697868-72469719 +3289768056-3297981558 +1252302304-1255392043 +1790730820-1811114333 +2174859799-2183407198 +886201633-889202088 +19375954-31509014 +3744158606-3754662081 +397449036-410415499 +3225483856-3249548102 +1710860245-1713942123 +3404715033-3430352329 +2708634517-2708741530 +2667400652-2670163449 +3857580753-3876586226 +3392645893-3398613395 +4092301476-4106703835 +3363347390-3378145817 +210865361-214231076 +1652835582-1653811106 +82283564-92454552 +2245228005-2294747076 +343309082-372597133 +3557494249-3562480031 +3638928730-3654819896 +1216377173-1235409713 +1608592165-1615831716 +2108846100-2139733225 +1076823620-1109612249 +3609909218-3626201996 +4175780599-4186505741 +2566250297-2575871414 +13318552-16430324 +1252595413-1253340233 +1960189697-1979387740 +2776526762-2776872724 +3749931896-3773683931 +3077917469-3078279785 +3078792657-3078906311 +1513308396-1514090595 +856321847-869580187 +54062011-67861593 +3339521306-3350026802 +1588869999-1591630332 +1678291151-1690477634 +1880072779-1880212289 +840824852-845817688 +146669149-177909605 +2879974061-2884449495 +94876761-104847723 +845044393-846012908 +1921963527-1934450745 +622724719-651861282 +3292341439-3319104138 +3331135637-3338309753 +980185763-993259134 +2344417197-2345872257 +528394043-546258450 +943645490-946672465 +3957544264-3972708024 +528749026-539257513 +3446096033-3446311663 +2708747493-2709012790 +2438903919-2452748692 +3756666729-3763686867 +4216375959-4226877817 +856631922-865986445 +1404172147-1407471452 +2396404446-2427988475 +57888624-64900497 +1677744332-1678710710 +836188704-843284710 +28373043-32259705 +2684399084-2689082987 +1403122589-1411905298 +433361724-488784028 +491246626-497808448 +1513715356-1514402462 +484333209-489208142 +1127314583-1139276488 +1003690091-1007378874 +2353620220-2360404912 +2017621038-2020278269 +80350283-82387329 +895096472-895470024 +224681682-227294023 +1615194305-1648770974 +2455410424-2462616251 +1718153883-1757875727 +2609772211-2610826989 +2254158260-2278527418 +2319296951-2335903536 +523948578-552904810 +2889295970-2899093286 +1568161119-1569319692 +3490871168-3500330877 +3043172825-3055388847 +927185290-941727993 +845851948-848022149 +2297721018-2303902332 +1329345975-1330547548 +218190183-224455542 +943868977-947001514 +2141462472-2145499631 +2566031585-2571192718 +1792458600-1795149977 +1395315688-1403276128 +905363657-905390853 +3511336294-3530392880 +757087669-757386036 +4239444994-4241432714 +1535218404-1568123507 +3640691513-3640970013 +2880760773-2881614965 +496194112-496896083 +2111404233-2164160801 +3404414568-3419217409 +4238986305-4242926825 +2256927710-2273975547 +2804331940-2819926559 +1701935813-1708663664 +1588950694-1599214971 +3510400521-3511395109 +1129713587-1136665779 +1514054191-1514698447 +858131110-869606915 +1775224803-1784920286 +434579228-471783644 +651598547-653748509 +1050803035-1058683279 +2858851864-2869378688 +3281154893-3281811234 +2915220884-2925393036 +2496162780-2515486958 +2677195388-2696820611 +2967380887-2969011309 +213481549-218190181 +2968615330-2969729409 +2548611109-2560233296 +3445240171-3446284637 +3378323178-3385567943 +3489184230-3493700167 +1858582421-1877327301 +2213981672-2229359168 +485397999-491224874 +762086623-763310022 +1849289620-1869732929 +264728363-271703714 +2884645965-2887387419 +2553167952-2563515723 +2125756179-2128106173 +17355233-19375953 +2483034583-2500148917 +3384910269-3389673095 +498051453-514692191 +621950310-625995472 +60716299-65270243 +838464928-842952141 +2635348335-2636032384 +2230224606-2237472251 +1980510515-2007310564 +1800059730-1806619910 +1066255458-1075087775 +2068178500-2070702946 +3038831977-3045654385 +1678147912-1681790073 +3054082845-3056715427 +302355307-304761774 +1126235434-1144474711 +3522659327-3552918955 +1152173440-1156391245 +653040124-659843371 +79022445-81404945 +1973676867-2003746696 +1071464363-1072196641 +3290362310-3312023623 +2993853471-3012871302 +2385180796-2415124762 +2111432773-2139880360 +3970565071-3977646395 +1662424002-1662681204 +3038310782-3049599829 +1094763429-1115133423 +2090156097-2103419951 +1775976288-1814448889 +2324307690-2333521274 +1336719058-1336743274 +2064985368-2084512625 +299927000-305939914 +3676811064-3683512625 +209494872-210628961 +3960688115-3972728202 +2720363316-2744931549 +3860527733-3876243719 +91890125-92979666 +2853956055-2873416725 +3077340783-3081919775 +1776462394-1791408419 +3440114951-3451398369 +3493467124-3496680748 +3440386366-3443192551 +4282609196-4290715281 +3443336601-3445562948 +4214124431-4222284544 +2794821062-2808024455 +921040981-924782187 +3596013391-3634862951 +534260866-548375289 +2458958602-2471455540 +3747894091-3748207701 +3870276360-3876280026 +3561742937-3565733282 +1010250932-1013103239 +2379531720-2403063175 +4157404438-4179114808 +4122554616-4123181860 +2266233269-2267898523 +1269632604-1282811736 +3773683933-3793706430 +2118949830-2134862117 +3953370767-3954791800 +765097189-767835931 +4263676902-4263871920 +4122946518-4123339915 +3892929343-3918435066 +3894650477-3929356673 +1047369390-1055679545 +4099992190-4103492112 +684023283-690649422 +2594592198-2597798504 +1058010651-1058988695 +3115484628-3128398224 +3252155476-3257172193 +4049977614-4050836259 +382218782-403479826 +971551901-981281276 +1066029358-1070060324 +36858571-47781806 +4158832957-4162735890 +3227501781-3251213560 +117094986-125882172 +1164142799-1173104466 +1336713132-1336741874 +2145222298-2153331727 +3962298480-3979228569 +3883668675-3884341737 +397208388-405391678 +3445102676-3445710895 +1389996440-1390087951 +2596728957-2601220450 +1625518726-1631665836 +2950389967-2953503525 +2963495051-2966111203 +1717904817-1729835403 +2244213154-2244993380 +2712395750-2723137423 +2435701775-2443021902 +2769782692-2780956386 +3747890793-3749909803 +659919226-662823969 +2018309465-2021408890 +2039257534-2055909502 +776039246-819243394 +2399763610-2422439722 +2244985646-2245228003 +1312204080-1322368748 +2059975223-2081217736 +4122479870-4123106635 +3719013979-3724775893 +858332479-880227949 +3858201699-3883668674 +2943109114-2966569634 +1000078355-1001761966 +472782809-486761737 +4113600355-4128801300 +2126535844-2129289971 +653071206-653811254 +3193148546-3202372563 +1121171845-1123503826 +4117243649-4133449289 +3237836668-3242352363 +3563022333-3569223532 +1485681399-1486549340 +608600410-609717306 +1584695275-1595117760 +1902892027-1915238898 +3371035006-3393214245 +3781150080-3801571299 +1233579115-1240736343 +661238616-663188533 +1552875969-1556456026 +654720606-659919224 +1488302562-1490353649 +1913673058-1917368445 +925470578-931362800 +1342859338-1368038853 +2038683701-2041333415 +2724425360-2727127788 +1098540136-1110198142 +673837200-682507492 +4047521532-4050045319 +2013033863-2018188690 +3054747092-3059173006 +4018258817-4028994309 +1629155802-1632788530 +991839446-998952485 +562145555-580230572 +3559785001-3562279352 +2836791888-2853681259 +983516355-991056333 +308562480-309430392 +674892544-689161021 +3528530225-3555941172 +2699137547-2708354864 +207156716-212616825 +4207753750-4220186938 +999863836-1001070582 +32259707-50079603 +2828275808-2850650148 +2039145807-2050771690 +2853412433-2873411805 +1282564486-1294910000 +2325148871-2330744570 +4024584612-4036410734 +2266106272-2267798061 +1123503828-1126773928 +2256107855-2291118816 +2772046892-2774797854 +3994843756-4002939303 +2732360553-2738858553 +3563635700-3578715286 +1505194531-1515567631 +2823286861-2823806336 +1818510208-1828668302 +1006314070-1012036709 +777709024-811196432 +2288165187-2294864498 +524054451-537548994 +1117811844-1121528612 +3165477738-3167086245 +3916194238-3917540974 +3775795777-3801302318 +3869811313-3874702891 +2365098298-2391411578 +1219475193-1237534441 +3846236610-3852986508 +2320430743-2327712356 +1402760255-1405869683 +3953422050-3956521070 +3535691776-3549207496 +920978465-931907658 +1832159289-1832246964 +785927945-830988238 +998952487-1000004784 +2461193412-2471504681 +3022276174-3024570760 +4262228301-4262493194 +785443701-801465571 +3785994706-3811837885 +3807334690-3819765091 +3673204729-3694489170 +3493281814-3499674093 +3141271231-3165373517 +921614839-950271878 +1662301645-1662563099 +3655491185-3656562728 +1102807557-1103843461 +346905339-354216679 +3433389503-3435931339 +1628325742-1638473994 +1267013398-1278804179 +1786577801-1810150299 +729849282-746564537 +1389346888-1389605636 +1390087827-1390331164 +3089706079-3092957140 +1559519643-1571261641 +3061804240-3069263603 +789326592-822746971 +3790762266-3823382594 +3024918011-3025603433 +1901731825-1910889978 +221787289-227134887 +2286065379-2289890860 +3502011450-3507276371 +1548306359-1561645926 +3459941445-3471082533 +3299442738-3313994747 +3266460634-3271035378 +413716286-418678242 +208460902-212960541 +2686874673-2694055319 +855623938-868720621 +3094083612-3098709952 +3985433654-3995048286 +1193251897-1233472595 +3088923299-3112153677 +1587957790-1599354834 +123843379-130969451 +3257436899-3274021069 +3497576854-3499382133 +920128668-923982837 +4048833150-4050132991 +1405586209-1407458263 +3265335828-3274774964 +1267251256-1280445269 +3898180436-3921372030 +1607242066-1631594583 +758994866-764068425 +761300629-762440244 +1085580076-1107729977 +296615725-307962372 +1824736464-1830239319 +1704751954-1713152671 +296288709-302836730 +3445788218-3446978671 +1839490311-1880692874 +1890391784-1913900038 +3379893868-3391882605 +1344731056-1374424194 +4007484017-4019069794 +1031587468-1036068823 +2861344334-2870455131 +3061072914-3068795780 +1618523268-1652835581 +1579033620-1583069016 +636591787-638895361 +2372294665-2414726364 +692264210-693980274 +799669527-799871872 +1523255094-1530404912 +2019105958-2021782653 +2975710047-3013256765 +3373038727-3391155696 +4259701425-4263703639 +1513199351-1529351133 +914180376-940277913 +760395312-770866764 diff --git a/day20/src/main.rs b/day20/src/main.rs new file mode 100644 index 0000000..9d76a26 --- /dev/null +++ b/day20/src/main.rs @@ -0,0 +1,80 @@ +use std::ops::RangeInclusive; + +#[cfg(debug_assertions)] +const INPUT: &str = "example.txt"; +#[cfg(not(debug_assertions))] +const INPUT: &str = "input.txt"; + +fn main() { + let ranges: Vec<_> = std::fs::read_to_string(INPUT) + .unwrap() + .lines() + .map(|l| { + let mut parts = l.split('-'); + let low = parts.next().unwrap(); + let high = parts.next().unwrap(); + RangeInclusive::new(low.parse::().unwrap(), high.parse().unwrap()) + }) + .collect(); + + // dbg!(&ranges); + let result = consolidate_all_ranges(&ranges); + dbg!(result); +} + +fn consolidate_all_ranges(ranges: &[RangeInclusive]) -> Vec> { + let mut work = ranges.to_vec(); + + let mut to_remove = (0, 0); + loop { + let mut found = None; + 'middle: loop { + if work.len() == 1 { + break; + } + for i in 0..work.len() - 1 { + for j in i + 1..work.len() { + if let Some(range) = merge_two_ranges(&[ranges[i].clone(), ranges[j].clone()]) { + found = Some(range); + to_remove = (i, j); + break 'middle; + } + } + } + } + if let Some(range) = found { + dbg!(&range); + work.remove(to_remove.1); + work.remove(to_remove.0); + work.push(range); + } else { + break; + } + } + + work +} + +fn merge_two_ranges(ranges: &[RangeInclusive]) -> Option> { + let a = &ranges[0]; + let b = &ranges[1]; + + if ranges_overlap(a, b) { + let start = if a.start() < b.start() { + a.start() + } else { + b.start() + }; + let end = if a.end() > b.end() { a.end() } else { b.end() }; + Some(*start..=*end) + } else { + None + } +} + +fn ranges_overlap(a: &RangeInclusive, b: &RangeInclusive) -> bool { + (a.start() < b.start() && a.end() > b.start()) + || (b.start() < a.start() && b.end() > a.start()) + || (a.start() < b.start() && a.end() > b.end()) + || (b.start() < a.start() && b.end() > a.end()) +}