commit 2c747da3b23c01b0a413697ebda50fafd22c48de Author: Klotz Date: Thu Mar 20 18:31:55 2025 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..738a002 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,54 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "aoc24" +version = "0.1.0" +dependencies = [ + "regex", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1956ead --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc24" +version = "0.1.0" +edition = "2024" + +[dependencies] +regex = "1.11.1" diff --git a/inputs/day1.txt b/inputs/day1.txt new file mode 100644 index 0000000..7d1b595 --- /dev/null +++ b/inputs/day1.txt @@ -0,0 +1,1000 @@ +40094 37480 +52117 14510 +92290 82570 +41563 59882 +56597 98604 +60657 66508 +85570 59882 +56065 27818 +78474 72704 +71099 14510 +34302 92950 +11680 14510 +17162 66508 +85767 69912 +43222 99057 +84192 42459 +86349 47916 +15974 93804 +62582 84872 +46480 96423 +49083 47125 +26321 82391 +29705 99057 +76669 53445 +97344 23937 +22364 82947 +43057 41784 +89096 14096 +54594 74691 +16496 21289 +16315 26820 +12070 39776 +92869 76329 +51048 82455 +39150 94320 +58187 83731 +68901 59853 +73788 77097 +11009 17200 +88295 15720 +59037 65311 +89459 74691 +44460 30211 +71139 80238 +91079 65185 +35005 50427 +50560 84872 +66445 66508 +11233 14510 +17699 33984 +90637 44753 +93142 10300 +19092 42065 +19173 83731 +58875 86050 +63423 83870 +71780 70501 +29252 92869 +59508 78068 +28083 14549 +81355 33405 +64678 38506 +83118 41435 +83177 48400 +94114 70501 +52985 82400 +60853 70531 +70827 98303 +78106 23782 +58175 55623 +33789 19841 +76421 45114 +58847 77539 +99979 53408 +59287 42943 +73877 29014 +95914 36915 +84344 87773 +19462 84872 +75441 13097 +51621 85661 +18456 32965 +49881 48400 +59056 55469 +52464 14549 +17562 76246 +99617 74396 +14300 46447 +15278 16859 +78081 41160 +74953 18829 +96718 92869 +56734 70429 +96632 92950 +87669 82496 +41413 47115 +23478 83870 +44726 38354 +98494 70501 +20040 82400 +52539 42459 +66799 78088 +34219 14821 +47568 77539 +36511 76135 +49296 14510 +81088 39776 +29532 39776 +93599 32110 +89573 43968 +61226 48400 +61073 17960 +10265 55334 +83307 82947 +26932 81159 +66857 83731 +77172 74877 +82796 14510 +83224 75812 +65968 33984 +58067 54289 +27835 73261 +25580 85562 +28693 14510 +11013 42459 +72686 75812 +38200 64002 +10540 82391 +16594 86787 +38238 47324 +72787 84872 +32314 65237 +52509 85451 +11856 42459 +74689 14549 +11006 47324 +62911 36777 +96648 28762 +78556 84872 +43118 55149 +15524 18835 +97188 68430 +36316 11638 +23469 74803 +30969 33984 +19616 57386 +74603 51560 +73140 52522 +50052 84086 +67225 82400 +82945 39776 +59463 36777 +43724 39776 +38655 36019 +16887 34982 +63076 82400 +57786 92869 +40159 91888 +86882 74877 +30168 74750 +94821 91385 +22335 20714 +14549 74691 +17267 46572 +86022 83923 +40758 83870 +33144 41548 +20281 78088 +87782 14661 +26820 67869 +72492 81368 +92950 55032 +42737 36777 +22360 65185 +61694 67189 +43534 76135 +25697 62054 +65617 70501 +36055 82455 +42978 70973 +69418 29676 +87319 39776 +92611 74554 +45366 50611 +86780 47925 +14580 36676 +60406 24721 +44987 66508 +23481 13654 +89422 77304 +21807 92950 +52893 22984 +70221 76135 +61432 28691 +50739 61410 +69705 10534 +11551 84737 +14653 82947 +84764 70227 +19435 86399 +46702 90481 +59882 66508 +27462 39776 +45303 78835 +41509 75370 +22494 80790 +59433 58283 +19204 20602 +13874 75812 +50130 44169 +68727 83731 +58262 18103 +33787 88584 +28931 50419 +90686 77539 +33865 92950 +57146 59882 +26465 55530 +68279 41051 +77998 92950 +44063 69056 +21928 28982 +18478 83731 +79582 30353 +80695 81630 +25322 71284 +52650 91070 +90146 16859 +74890 66508 +54271 49699 +35728 96535 +15295 88122 +85415 41051 +96077 74836 +71257 31093 +10677 78088 +72271 58494 +50820 64678 +12266 33434 +32264 78179 +59541 64841 +51353 83870 +41310 74853 +62865 15554 +66303 53130 +30556 25580 +27203 66508 +31790 71172 +33932 47324 +43212 88773 +58069 83731 +88235 25580 +41094 99057 +25979 25580 +62261 60853 +79993 23589 +73964 71455 +82400 64678 +65762 18579 +73651 16859 +67581 76135 +30713 14716 +47252 19658 +14691 39961 +40662 12202 +57025 69091 +83266 48400 +30600 79683 +62076 16859 +16881 83870 +65361 63743 +80773 63741 +71794 48591 +65839 66508 +75318 20602 +91238 82391 +45707 64678 +40980 77539 +85661 99057 +59298 29272 +19492 84014 +93934 48400 +15984 64678 +89737 48584 +94738 63640 +36639 52035 +61394 40066 +48772 34199 +18258 74691 +20283 80659 +63972 40629 +82137 59882 +76239 25580 +12349 41106 +75728 64348 +74691 78088 +62001 21680 +70269 34199 +25443 39776 +19584 15829 +30199 87448 +92524 19400 +41674 23116 +63728 44519 +99875 91712 +17735 30851 +67540 81902 +27828 92950 +85889 33984 +39816 37113 +87480 91733 +19469 33984 +62803 12772 +17043 33984 +97479 81159 +91505 45435 +12207 69925 +60626 95997 +68126 92869 +76852 13346 +71419 70109 +49664 42459 +74526 32376 +16446 47891 +23116 39776 +43806 64678 +23988 61719 +97167 92950 +66668 44592 +25225 35154 +14284 14510 +23861 47115 +55048 45238 +33484 60853 +46372 80717 +61795 22743 +73995 44753 +89733 76532 +91399 53238 +53467 20602 +71484 98629 +37974 64678 +73312 99057 +75812 73554 +47324 58729 +14895 92017 +69525 50204 +47032 78088 +90971 72856 +63357 33984 +94931 99057 +11959 73715 +70226 77539 +54005 44541 +38941 48400 +64230 74691 +31008 11797 +47599 55425 +67007 10384 +14054 82455 +22131 22556 +52663 80307 +90266 61207 +76934 33537 +97373 27252 +37507 99057 +95323 86821 +79869 56443 +53249 77539 +62806 14510 +23745 41051 +61452 60853 +97548 19963 +57870 24236 +18763 15129 +85117 39776 +30254 51456 +51491 67525 +93572 77539 +82325 83731 +15877 41056 +98690 11852 +58483 14549 +46792 46579 +19738 32343 +96327 41051 +84003 82455 +58135 99057 +22481 68384 +38401 92272 +44698 30430 +39030 14510 +64037 47324 +70100 84872 +64299 48400 +75003 18219 +74190 19588 +71831 92869 +20635 88403 +28133 39036 +39722 42459 +42378 20602 +31939 75812 +69490 77539 +85822 41051 +99562 93734 +48527 23116 +56404 52393 +44682 26105 +66332 92869 +55356 52743 +13056 18829 +19925 82455 +66686 22256 +48103 99057 +82466 99057 +71384 20602 +56960 36777 +14192 41310 +44212 58300 +71988 92950 +90172 75812 +86104 75812 +58359 98375 +95930 48202 +61264 14510 +85630 74877 +27124 48370 +49572 48140 +48424 77539 +77569 45931 +30308 81159 +26594 40011 +63775 66508 +34220 82947 +46571 47585 +81978 77539 +37668 82947 +51727 66508 +79066 20602 +12567 74691 +47130 12241 +15691 93831 +65408 33984 +15617 82400 +48601 36777 +10561 60853 +97955 41051 +82817 21661 +21081 77539 +50859 33984 +23474 82400 +15893 47324 +48663 98013 +80276 77539 +29558 64989 +98180 99880 +31381 66796 +32510 14549 +47508 15854 +14500 14549 +30226 70501 +10524 92869 +26213 92869 +75481 44753 +39239 53324 +72660 64678 +16154 83870 +84492 41051 +21987 20602 +45236 75576 +36827 57147 +81865 60831 +36531 99057 +77201 70501 +28863 31856 +32410 48400 +62294 53873 +49825 99057 +17226 50273 +36614 34199 +14510 48400 +15818 74691 +41051 27891 +39776 33984 +43740 25580 +61248 97412 +63739 47404 +33984 88105 +64598 81159 +71104 89965 +71399 13250 +22174 20602 +60654 39776 +36993 45136 +81016 74327 +47735 64918 +80903 14510 +87865 39776 +38245 91066 +29883 51319 +52463 23311 +32632 35610 +75507 97544 +57330 65354 +59693 55540 +96123 48400 +15649 92950 +84872 82947 +52036 85576 +56140 65185 +23571 32245 +45230 97874 +49231 50934 +43993 85661 +27831 14510 +59732 83870 +46676 39776 +92968 60853 +66157 28036 +88365 70501 +78552 95048 +30812 39388 +70615 32340 +90718 49637 +55059 43376 +44052 32254 +64928 14510 +49820 82400 +60638 64678 +39415 82391 +17390 82391 +64214 77539 +59411 78901 +13819 33984 +92129 28689 +51618 86239 +24039 42459 +27702 39776 +69110 75948 +58967 84872 +97823 45780 +11609 82400 +54722 82391 +82391 18829 +74051 85569 +24976 75812 +65185 36777 +86919 18888 +39690 82947 +42614 48845 +36554 16859 +29410 99296 +38412 70501 +74218 18829 +49407 90164 +48400 64678 +23114 82947 +27649 78088 +68537 78526 +24479 21094 +47444 99057 +65003 33984 +39426 83535 +90358 51196 +22234 98284 +30880 28789 +32544 82947 +10847 82947 +54047 18829 +52242 32818 +10490 24089 +41618 75977 +35876 14549 +49262 28889 +94438 26726 +51893 75812 +93759 58987 +51981 14510 +60103 71702 +88905 66508 +48747 42459 +96263 75812 +40463 83870 +48597 57204 +22536 44753 +66412 99054 +17790 66120 +77539 25203 +78865 50851 +50309 81159 +17303 35610 +54010 79127 +20241 14510 +63100 92950 +83731 14510 +68951 31982 +56970 82400 +44753 60853 +46362 49519 +67946 60853 +84813 83698 +71665 11245 +30689 66459 +69584 47324 +42706 75812 +52831 78088 +92039 20602 +58831 14549 +20290 41051 +90055 41727 +50084 48967 +23456 27651 +39078 41568 +63877 34199 +99100 83870 +45801 64678 +84659 44834 +11493 25580 +69169 85661 +67297 75310 +13814 88874 +92809 83870 +84504 44970 +18829 39776 +32708 83870 +55821 81159 +33006 82400 +73062 16859 +19055 99551 +78888 33984 +19620 36962 +35643 84872 +36777 74691 +81225 41051 +11880 96744 +58979 11943 +22530 25580 +61936 72308 +50817 85661 +33683 82947 +38394 67535 +78267 50808 +90229 95996 +76219 47324 +24324 40775 +64552 77539 +50492 24650 +75184 37186 +72456 98388 +65577 28564 +74502 42459 +70395 70501 +45032 12987 +71299 82400 +39462 59882 +90600 62577 +47384 74691 +13946 81159 +72317 58599 +15940 38852 +10917 33984 +35057 70501 +62360 55948 +78591 36777 +92380 95224 +80300 25360 +74967 47844 +33642 32775 +67167 29873 +84766 31938 +54914 18149 +12612 60853 +51871 78088 +52446 11322 +45850 99057 +86339 20388 +92007 92950 +50584 55255 +74877 83870 +70625 36777 +59262 76788 +88734 74877 +54461 99057 +53614 20602 +97695 92442 +95664 74877 +26474 63443 +40271 66508 +46223 27041 +95183 18367 +23141 76135 +90287 82391 +86387 74877 +59164 63318 +96424 13830 +46986 50003 +14676 98418 +16897 75812 +93799 83870 +26152 14783 +73164 35799 +83870 74691 +69539 25580 +37270 25580 +22633 66508 +95442 35703 +60229 92950 +68469 74691 +32827 95745 +54254 66508 +19421 30678 +83601 37175 +48236 33984 +35864 92869 +12715 91646 +37578 49676 +52157 28386 +89788 39266 +55235 50669 +77355 33641 +92895 48400 +90314 82391 +89697 29794 +78864 81204 +74210 71372 +19120 45857 +50876 30101 +59106 92950 +19702 25499 +97014 91896 +74875 16783 +13073 84306 +26041 83870 +68942 88484 +40578 83731 +72258 65004 +92705 83870 +86757 59882 +98431 76644 +26967 82947 +16928 37207 +35610 15275 +78099 66508 +18168 48400 +58016 48400 +81932 93264 +49522 70501 +46342 99057 +78434 34199 +57459 93096 +99686 37409 +45420 15677 +65862 61547 +68451 32852 +62057 20602 +54187 53430 +41398 43131 +81637 25396 +10157 93885 +66508 12152 +10450 84872 +25261 20602 +56274 63730 +72119 95604 +46569 75812 +35380 42970 +43443 92950 +39631 52734 +42459 45026 +96567 34884 +93222 62504 +60053 71698 +75897 47324 +48328 20602 +99057 48400 +35826 82341 +67035 82400 +58053 86856 +81936 12257 +68310 14510 +29468 62020 +81781 67379 +15436 14549 +56095 65185 +66163 10638 +49425 14510 +68972 92950 +49574 14549 +38234 83870 +28540 84872 +81462 48400 +41295 34199 +80808 91315 +28524 33984 +77949 74691 +99083 20602 +62026 42459 +31125 48400 +79195 63833 +42400 74725 +13187 57183 +28716 77539 +80819 92964 +95678 39668 +54023 39776 +59766 42459 +71124 13499 +68339 49253 +61897 46696 +80221 11294 +35387 98184 +68473 39786 +35763 73269 +65760 20385 +89259 47268 +14170 77539 +35101 85211 +18374 83870 +92328 85661 +82839 78903 +18361 33984 +23227 74691 +95071 64678 +90966 82947 +95801 77539 +81159 64755 +65256 70501 +55147 13543 +15387 99057 +35642 82400 +32240 27515 +67866 14549 +12086 49665 +36184 84872 +15635 31890 +10214 40993 +49134 77539 +62743 48400 +44489 70501 +80178 68714 +36457 78753 +17887 84293 +16849 67107 +63559 77539 +80694 52080 +58142 78088 +18872 14510 +12338 67478 +85829 40208 +66792 84872 +61928 93693 +33263 17549 +84614 81847 +61330 48400 +68335 20602 +29181 60853 +74548 75771 +30127 15911 +47115 26923 +91933 35610 +83734 84584 +44683 89834 +41249 78088 +80290 48400 +96903 79098 +70501 82561 +32022 63239 +69817 24120 +90313 78614 +70861 42934 +58151 47251 +28667 55887 +22841 34199 +73857 71309 +16835 14899 +95850 34199 +50640 51985 +18035 47324 +37594 50221 +16970 71726 +25362 15286 +44543 18995 +83609 45774 +89691 84872 +50795 70501 +24679 48469 +71908 82947 +67185 38287 +18054 35390 +34199 69184 +40616 75812 +20602 94728 +49793 82400 +14963 24258 +60662 74691 +86403 43539 +74430 66236 +77078 39136 +87428 82947 +77070 54393 +70944 42459 +12653 18130 +81773 25580 +49019 17153 +82455 31077 +25942 64678 +26835 91201 +39062 80768 +81313 27193 +45192 77539 +15593 37923 +56100 28304 +82947 38124 +88630 40195 +52146 10487 +85442 23549 +99766 23732 +16859 25580 +21961 24033 +76135 30552 +17662 77266 +52907 28266 +98310 14512 +52835 17260 +41921 99977 +98536 79658 +14361 75812 +33091 85661 +98222 76135 +21436 89453 +38710 11479 +82047 68962 +35897 14592 +88326 74877 +46035 99057 +78652 97213 +44755 20602 +96573 47324 +36653 46767 +70603 26820 +61979 76005 +21272 39776 +78088 81081 +34305 33984 +35661 10012 +61006 47115 +93440 41051 +21321 98330 +75070 16859 +95372 70501 +38869 60853 +76195 78088 +14557 46481 +42861 86390 +57044 34199 +68752 33984 +86232 67003 +27620 76135 +55091 37530 +29965 41051 +33771 84872 +58339 66508 +12708 75812 +72653 92869 +84021 10337 +87356 82391 +74653 92950 +92234 47324 +50621 33984 +42267 64801 +22400 42459 +24231 79555 +58301 84563 +80962 99057 +71109 14549 +65386 46911 +26148 43854 +38755 82400 +75344 98637 +25436 14549 +64378 97144 +62564 94652 +10638 16859 +38487 36777 +73552 66508 +91379 34199 +22001 14549 +56967 13015 +98527 38329 +41766 38964 +10762 75812 +15598 25580 +42586 16859 +51351 32233 +59322 66508 +98442 10520 +15717 73514 +20342 72228 +13498 75812 diff --git a/inputs/day2.txt b/inputs/day2.txt new file mode 100644 index 0000000..0164a32 --- /dev/null +++ b/inputs/day2.txt @@ -0,0 +1,1000 @@ +6 8 9 11 10 +13 16 19 22 24 25 25 +43 46 47 48 50 52 56 +55 57 60 61 64 65 68 74 +81 84 86 83 84 87 +45 47 50 49 46 +15 16 18 16 16 +79 80 81 79 80 83 85 89 +70 73 74 72 77 +78 80 81 81 83 +77 79 82 85 88 88 89 87 +74 75 75 78 80 82 82 +83 84 84 87 88 90 94 +9 11 14 16 16 21 +40 42 44 48 51 53 56 +71 74 78 81 80 +7 9 11 14 18 20 21 21 +74 77 81 82 83 87 +76 77 79 80 84 86 93 +62 63 69 72 75 77 78 +21 23 29 32 35 37 35 +85 87 88 94 94 +45 47 49 56 60 +45 46 51 54 56 61 +63 60 62 65 67 69 +39 37 40 43 44 45 46 45 +84 81 84 87 87 +93 91 93 95 99 +45 44 46 47 49 56 +72 69 68 69 72 +83 81 84 81 80 +4 3 5 7 6 8 10 10 +92 90 87 89 93 +46 45 47 44 47 48 49 54 +43 42 43 43 45 +18 15 15 17 20 21 19 +72 71 72 73 75 75 78 78 +49 46 47 49 51 51 52 56 +73 72 73 74 75 78 78 84 +52 49 53 55 57 60 62 +21 19 23 25 27 29 28 +80 77 78 81 85 86 88 88 +21 20 24 27 31 +37 35 39 42 48 +64 61 63 69 70 72 74 75 +84 83 85 88 94 91 +24 23 30 32 34 37 37 +70 69 70 75 79 +4 3 8 10 13 20 +13 13 15 17 18 19 21 +9 9 10 12 15 13 +50 50 53 55 57 60 62 62 +5 5 7 9 13 +43 43 45 47 48 50 55 +79 79 81 84 82 85 88 +92 92 95 93 96 95 +22 22 23 22 23 25 26 26 +84 84 85 83 87 +72 72 70 71 72 78 +17 17 19 19 20 21 24 +41 41 44 47 47 44 +31 31 31 32 34 35 35 +7 7 9 12 12 14 18 +21 21 21 22 29 +83 83 85 86 88 92 94 97 +26 26 27 30 33 37 35 +28 28 32 35 35 +82 82 85 88 92 96 +6 6 10 12 18 +83 83 88 89 90 92 95 +19 19 24 26 28 27 +41 41 48 49 49 +25 25 32 33 34 36 40 +28 28 29 30 33 36 43 50 +83 87 89 90 93 96 99 +46 50 53 54 55 58 59 56 +65 69 70 73 76 78 78 +67 71 72 75 77 78 82 +82 86 87 89 96 +81 85 86 88 91 93 92 94 +59 63 66 67 65 67 64 +16 20 19 20 20 +89 93 96 93 97 +70 74 72 74 77 83 +7 11 13 14 14 15 16 +26 30 31 33 36 39 39 38 +55 59 62 64 64 66 66 +30 34 35 35 38 40 43 47 +5 9 9 12 15 22 +43 47 49 52 53 54 58 61 +38 42 46 48 51 53 50 +1 5 6 10 10 +9 13 17 20 21 23 27 +28 32 36 39 40 43 48 +23 27 33 36 38 40 41 +51 55 57 63 61 +64 68 70 77 78 81 83 83 +22 26 29 32 37 41 +80 84 90 92 93 99 +57 63 66 68 70 +75 82 84 85 86 85 +52 58 61 62 62 +49 56 59 61 63 66 70 +33 39 40 42 45 46 53 +71 77 75 76 77 +73 79 76 79 82 84 82 +53 58 60 62 64 63 63 +47 54 51 53 55 58 60 64 +70 77 74 76 83 +41 46 46 48 49 +26 31 33 33 32 +82 89 91 91 92 92 +54 60 60 61 65 +20 25 26 26 31 +49 56 57 61 62 65 +60 65 68 70 72 76 77 75 +8 13 16 20 22 24 27 27 +17 24 25 29 31 35 +74 79 83 86 93 +5 11 14 21 22 25 28 +48 53 55 61 64 67 69 68 +68 73 74 80 82 82 +9 14 19 20 21 25 +10 15 22 24 29 +68 65 63 61 59 60 +25 24 21 20 20 +71 69 66 65 62 58 +77 76 73 71 64 +83 80 81 79 78 75 +20 17 20 19 18 20 +70 67 65 64 66 66 +93 92 94 92 88 +75 72 69 70 68 61 +12 10 7 7 5 4 2 +63 62 59 59 62 +18 17 14 13 12 12 10 10 +82 80 78 78 75 71 +26 24 23 23 18 +49 47 43 42 39 36 34 33 +50 49 46 42 39 41 +38 35 31 29 27 25 25 +15 14 10 7 5 1 +69 66 64 60 59 56 55 49 +77 75 73 67 64 62 +95 93 90 87 81 82 +14 13 12 10 9 4 4 +62 59 56 49 46 42 +47 44 37 34 32 30 29 24 +79 81 78 75 72 70 67 65 +62 64 63 60 58 59 +66 67 66 64 63 61 61 +38 39 38 36 34 30 +39 42 41 39 38 37 34 27 +58 61 58 55 53 52 53 52 +82 85 87 85 88 +25 26 27 25 23 21 21 +87 89 91 88 87 86 84 80 +34 35 33 34 32 27 +85 88 85 84 84 83 +14 16 16 14 15 +16 18 15 12 12 10 10 +55 57 54 52 52 48 +71 74 73 73 72 67 +25 28 24 21 19 16 +59 62 60 56 55 53 52 54 +55 57 53 50 47 45 44 44 +34 37 34 33 32 28 24 +84 87 83 80 78 76 73 66 +23 25 23 17 15 +75 78 76 74 73 70 65 68 +24 25 19 17 17 +95 98 92 91 87 +91 92 90 83 77 +45 45 44 43 42 +88 88 85 82 79 78 75 77 +55 55 54 53 50 50 +73 73 70 67 64 60 +97 97 94 92 91 84 +7 7 6 3 4 3 +71 71 70 67 65 66 67 +69 69 70 67 64 61 60 60 +20 20 18 16 14 16 15 11 +39 39 36 38 35 33 30 25 +42 42 42 40 38 36 +49 49 46 46 44 43 45 +19 19 17 15 15 13 13 +81 81 81 78 76 75 71 +20 20 17 17 14 12 11 5 +74 74 73 69 68 66 63 +68 68 65 61 58 61 +44 44 40 37 34 34 +60 60 59 55 53 49 +38 38 36 32 30 23 +70 70 68 62 61 58 +51 51 49 48 41 39 41 +28 28 25 19 18 18 +19 19 12 9 8 4 +83 83 76 73 67 +66 62 59 56 55 53 +19 15 14 13 15 +78 74 72 69 67 66 66 +93 89 88 87 84 82 78 +92 88 87 86 85 83 80 73 +84 80 82 80 78 76 +71 67 69 66 67 +84 80 78 81 81 +25 21 18 17 16 18 14 +57 53 55 54 47 +18 14 14 11 10 +66 62 59 58 55 55 58 +79 75 74 74 74 +67 63 60 60 59 56 52 +49 45 42 40 38 37 37 31 +94 90 87 85 81 79 +30 26 23 22 21 17 19 +75 71 68 65 63 60 56 56 +97 93 91 90 86 83 79 +23 19 18 14 12 6 +93 89 88 82 79 77 74 +57 53 52 50 47 42 45 +41 37 34 32 27 27 +96 92 91 86 84 81 80 76 +57 53 47 44 41 39 33 +49 43 41 39 38 37 35 +44 38 37 35 38 +24 18 16 13 11 11 +67 61 58 57 55 51 +60 55 53 52 46 +49 44 46 44 41 +16 9 10 8 5 7 +27 21 20 21 19 16 16 +20 15 13 16 13 9 +91 84 87 86 81 +60 55 52 49 49 46 45 +16 9 7 5 4 4 3 5 +94 88 88 86 83 83 +84 77 76 76 73 70 68 64 +65 59 57 55 52 49 49 42 +47 41 38 36 32 30 +24 19 18 14 12 14 +43 38 36 32 32 +78 71 68 64 62 58 +38 31 27 26 20 +30 24 23 18 16 13 +61 55 52 45 42 39 37 40 +30 24 23 22 17 15 15 +75 69 64 62 60 57 55 51 +94 89 86 80 78 71 +13 15 18 21 19 +20 22 23 26 29 29 +41 43 46 49 53 +27 30 31 32 39 +18 21 23 22 23 26 28 +64 66 69 66 68 69 71 68 +15 18 21 19 21 24 24 +76 78 80 77 81 +60 61 62 64 63 64 70 +13 16 17 17 20 21 +66 69 72 72 75 74 +14 16 16 17 17 +5 6 6 8 12 +1 3 6 6 12 +64 67 71 74 75 78 81 83 +20 22 24 26 30 33 35 34 +29 31 35 37 37 +31 32 36 37 40 42 46 +59 62 65 69 72 74 77 82 +77 78 83 84 85 88 91 +72 74 76 82 83 85 83 +12 13 15 21 21 +63 65 68 70 76 80 +42 44 47 48 53 54 55 60 +43 41 43 45 46 49 +38 36 39 40 41 40 +16 15 16 17 17 +29 27 29 32 35 39 +28 25 27 30 33 38 +44 41 43 40 42 44 46 +72 70 71 70 72 70 +83 80 78 81 83 85 88 88 +43 41 43 45 46 49 47 51 +69 66 65 66 67 68 74 +31 28 31 31 34 +66 64 67 70 70 71 68 +86 83 83 86 87 89 89 +76 74 74 76 79 82 86 +6 3 3 4 10 +43 42 43 44 47 49 53 55 +64 62 64 68 65 +61 59 62 64 65 69 72 72 +87 85 88 92 96 +48 46 50 53 60 +12 10 15 17 19 20 +26 25 27 29 30 37 34 +25 22 25 27 32 33 35 35 +55 53 55 62 65 67 70 74 +79 78 80 87 89 96 +58 58 61 62 64 66 68 +66 66 68 71 73 75 72 +30 30 32 33 34 37 37 +30 30 33 36 38 40 44 +78 78 80 81 83 90 +56 56 59 62 65 63 64 66 +38 38 39 40 37 39 41 40 +79 79 77 79 82 84 87 87 +21 21 19 21 22 24 28 +23 23 22 25 31 +68 68 70 72 72 75 +21 21 22 22 23 25 23 +22 22 25 26 26 28 28 +84 84 84 87 90 92 96 +76 76 79 79 85 +26 26 28 32 34 36 38 40 +15 15 17 21 19 +59 59 62 65 69 71 71 +30 30 32 35 38 42 43 47 +53 53 54 55 59 64 +28 28 30 37 38 +57 57 64 67 66 +65 65 66 69 74 74 +49 49 55 56 60 +39 39 41 42 49 56 +77 81 83 84 86 89 91 +12 16 18 19 22 24 22 +24 28 30 33 35 38 41 41 +85 89 91 93 95 99 +1 5 6 9 11 18 +66 70 72 74 75 77 75 76 +67 71 72 74 76 73 70 +2 6 8 11 12 9 9 +52 56 53 55 56 60 +15 19 22 21 28 +71 75 77 77 80 83 +16 20 22 22 25 23 +18 22 25 26 26 26 +8 12 12 14 15 18 19 23 +53 57 60 63 63 64 66 72 +37 41 44 48 50 +32 36 38 42 44 47 46 +3 7 9 11 13 17 17 +72 76 80 83 87 +61 65 68 70 72 76 77 82 +35 39 41 48 51 53 +80 84 85 92 94 95 94 +17 21 24 31 31 +61 65 70 73 76 80 +34 38 41 44 50 51 58 +22 27 30 31 33 36 39 42 +51 58 59 60 63 61 +35 41 42 44 45 46 49 49 +77 83 85 87 89 93 +14 20 23 24 25 27 32 +28 34 36 37 39 36 38 +62 69 71 70 68 +79 84 81 82 85 86 86 +63 69 71 68 70 74 +18 24 21 22 23 28 +76 81 82 83 83 84 86 87 +62 69 72 72 69 +79 84 84 87 90 90 +4 10 11 11 15 +46 52 55 56 56 58 63 +58 65 68 72 73 +44 50 53 55 59 56 +67 72 76 79 81 83 84 84 +64 70 72 76 77 79 80 84 +14 21 25 27 29 35 +11 16 18 19 25 27 30 +26 32 34 41 39 +18 25 26 29 35 35 +15 22 28 29 32 33 37 +74 81 82 88 95 +56 53 52 51 50 48 51 +11 9 6 3 3 +42 39 36 35 31 +67 64 62 60 54 +9 6 9 8 5 +38 35 33 36 35 36 +59 57 56 53 55 55 +97 96 94 92 93 89 +88 87 86 87 86 81 +40 37 37 34 31 +29 28 28 27 26 29 +91 89 87 84 84 84 +85 84 84 81 77 +16 14 11 11 5 +95 94 91 90 86 83 +40 39 38 37 33 35 +32 31 27 26 26 +22 20 16 13 9 +32 29 27 25 24 20 19 14 +60 57 55 50 48 +28 25 22 20 13 10 8 9 +45 43 42 36 33 30 30 +89 88 86 79 77 76 73 69 +27 26 19 16 13 10 3 +21 24 23 21 20 19 18 +32 35 32 30 28 27 29 +68 71 68 65 63 60 59 59 +58 59 58 57 53 +43 46 44 43 40 38 35 28 +9 11 12 10 7 +85 86 83 80 77 80 77 78 +8 10 8 7 5 6 6 +53 56 53 52 53 49 +24 27 25 23 20 22 20 15 +12 15 14 14 13 10 +53 54 53 50 50 47 44 45 +36 38 35 35 34 33 31 31 +36 39 39 37 33 +71 72 72 71 69 64 +11 13 11 10 6 4 +52 53 49 48 50 +59 61 59 55 54 54 +82 84 81 77 76 73 71 67 +56 57 54 53 49 46 44 37 +64 66 65 60 57 +65 67 64 58 57 56 59 +90 92 85 84 81 78 78 +43 45 44 42 36 32 +27 29 26 24 23 20 14 9 +53 53 51 49 47 44 42 39 +85 85 82 81 79 76 75 78 +51 51 50 48 46 46 +78 78 75 73 71 69 67 63 +36 36 33 31 29 22 +73 73 71 74 71 +16 16 13 11 13 14 +64 64 61 62 62 +53 53 55 52 48 +48 48 49 48 41 +28 28 26 26 25 +48 48 46 43 43 42 45 +77 77 74 72 71 71 68 68 +36 36 33 31 31 30 28 24 +26 26 23 23 17 +89 89 86 82 79 76 75 +14 14 13 12 8 6 8 +88 88 84 81 80 80 +55 55 54 50 47 43 +99 99 95 92 89 86 84 78 +56 56 54 47 44 +18 18 16 14 8 7 8 +87 87 80 79 78 76 74 74 +86 86 81 78 76 72 +87 87 84 77 75 73 66 +82 78 76 73 70 69 68 +38 34 32 30 27 25 24 25 +64 60 59 56 55 55 +50 46 45 44 42 38 +21 17 14 11 9 3 +39 35 34 32 34 31 +73 69 67 64 61 58 59 62 +23 19 16 14 17 17 +22 18 19 17 13 +27 23 21 19 21 18 17 12 +60 56 55 53 50 50 49 +21 17 14 14 17 +61 57 57 55 53 52 52 +89 85 83 82 82 81 79 75 +90 86 84 84 78 +52 48 46 42 39 +85 81 79 78 74 72 69 72 +40 36 34 31 28 24 24 +89 85 81 79 76 74 70 +43 39 35 32 29 27 22 +45 41 35 34 33 32 30 28 +74 70 68 62 64 +92 88 86 81 79 76 73 73 +71 67 64 63 57 56 52 +93 89 88 81 80 75 +27 21 18 16 14 +18 11 10 9 8 6 7 +80 75 73 71 71 +27 21 19 17 15 12 10 6 +43 38 36 34 33 28 +71 64 63 64 62 +97 91 89 88 87 88 89 +68 63 60 63 61 61 +17 11 13 10 9 7 5 1 +64 57 55 57 55 53 47 +73 66 63 60 59 59 56 53 +27 22 21 20 19 16 16 19 +31 25 25 24 24 +34 28 28 25 24 20 +73 68 65 65 64 59 +67 62 59 55 54 51 48 46 +76 70 68 64 61 58 60 +83 76 75 71 71 +76 71 69 68 64 60 +42 35 32 31 27 24 21 14 +52 46 44 43 36 33 +69 62 56 53 52 49 51 +23 18 12 10 9 7 7 +74 67 64 62 56 52 +28 21 15 12 9 2 +48 49 50 51 49 +48 51 52 53 54 56 56 +61 64 67 70 74 +14 17 20 23 29 +11 13 10 13 16 +26 28 31 30 33 30 +17 20 22 19 19 +59 61 63 65 62 66 +64 66 67 70 67 70 71 76 +20 22 22 25 28 31 +82 84 85 85 87 90 87 +32 33 36 37 37 39 41 41 +30 33 36 38 40 42 42 46 +83 85 86 89 92 92 93 99 +13 14 15 19 22 23 25 +20 21 25 28 26 +17 19 22 26 26 +35 36 40 42 45 49 +19 22 23 24 28 34 +37 39 40 46 49 +74 76 78 84 81 +23 25 28 35 35 +82 83 89 90 92 96 +39 41 47 48 53 +26 24 26 29 30 31 33 34 +8 7 10 11 9 +38 37 39 40 41 41 +39 38 40 42 46 +68 66 69 70 72 78 +60 57 59 60 58 61 62 +62 60 61 59 58 +11 10 12 14 13 13 +63 62 61 64 67 71 +89 86 85 88 90 91 97 +34 32 32 33 35 +16 14 14 17 18 19 18 +20 17 20 22 25 28 28 28 +6 5 6 6 10 +20 17 18 18 20 25 +20 19 22 26 29 32 35 +59 56 59 62 65 69 66 +72 70 71 75 76 79 82 82 +30 29 32 36 40 +80 79 83 86 93 +25 24 31 32 34 35 36 +12 9 14 16 13 +26 23 29 32 35 36 36 +23 22 27 28 32 +71 68 74 77 80 83 89 +81 81 84 87 90 93 95 97 +66 66 67 69 72 73 75 73 +75 75 76 78 80 82 82 +15 15 16 18 21 25 +51 51 53 56 61 +74 74 71 72 75 +34 34 36 35 32 +41 41 44 43 43 +72 72 69 71 75 +51 51 52 53 51 57 +53 53 55 58 59 59 61 +1 1 4 4 7 4 +76 76 79 79 82 83 83 +2 2 4 4 7 8 12 +85 85 86 88 88 93 +57 57 59 63 66 67 +65 65 68 69 71 72 76 75 +71 71 75 78 80 80 +29 29 33 36 40 +63 63 65 69 70 73 74 81 +11 11 17 18 21 24 +79 79 82 84 90 91 93 91 +15 15 20 23 25 25 +76 76 78 80 86 88 91 95 +38 38 39 46 51 +47 51 53 54 55 +33 37 38 41 40 +6 10 13 15 15 +50 54 56 59 60 62 66 +1 5 6 9 14 +44 48 46 48 50 52 +34 38 40 41 42 43 40 37 +77 81 82 83 82 83 83 +17 21 22 23 21 22 26 +74 78 80 78 80 83 88 +47 51 51 52 54 56 +65 69 72 74 75 75 77 76 +56 60 63 63 64 66 68 68 +53 57 58 59 59 61 65 +30 34 35 37 39 39 42 47 +72 76 78 82 85 88 89 +56 60 64 65 68 66 +83 87 90 94 94 +12 16 20 22 25 29 +45 49 53 56 63 +67 71 78 79 80 81 82 +75 79 82 84 89 92 91 +49 53 55 58 61 62 69 69 +58 62 64 69 70 73 76 80 +48 52 57 60 61 62 63 69 +45 52 54 56 58 60 +13 19 21 24 23 +25 31 32 33 34 37 37 +76 82 83 85 86 88 92 +48 55 56 58 64 +16 22 23 21 24 25 28 +25 32 34 36 35 32 +11 18 19 16 17 19 19 +25 31 32 34 37 40 38 42 +15 20 22 20 26 +67 72 75 75 76 79 +26 31 32 34 35 35 32 +71 77 80 81 83 85 85 85 +44 49 52 52 56 +66 71 71 72 73 76 78 83 +54 60 64 66 68 71 73 +36 42 45 46 50 52 49 +79 84 87 90 92 96 96 +30 37 40 42 44 45 49 53 +36 41 45 47 53 +45 52 59 61 63 +11 18 20 27 28 26 +16 21 28 31 31 +13 19 20 26 28 29 30 34 +56 61 62 65 72 75 82 +20 18 16 15 16 +37 34 33 32 31 30 30 +50 49 46 45 42 38 +61 58 55 53 51 48 43 +72 69 68 71 70 67 65 +13 10 11 9 8 7 10 +64 63 61 62 62 +48 46 47 46 42 +44 42 43 41 40 33 +11 8 8 5 2 +94 91 91 88 89 +47 46 43 43 40 40 +93 90 87 87 83 +25 23 20 18 18 12 +83 82 79 75 72 +38 35 32 29 25 23 24 +77 76 74 70 68 66 66 +85 83 81 78 77 75 71 67 +49 48 47 43 42 36 +79 78 75 73 72 70 63 61 +32 29 27 24 18 19 +48 47 40 38 38 +56 53 50 49 42 39 35 +25 22 21 20 15 8 +59 61 58 57 55 54 +64 67 64 61 60 58 61 +21 23 22 20 19 16 16 +68 69 67 65 64 60 +21 23 21 20 17 15 12 5 +11 12 10 7 8 6 4 3 +94 96 93 95 98 +77 79 77 78 75 72 72 +23 24 21 19 20 19 15 +32 34 33 34 27 +15 17 17 16 15 +34 37 35 32 31 31 33 +24 25 22 20 19 19 19 +15 18 15 15 13 11 7 +88 90 90 89 86 85 83 76 +81 84 81 77 74 72 69 +50 53 50 46 49 +51 53 49 48 48 +52 53 49 46 44 41 38 34 +57 60 58 55 51 48 41 +87 89 88 82 79 +64 65 64 61 54 55 +95 96 93 90 83 81 78 78 +17 20 18 11 9 6 5 1 +42 45 38 36 29 +48 48 47 44 41 40 +21 21 18 16 13 12 10 13 +64 64 63 60 57 57 +19 19 17 14 11 8 6 2 +18 18 15 13 8 +97 97 99 98 95 94 +42 42 40 42 40 38 39 +5 5 8 6 4 4 +66 66 64 63 61 64 62 58 +18 18 16 18 16 15 13 6 +23 23 23 20 17 16 +41 41 41 38 40 +36 36 34 31 28 28 28 +70 70 70 68 65 64 62 58 +21 21 19 19 14 +66 66 62 61 59 56 54 53 +78 78 74 71 68 67 66 68 +81 81 80 78 74 73 71 71 +69 69 68 64 60 +68 68 66 62 60 57 55 48 +55 55 48 45 43 42 40 38 +23 23 21 14 15 +61 61 60 57 56 51 51 +66 66 64 62 60 54 50 +96 96 90 87 81 +39 35 33 31 30 28 25 +35 31 28 26 23 26 +83 79 78 77 75 72 72 +42 38 37 35 31 +50 46 44 43 40 38 37 31 +74 70 69 71 69 68 65 63 +97 93 90 93 96 +43 39 38 35 38 35 35 +60 56 59 57 53 +87 83 82 85 83 77 +28 24 22 22 19 17 +52 48 48 45 48 +16 12 9 9 8 6 6 +94 90 88 86 86 84 81 77 +87 83 83 80 78 77 71 +66 62 61 57 56 +36 32 28 25 24 21 24 +64 60 59 56 52 52 +73 69 68 65 63 62 58 54 +76 72 68 67 65 62 56 +33 29 24 21 18 +94 90 88 81 83 +30 26 21 20 20 +42 38 36 30 26 +47 43 38 35 28 +40 35 32 31 28 25 +87 82 80 77 76 75 76 +16 10 8 5 2 2 +29 24 23 20 18 15 12 8 +57 50 48 45 40 +58 52 54 53 50 49 +86 80 77 78 76 73 75 +75 70 67 69 69 +66 60 57 58 55 54 51 47 +38 32 30 29 31 24 +54 47 45 43 43 41 +74 69 67 67 70 +52 47 44 44 41 39 37 37 +36 31 29 26 26 24 20 +32 26 25 23 22 22 21 16 +34 28 25 21 19 +86 80 76 73 75 +65 58 54 51 50 49 49 +50 43 41 38 37 35 31 27 +35 28 24 21 18 11 +34 27 20 18 16 +14 9 8 3 6 +63 57 56 49 49 +94 88 85 79 77 73 +70 65 60 57 56 55 52 45 +69 69 66 65 64 67 66 66 +62 64 66 66 63 +82 80 78 76 72 74 +90 92 92 93 94 +69 67 64 62 60 +42 45 47 48 51 +36 39 42 43 46 49 52 +13 10 9 7 5 +25 26 28 29 31 33 35 38 +14 13 12 9 7 4 2 +65 68 70 72 75 77 +23 26 28 29 31 34 35 37 +17 14 12 9 7 6 4 2 +33 34 37 38 41 +37 36 33 30 27 +5 8 9 10 12 +63 61 58 57 54 +23 25 28 31 33 35 38 39 +13 10 7 6 4 +86 88 90 91 92 94 +55 54 53 51 50 48 46 +33 30 27 24 21 18 +65 67 70 73 74 75 78 +53 51 48 45 43 40 37 +94 92 91 89 87 86 83 +69 71 74 75 76 +72 74 77 79 81 82 84 85 +21 18 17 14 11 +18 17 14 12 9 +88 91 92 94 96 99 +12 9 6 5 2 +68 65 62 61 60 57 55 53 +30 27 25 22 19 18 17 +34 37 39 42 44 47 49 51 +71 74 77 80 81 84 87 +29 28 25 23 20 17 14 12 +53 54 57 58 59 +23 21 19 17 16 15 +31 34 36 37 39 41 42 44 +58 61 64 66 68 70 72 +3 4 6 9 10 13 15 +64 63 60 58 56 54 53 52 +75 77 78 80 81 83 86 88 +61 63 65 66 68 71 73 +20 23 24 26 28 30 33 +18 15 12 10 7 +50 48 45 43 40 39 37 36 +48 47 45 42 41 39 +7 10 11 13 14 17 18 +25 22 19 18 16 14 12 11 +53 50 47 45 42 +57 58 59 60 62 64 65 +38 41 42 43 44 46 47 +50 53 56 57 60 62 64 +86 83 81 78 76 74 72 69 +60 61 64 66 68 69 71 73 +13 16 18 19 22 25 26 27 +77 79 81 84 85 +81 79 78 76 73 71 +32 34 37 40 42 +89 88 87 85 84 83 +59 62 65 67 68 70 73 74 +54 57 58 60 63 +34 32 31 29 27 24 21 +43 45 46 49 51 +76 78 79 80 82 84 +36 34 32 30 27 +23 24 25 28 29 +19 22 25 28 30 33 35 +61 59 57 54 52 50 +23 24 25 27 30 32 33 34 +63 64 66 69 70 71 72 74 +85 86 88 89 92 95 96 97 +8 9 10 13 15 +74 73 71 68 65 62 60 59 +51 48 45 44 41 38 36 +41 39 38 36 34 31 +58 59 60 62 64 +29 31 33 36 38 39 41 43 +1 2 4 5 7 10 11 14 +24 27 29 32 33 35 +54 52 50 49 47 45 +30 29 27 24 21 19 16 14 +44 46 49 50 51 52 54 +24 25 28 31 34 36 +53 52 51 50 47 +63 62 60 58 57 56 54 51 +38 39 41 44 47 49 52 +97 96 93 90 87 84 83 +81 79 77 75 72 70 +36 35 32 31 29 +76 77 80 83 86 89 91 +21 22 24 27 28 30 32 33 +80 81 82 84 85 86 +94 93 91 88 85 84 81 79 +77 79 81 82 85 86 89 91 +42 39 36 35 32 29 27 +19 18 16 15 14 +63 62 60 57 55 54 53 51 +31 30 27 25 23 22 20 18 +35 37 38 40 42 45 46 +41 44 45 47 48 51 +19 21 23 26 29 31 +32 30 28 26 23 +31 33 35 37 38 +46 43 40 37 35 32 +81 80 77 74 71 +16 17 18 19 22 +67 65 64 62 61 +66 63 61 58 55 54 51 +46 49 52 54 56 +51 50 47 46 43 +30 32 33 35 36 +66 63 60 58 57 56 55 +67 64 61 59 56 55 +37 36 33 32 31 +87 88 91 92 93 95 96 +62 59 58 55 54 +12 10 9 8 5 +64 62 61 60 58 +16 18 21 24 27 28 29 +79 78 76 73 71 70 69 66 +87 85 84 82 81 79 77 +74 76 79 81 82 83 86 89 +91 89 87 85 84 81 78 77 +75 72 71 68 65 64 62 59 +52 55 58 60 62 64 +44 46 49 51 53 54 55 56 +65 63 62 59 56 55 52 51 +21 23 25 28 31 32 34 37 +81 79 78 76 73 72 69 67 +14 11 10 9 8 6 3 +59 56 55 53 51 49 +62 59 58 56 54 53 52 49 +45 48 49 51 53 55 56 +11 13 16 18 20 21 24 +27 26 23 22 19 18 +70 67 64 62 60 57 55 +96 94 91 90 88 86 +63 66 67 70 73 +5 8 11 14 16 19 21 22 +83 85 86 88 91 92 +40 39 36 35 34 +73 75 77 78 81 83 +50 49 47 46 44 41 38 35 +73 76 79 81 83 86 88 90 +15 16 18 20 21 +85 87 88 89 91 +71 73 75 76 77 79 80 83 +28 25 22 21 20 +15 17 19 20 21 24 25 +40 39 37 34 31 30 27 25 +90 87 86 83 81 78 76 75 +32 31 28 25 24 21 18 +9 11 14 16 18 +9 10 11 14 16 19 21 22 +14 13 12 10 9 7 6 +53 50 48 46 43 42 +51 54 56 59 61 63 66 68 +39 41 43 44 47 50 53 +77 75 74 73 72 70 68 +40 43 46 48 50 52 54 +44 46 49 50 53 55 58 59 +13 14 15 18 20 21 24 +13 16 18 20 23 25 +16 19 20 23 26 +34 35 36 38 41 43 +62 59 58 56 55 53 52 +14 13 10 8 5 4 2 +14 13 12 9 6 4 +25 23 21 19 16 15 +64 63 60 57 55 53 50 48 +51 53 54 55 56 58 60 +74 72 69 66 64 63 61 58 +6 9 11 14 15 18 19 +69 72 73 76 78 79 +47 45 43 41 39 +30 28 26 23 20 19 17 +11 9 7 6 5 2 1 +53 51 50 49 48 45 +56 58 59 60 63 65 67 +88 85 84 81 79 78 77 +90 87 85 84 81 80 77 +49 46 45 42 40 37 36 +26 24 23 22 20 18 +45 43 42 41 38 +66 68 69 72 75 +25 24 21 20 17 14 +50 52 55 56 57 59 60 63 +15 14 13 10 9 6 +47 46 44 42 41 39 +75 77 79 80 83 85 86 88 +13 10 7 4 3 +95 92 89 87 84 81 +88 89 91 94 95 97 99 +79 76 74 71 68 66 65 +83 85 86 87 89 90 92 +44 45 46 48 51 +20 17 16 14 12 +59 60 63 65 67 70 72 75 +11 12 13 14 16 18 +63 60 59 57 55 53 51 +39 36 34 33 31 30 27 24 +61 59 58 56 53 +34 31 29 27 24 +66 67 68 70 73 74 77 +88 90 91 93 96 97 98 +58 59 61 64 65 68 71 +19 16 15 14 11 10 +34 31 28 25 23 21 18 16 +9 12 15 16 19 22 +11 13 16 19 20 23 24 +97 96 95 94 93 92 89 +33 30 29 28 26 +2 3 4 5 7 8 +57 60 61 64 67 +23 25 27 29 31 34 37 38 +70 67 65 64 61 +80 79 78 77 75 72 +43 40 38 37 34 +56 58 59 61 62 64 +54 57 58 60 62 64 67 69 +36 33 30 27 26 25 +48 50 53 56 59 62 63 +61 59 58 57 55 53 +81 82 83 85 86 89 92 +37 40 43 45 47 49 51 +99 97 95 92 89 +30 32 35 37 38 +52 53 54 57 59 60 61 62 +58 56 53 51 50 +30 29 26 25 24 +16 15 13 11 8 6 +26 23 21 20 19 18 +72 71 68 67 66 63 60 +18 15 13 12 9 6 +70 69 68 67 66 65 +64 66 68 71 72 74 76 +47 45 43 40 38 +9 12 13 14 15 17 19 20 +50 52 54 55 57 59 62 65 +17 15 14 12 10 +26 25 23 22 20 18 16 15 +82 80 78 77 75 +96 95 93 92 89 +22 23 25 28 29 32 33 35 +35 37 40 42 44 47 50 +74 73 70 69 67 64 +19 17 14 12 11 8 5 3 +62 64 67 68 70 +69 71 73 74 76 78 +7 8 9 10 13 14 +84 82 80 78 76 75 72 +18 21 24 25 26 +54 56 57 60 62 64 65 +62 63 66 68 70 73 diff --git a/inputs/day3.txt b/inputs/day3.txt new file mode 100644 index 0000000..024e5b3 --- /dev/null +++ b/inputs/day3.txt @@ -0,0 +1,6 @@ +'{}mul(339,896)>^+!)^mul(799,303)don't()>mul(188,763)'<};who()select()%;+mul(924,355)mul(492,757) what()mul(582,171)][*+select()#mul(840,899){!when()from()%where()mul(318,527)} :!-'mul(530,886)?}>mul(937,475) $;),%:}mul(201,723)where()select()mul(673,729)why()who()^'who()mul(673,694)[+mul(295,161)[!how(88,740)*mul(364,904)how()<]when()+where()mul(329,432)when()mul(499,11)who(238,444))#~mul(775,866);,[)':where()%{[mul(835,890)+&&select()&[when()why(783,259) select()mul(735,871)!)when()'what()[/:mul(952,728)mul(633,505)@ -(?mul(176,469)*%what()>what()who()@{+do()'mul(117,634)-?(^^%:mul(234,514)where()@%mul(291,507)#from()*!*mul(668,282)@&)>,:select()>{%mul(195,300)-why()select()+&~>/^from()mul(801,834)why()~mul(463,630){*, from()$}:@mul(280,83)when()[mul(358,910)[;'why()where()mul(242,569)from()#<>from()&mul(553,455)%who())mul(284,63)%%*+?mul(437,226)* }how()when()~%'mul(57,491)]select(918,666)where()$when()why()'from()?]mul(321,301)'~:mul(619,356):mul(78,106)what()}!+~mul(609,442); $where()$who()mul(996,918)mul(217,653)@##:#mul(998,408))~<#where()from()who()who()what()(mul(305,980)-~(:>where();when()#mul(721,412)how()'< { mul(143,735){:]why(){#),@mul(670,301)$when(),}why()]?why(839,544)mul(120,681){when()$[?@-)mul(805,510)>from()))when();?'#mul(104,633)%<$%}why()mul(555,387)@$+mul(850,237)!^where()<}from()select()from()<@mul(298,559)who():from()+what();mul(556,540)$%<&(%don't()$/':'*)(mul(976,624)!~*/%why()mul(790,645):~^from()[{+*!mul(153,86)+select(){#!from()how()$mul(980,956)>from()select()}<}@}?~mul(151,20)select()mul(703*(){+]who()what()mul(827,322)+](}mul(531,132what()where()+mul(933,2){&$how()%#;]don't())[]mul(845,519)how(),]when()^mul(518,563)#,++$#mul(500,591)(#/what()where()how()from()mul(243,908);mul(574,691)/who(),who()how()&mul#{where()when()]!@mul(534,43)}do(),}/from()when()~{&@mul(92%what()~}mul(496,669)^(!+ ^~mul(28,334)mul(621,688)]mul(627,561))mul(206,37)]~^&mul(288,740,<@mul(540,77)<&:who(594,229)&'*who(){mul(923,453)mul(733,228)where()how()mul(104,17)/!why()~what()*@}mul(500,830)#'(&%{select()*?mul(301,211)]>@@,mul(21,358) ?mul(285,542)how()from())mul(361,19)(who()%}select(){*mul(362,324)<[]'&when()'mul,why()mul(352,273)mul(742,91)>mul(624,723)) ;@+mul(14,149)(from()%%,(mul(547,492)~+mul(712?@@@&{{mul(972,531) +]&%where()~}who()[how()]mul(602,51)how()+&>,{>] #do()from()~{,*[-mul(862,742)how()why()]%mul(432,72)what(){:do()%@!}-mul(663/+,what()--(&?mul(384,302)'@(mul(649,348)+from()%mul(184,596)~+}~mul(719,53)mul(634,179){-:where()mul(684,320where()when(395,300){who()how()^/;where()mul(849,756)!mul(530,108)#*+}what()^(]select()mul(333,615)[why()%?]~$how()mul(314,366)}where()mul(222,364)<){*[mul(449,95){:who(844,554)<;why()$who() mul(831,201))$mul(408,650)who()what()}<[do()~how()select()!]'why()]how(289,983)* <+%&mul(836,460)%mul(339,868)why():from()from()%mul(91,296)!+^,*when()who()from()-$mul(6,37)when()when()mul(69,574)who(),from(),how()mul(431,678~+how()]mul(644,184)-(?why(571,97)])why()from()mul(516>select()mul(67,86)+~%^!~what();mul(526,440)!+>?<:&mul(81,534)&}'mul(64,25)[-;mul(828$<>*mul(157,667)@[ *who()mul(356,285)select()(~*do()how()';why()&^?mul(165,944)select()mul(980,979)<:!~%mul(15why()$ mul(109,665)&-!why()]<'&mul(887,673)]mul(906,700)#mul}@-where()/{{ -mul(935,960),)''[{mul(533,431)what())'@mul(63,509)@why(464,997)$]mul(164,971)select()~where()how()#>' when()>mul(301,62) +;'+what()}!->mul(722,492))!'mul(262,457):@when()-/mul(902,705)~#(mul(640,550)/*$$#select()where(905,349)!&&don't()when()mul(998,104)select()from()select()'when()mul(37,27)!where()$:do()}mul(160,45)mul(716,642~,{+&+!}[}mul(281,768)who()-?;);%mul(270,620) mul(793from()(![(! : who()mul(481,293)?mul(264,360)where(){from();(select()~!from()mul(748,940)[~]why()$[+how(709,453)mul(590&!+*why()]when()mul(182,631)(how()?(select():;&]{mul(83,366)%when()when()&mul(878,366)why()[:,]mul(77,997);%/$&%]mul(827,204)mul(919,654)>,where()%+mul(678,952)who()@select()}*(mul(344,894)where()mul(408,29)#*!{}*~where(906,182)mul(144,162)!&#select()how()&why()~*#don't()-()]~:how()mul(803,649)]@?#;mul(170,978)mul(263,974)!@why()$how()@mul(155,265)&/%^/mul(571,825)$where()mul(507,171)from()^(~*mul(437,680)from()who()>select()}mul(332,921) where()mul(218,74)})from()/mul(470,570)why()@?who()don't()@({*mul(931,767)mul(486,567):&])%/{]%mul(901,942),' ]why()^where()do(){#,what()mul(331,184)how()when()how()*{:^){mul(339,48){'(what(545,390)mul(818,891)who()mul(828,226), how()where()'#,%?mul(798,324))';mul(337,760)[#mul(350,889)~#how()mul(859,480){}^?&select()where()do()~); who()^mul(640,455}why()#mul(744,51)'[who()/> select()mul^where()select()^}^mul(450,596))select()what()}&%;?mul(218,957)+*who(),}do()from()^} when()+[select(938,490))select()mul(406{how()(+who()()select()mul(329,937)&!mul(693,766)<{+}<[@mul)]%why()when()){~[ who()mul(888,144)~$:,mul(517,97)@) ~mul(394,320)why()when()who()(,%mul(761,855) +mul(22,362)('from(886,421)]mul(730,655)[@,how()(mul(692,165)]&$when()!}from()%mul(481,375)where()~mul(954,570)?why()-+mul(338,656)who()~ <}from()mul(616,31)where()/]:select())?from()mul(113,2):?$mul(295,905)];mul(410,181)@%${^how()>select()where()-mul(779>+what();^who(),>)mul(599,200)%~][select()>+>mul(486,481)*!who(693,495)-$mul(237,686)? how()! -@#do()#<(where()-&'>&what()mul(321,434)}@what()~/from()do()?who()$where()mul(328,792)select()how()mul(82,296)#,who())/when(637,168)mul(465,709)mul(208,775)^[@when()>>##<>mul(379,29)%mul(826,43){when()?who()*why()do()&[):@mul(411,966)^mul(24,557)<;where()mul(391,794)#;mul(592,819)+,}'%'mul(210,928)%mul(29,613);$who()why()!]who()mul(56,646)*@]-{~+:mul(425,457)>mul(896,578)%(how()](*where()when()select(237,23)mul(895,482)~<{mul(432,547)who(471,124){mul(483,785)*mul(422,876)^>& ;(^where()~#mul(709,114)(:;where()select()?%mul(263,276)&?;from()&&~(mul(113,694)who()mul(228,70): >[:@ ;@mul(707,104);:mul(423,229)&$[]>who()mul(194,895)><&&when()%%mul(836,144)<^!~)/;#who()>mul(786,723)?!#[mul(287;why()mul(734,761)!who()/<)mul(520,746)where(){!>>select()how()mul(185,986)mul(566,786)why()when()[~do(),}mul(188,610)/+^%-how()[mul(671,105)*[}[mul(403,996)mul(214+($?{when()mul(268,651),[>mul(660,864)%-/how()->([~mul(769,53)?from(197,675)^[-mul(83,519)where()select()don't()[:from()@{who() ?mul(305,335)[when()when();where(751,621)what()mul(395,86)how()?,who():>mul(349,362)how()?*select()when()from()who()where()''mul(414,725)*)when()select()]+mul(180,197)$who()why()&%'}mul(531who()#{mul(370,295)who()%mul(121,586)*^^%?>{,when()mul(944,189)&[/)select()>&^mul(222,28)@!where()'mul(449,827)^[mul(289,78)$how(287,947)mul(337,811)why()''-what()[/when(370,472)from()>mul(865,636){#mul(524,198)why(714,875)!*%mul(181,23)^)why()?:what(630,704)+}mul(569,165);when()')where(597,70):$where()why(),mul(15,411)* ) &don't()mul(124,709)$;/[+select()({mul(50,277))*;+*<#do()!@mul~mul(19,630),,,*+{mul(404,379)mul(72,663)when()don't()where(221,302)from()^>mul(942,445)+^from()]from()*{)mul(83,601)-+what(): where()what()from(),mulwhy()where(856,731)&/+mul(777,574)!+when()don't()*^mul(680,66)how()$mul(361,449):,how(766,248)#}&}[mul(869,603);;where()what()mul(385,816)[!' <-~from();mul(298,605*from()^mul(573,375)when()@(where()%mul(871,907)mul(718,918)?mul/~ ~what()-!select()~do()why():mul(682why()]mul(585,886)(,?+*?%!mul(684,834)what(786,470)mul(443,590))where(228,285) !/%?mul(815,879)#!/usr/bin/perl@mul(444,941)$select(687,764)%'(where()>-/mul(180,328) +[/:@how()*what()!+mul(911,368)?/what()~(+]mul(843?$,who()mul(865,234)@]/-from()mul(397,906)^mul(806,349)]how()where()^)+%select()when()~mul(827,131)]don't()@+/mul(44,818)[,<,mul(295,441)what()/select()]^mul(756,90) [mul(67,416){mul(230,994)select()how()who()/mul(66,226);<~!when()mul(325,467),mul(6,370)mul(619,21)~mul(699,668))^:mul(755,644)<%?#)mul(46,923!mul(730,880)]~]how()-why()'&mul(952,543)from()>!-mul(123,880){(mul(555,437)*mul(692,73)&*when()~>mul(465,602)(mul(471,204){%from();don't()$mul(945,735)from()select(520,626)>@who()]who()mul(615,73)):(;^^when(793,925)*&do(){mul(431,683)*+#select()where()from()?+mul(254,617)#%where()>;%don't()$who()#how()^[how()why()*mul(907where()select()(!:'!?@mul(208,995)}/:when()how(415,229)^-'from()mul;mul(22,79),']^?(mul(583,536):mul(355/-where()?~%,mul(990,358)//+&how() do()?who()%!}]mul(603,599)@mul(285,652){&@@mul(808,857when()when()%select()/'$@mul(585,541)from()@mul(136*#from()@mul(710,522) #*when()*}/mul(801,485) >/mul(393,477)where()(mul(13,599)what()when()(*%>@?];mul(808,562)>mul(407,85)mul(244/$&!+where()mul(67,663)-mul(934,570)]mul(857,473)who()mul(585,495)where()mul(45,904)!when()where())-:mul(747,283)why()#where();what()how(){'from()mul(405,574)[,?what()why()-([mul}where()select(450,140) /@who():@who(),>~mul(104,734)$]#-#who()mul(760,886)what()&where(352,510)->(don't()mul(863,264)$<)where()*/(@'mul(756,795)^)]mul(278,155):&!%$select()mul(189,750)[$#-/mul(549,580))^how(152,70):$mul(28,530)-],;]mul(33,157);!/+?what(253,786)%what()mul(841,40)+&when()why()^mul(898,936)!])mul(891,523);>mul(312,16)@how()*where()'where()<@?mul(967,420)/}why()~,mul(581,636)/ [mul(673,139)who()>mul(578,980):,%mul(75,107)+)how()-mul:/where()why()mul(315,687)!{%'what()mul(110,111)+ #:%!mul(731,760) +(+&mul(887,468)$::)],mul(765,973)'from()from()*mul(810,344)?what()mul(768,468)~'+)select()where()(select()where()$mul(576,358)%??'mul(41,789how()when()&-mul(606,191)!when()'~mul]]how():;~{how()mul(15,34)>%%*^how(54,122)$@mul(739,223)how()~*@!don't()]:{~'@>why()-]&how() **;}mul(900,428)select()]$'mul(874,363)what()@mul(892,45)^*+mul(387,178)?mul(823,845){where()mul(854,982);;/how()-why()mul(899,363)[where()who()what()>$]['do()<'how())mul(201,507)select(): >select()select()what()/where()*do()}@when(392,773)?mul(231,610){- why()*from()when():select():mul(334,751)from()how()~+who()-mul(811,647){^mul(116,805)^where()@}mul(691,631) when()&%from(),@^mul(336,461) ,what())who()when(540,382)'mul(549,430)%]from())@mul(339,808)?mul(264,497)'when()what()~who()~@how()$+mul(965,916)('who())%~from()from()%mul(776,506)/select()mul(385,184)*##select()mul(691,451)]$$mul(303,437);!when()&/<>]^mul(524,315)#^)mul(42,992who()}&-select()mul(902,182)(!''where()'+mul(48,755)@~what(644,7)$select()&%who()-mul(629,650)!^mul(822,985){/select()why()where()!who()%%mul(102,630)why()-{don't(),mul(166,527)'where()mul(245,921)select()-select()mul~>select()'%who()<+,mul(795,941))%$,what()where()>mul(414,585)from(26,999){mul(293,208)when()?#?mul(99,672)why()(select()+]when()mul(300,836)[}where()/mul(425,328))mul(702,532)?#(mul(45,856) ]/$mul(220,616)^when(){^* ?where():,mul(931,398)$;-mul(471,783)why(){:who()what()]>mul(276,590)select()when() /$(^<'mul+*&do()&)>;mul(785,175)mul(131,573),]from():(mul(833,970)! ><<(mul(496,285)&from()~select(){mul(296,374)?[#&from()from(){{when() mul(718,993)@who()&>mul(639,708)why()where()/-<{[ how()&mul(187,633)#:]:?mul(872,562)/who()[-who()(>$%}don't()!{:*mul(82,739)select()]+ ?$?@when()mul(830,429)+;:$>mul(390,30)(&@%&'} {%mul(208,444)mul(854,207);:@where(774,785)mul(120,222)mul(885,372)$ '<[mul(476,77)select()from()mul(305,758)}#[>;,@where()~how()(why(){mul(2,348)%@(~}how():mul(148,153)where()^:'why(907,374)+]mul(375,986);{]where()(!@what()]:mul(254,345))*)where()select()@?^#what()mul(94?what()!@when()select(),$?select()mul(966,420)select()/+{[;!(>what()mul(688,942)&]'^)'#!mul(363,573):$,from()select()mul(260,171)#mul(116,728)'(?mul(51,309)[!^mul(400,128))select()$-^how(740,875)where()@from()mul(319,269)select(844,13)who()#/mul(431,542)mul(794,709)- who()*do()*:)select()mul(12,579)@%])[what()&/mul(361,146)why()>:'-^&;mul(465,576))select()@%mul(101,476)who()%}' [#mul(13,38);:how()from()from()#}#&-mul(30,350)what()/+select()+]don't()!#:@;,[when()mul(303,869)when()where()]/'^!^ mul(938,614) {who()?!what(363,886)mul(439,873)>who()what()-+when()where()[why()mul?from()what()> where()who()!mul(510,226) {how()mul(353,498)]select()why()?[why()'*}(mul(709,649)~?select()*($>[from()mul(144,790)!%!mul(653,286)[<$)*+from()what(),from()mul(373,21))] select()?;+mul(601,965)what(), ,:mul(970,654)~why()(~*<+&mul(19,700)what()$what() <{({,)'how()-@mul(629,950)how()when()who()what(623,556)mul(891,30)(!don't()>who()who()%+ [)when()mul(808,962)+?<({~$#+do()}what()how()(what()*-@mul(296,108)>]^+&mul(592,463)~['%%& mul(733,447),#how()where()select()how()who()>mul(496,360)(&%*{+what()!mul(615,52)#&*,mul(807,92)&]mul(544,513){/+who(868,321)from()mul(164,401)how()][%what()where()(+[>mul(815,703)from()(when(),*select() {what()mul(437,310)who(226,447)mul(45,389)#&who()*[mul(659,114))what()#:+[%mul(686,605)<',,{who()^@-mul(127,293)& ;@mul(608,869)?%+*select(74,799)who()when()/^select()don't()where()$why()>why()when()%mul(752,203)-}'{^#;[%^mul(307,633)%when(970,30)mul(265,251)what(42,790)#mul(188,777)<:*& when():/when()?mul(94,809)mul(621,327)+;/*,,[select();~do()^(when()mul(896,407),$mul(280,745)*:){^~:({where(796,413)mul(262,847)why()&& Result<(), io::Error> { + let input = load_file("day1.txt")?; + println!("Day 1 part 1: {}", part1(&input)); + println!("Day 1 part 2: {}", part2(&input)); + Ok(()) +} + +fn part1(input: &str) -> u32 { + let (mut left_side, mut right_side) = create_vecs(input); + left_side.sort(); + right_side.sort(); + left_side.into_iter().zip(right_side) + .map(|(x, y)| (x as i64 - y as i64).unsigned_abs() as u32).sum() +} + +fn part2(input: &str) -> u32 { + let (left_side, right_side) = create_vecs(input); + left_side.into_iter().map(|num| num * right_side.iter() + .filter(|&&x| x == num).count() as u32).sum() +} + +fn create_vecs(input: &str) -> (Vec, Vec) { + let mut left_side = vec![]; + let mut right_side = vec![]; + let split: Vec<(u32, u32)> = input.split("\n").filter(|l| !l.is_empty()).map(|line| { + let mut line_iter = line.split_whitespace(); + let first_number: u32 = line_iter.next().unwrap().trim().parse().unwrap(); + let second_number: u32 = line_iter.next().unwrap().trim().parse().unwrap(); + (first_number, second_number) + }).collect(); + for (x, y) in split { + left_side.push(x); + right_side.push(y); + } + (left_side, right_side) +} + +#[cfg(test)] +mod tests { + use super::*; + const TEST_INPUT: &str = r#"3 4 +4 3 +2 5 +1 3 +3 9 +3 3"#; + #[test] + fn test_part_1() { + assert_eq!(part1(TEST_INPUT), 11); + } + #[test] + fn test_part_2() { + assert_eq!(part2(TEST_INPUT), 31); + } + +} diff --git a/src/solutions/day2.rs b/src/solutions/day2.rs new file mode 100644 index 0000000..3ddff96 --- /dev/null +++ b/src/solutions/day2.rs @@ -0,0 +1,73 @@ +use aoc24::utils::load_file; +use std::{io, usize}; +pub fn run() -> Result<(), io::Error> { + let input = load_file("day2.txt")?; + println!("Day 2 part 1: {}", part1(&input)); + println!("Day 2 part 2: {}", part2(&input)); + Ok(()) +} + +fn part1(input: &str) -> u32 { + let lines = parse_lines(input); + lines.into_iter().filter(|l| check_safety(l)).count() as u32 +} + +fn part2(input: &str) -> u32 { + let lines = parse_lines(input); + lines.into_iter().filter(|l| { + let sublists = generate_sublists(l); + sublists.iter().any(|e| check_safety(e)) + }).count() as u32 +} + +fn check_safety(vec: &[usize]) -> bool { + if vec.is_sorted() || is_descending(vec) { + vec.windows(2).all(|w| { + let abs = (w[0] as i16 - w[1] as i16).abs(); + abs < 4 && abs > 0 + }) + } else { + false + } +} + +fn is_descending(vec: &[usize]) -> bool { + vec.windows(2).all(|w| w[0] > w[1]) +} + +fn generate_sublists(vec: &[usize]) -> Vec> { + let mut sublists = Vec::with_capacity(vec.len()); + for i in 0..vec.len() { + let mut sublist = vec.to_vec(); + sublist.remove(i); + sublists.push(sublist); + } + sublists +} + +fn parse_lines(input: &str) -> Vec> { + input + .split("\n") + .filter(|l| !l.is_empty()) + .map(|line| line.split(" ").map(|x| x.parse().unwrap()).collect()) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + const TEST_INPUT: &str = r#"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"#; + #[test] + fn test_part_1() { + assert_eq!(part1(TEST_INPUT), 2); + } + #[test] + fn test_part_2() { + assert_eq!(part2(TEST_INPUT), 4); + } +} diff --git a/src/solutions/day3.rs b/src/solutions/day3.rs new file mode 100644 index 0000000..36af171 --- /dev/null +++ b/src/solutions/day3.rs @@ -0,0 +1,56 @@ + +use aoc24::utils::load_file; +use std::{io}; +use regex::Regex; + + +pub fn run() -> Result<(), io::Error> { + let input = load_file("day3.txt")?; + println!("Day 3 part 1: {}", part1(&input)); + println!("Day 3 part 2: {}", part2(&input)); + Ok(()) +} + +fn part1(input: &str) -> u32 { + let re = Regex::new(r"mul\((\d+),(\d+)\)").unwrap(); + let mut result = 0; + for (_, [x, y]) in re.captures_iter(input).map(|c| c.extract()) { + result += x.parse::().unwrap() * y.parse::().unwrap(); + } + result +} + +fn part2(input: &str) -> u32 { +let re = Regex::new(r"mul\((\d+),(\d+)\)|do\(\)|don't\(\)").unwrap(); + let mut enabled = true; + + let mut results = Vec::new(); + for cap in re.captures_iter(input) { + if &cap[0] == "do()" { + enabled = true; + } else if &cap[0] == "don't()" { + enabled = false; + } else if enabled { + let first: u32 = cap[1].parse().unwrap(); + let second: u32 = cap[2].parse().unwrap(); + results.push((first, second)); + } + } + + results.iter().map(|(a, b)| a * b).sum() +} + +#[cfg(test)] +mod tests { + use super::*; + const TEST_INPUT: &str = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"; + const TEST_INPUT_2: &str = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))"; + #[test] + fn test_part_1() { + assert_eq!(part1(TEST_INPUT), 161); + } + #[test] + fn test_part_2() { + assert_eq!(part2(TEST_INPUT_2), 48); + } +} diff --git a/src/solutions/mod.rs b/src/solutions/mod.rs new file mode 100644 index 0000000..4e7d712 --- /dev/null +++ b/src/solutions/mod.rs @@ -0,0 +1,3 @@ +pub mod day1; +pub mod day2; +pub mod day3; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..1857af3 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,6 @@ +use std::fs; +use std::io; +pub fn load_file(name: &str) -> io::Result { + let path = "./inputs/".to_owned() + name; + fs::read_to_string(path) +}