From 5dffb6f92908d32e80cf1bc68b40534bfbd7af1c Mon Sep 17 00:00:00 2001 From: JonOfUs Date: Fri, 6 Dec 2024 12:11:29 +0100 Subject: [PATCH] d05 --- res/05/example | 28 + res/05/input | 1371 +++++++++++++++++++++++++++++++++++++++++++++++ src/days/d05.rs | 82 +++ src/main.rs | 2 +- 4 files changed, 1482 insertions(+), 1 deletion(-) create mode 100644 res/05/example create mode 100644 res/05/input create mode 100644 src/days/d05.rs diff --git a/res/05/example b/res/05/example new file mode 100644 index 0000000..9d146d6 --- /dev/null +++ b/res/05/example @@ -0,0 +1,28 @@ +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 diff --git a/res/05/input b/res/05/input new file mode 100644 index 0000000..b5c38bd --- /dev/null +++ b/res/05/input @@ -0,0 +1,1371 @@ +75|21 +28|29 +28|73 +95|48 +95|19 +95|16 +81|51 +81|95 +81|16 +81|56 +48|59 +48|83 +48|64 +48|57 +48|86 +15|43 +15|82 +15|49 +15|31 +15|35 +15|48 +83|68 +83|26 +83|56 +83|63 +83|64 +83|69 +83|84 +47|83 +47|29 +47|23 +47|18 +47|87 +47|53 +47|79 +47|59 +35|43 +35|34 +35|85 +35|28 +35|64 +35|94 +35|48 +35|79 +35|78 +34|65 +34|88 +34|87 +34|82 +34|45 +34|76 +34|47 +34|39 +34|49 +34|85 +92|15 +92|35 +92|59 +92|69 +92|34 +92|67 +92|26 +92|18 +92|73 +92|84 +92|19 +94|47 +94|83 +94|82 +94|85 +94|57 +94|48 +94|64 +94|28 +94|43 +94|76 +94|49 +94|88 +29|59 +29|51 +29|15 +29|73 +29|89 +29|66 +29|76 +29|75 +29|63 +29|53 +29|18 +29|62 +29|95 +69|94 +69|56 +69|66 +69|43 +69|85 +69|63 +69|82 +69|57 +69|78 +69|15 +69|34 +69|31 +69|35 +69|16 +63|78 +63|65 +63|43 +63|27 +63|66 +63|23 +63|62 +63|35 +63|34 +63|48 +63|56 +63|19 +63|94 +63|85 +63|57 +31|92 +31|28 +31|53 +31|49 +31|64 +31|59 +31|26 +31|47 +31|23 +31|76 +31|89 +31|79 +31|81 +31|83 +31|86 +31|45 +56|86 +56|43 +56|65 +56|57 +56|82 +56|47 +56|85 +56|48 +56|62 +56|31 +56|78 +56|35 +56|16 +56|87 +56|23 +56|95 +56|34 +23|76 +23|29 +23|39 +23|53 +23|45 +23|26 +23|27 +23|28 +23|79 +23|21 +23|84 +23|83 +23|73 +23|86 +23|81 +23|59 +23|68 +23|89 +65|53 +65|48 +65|87 +65|88 +65|27 +65|28 +65|49 +65|45 +65|82 +65|43 +65|29 +65|39 +65|76 +65|85 +65|64 +65|23 +65|31 +65|79 +65|92 +45|68 +45|59 +45|69 +45|73 +45|53 +45|21 +45|81 +45|62 +45|56 +45|15 +45|95 +45|35 +45|63 +45|51 +45|26 +45|19 +45|92 +45|66 +45|89 +45|78 +76|73 +76|51 +76|18 +76|75 +76|95 +76|66 +76|56 +76|69 +76|81 +76|21 +76|67 +76|26 +76|53 +76|92 +76|89 +76|35 +76|63 +76|19 +76|62 +76|59 +76|45 +53|92 +53|21 +53|18 +53|94 +53|67 +53|68 +53|69 +53|63 +53|66 +53|84 +53|34 +53|59 +53|89 +53|73 +53|78 +53|81 +53|19 +53|35 +53|26 +53|56 +53|15 +53|51 +51|47 +51|15 +51|69 +51|65 +51|94 +51|66 +51|31 +51|95 +51|43 +51|35 +51|78 +51|82 +51|85 +51|48 +51|23 +51|63 +51|34 +51|16 +51|88 +51|67 +51|62 +51|19 +51|56 +79|84 +79|28 +79|69 +79|45 +79|92 +79|83 +79|29 +79|53 +79|64 +79|76 +79|89 +79|51 +79|68 +79|39 +79|26 +79|81 +79|21 +79|63 +79|62 +79|59 +79|75 +79|56 +79|73 +79|18 +19|35 +19|48 +19|82 +19|94 +19|57 +19|78 +19|43 +19|79 +19|83 +19|31 +19|64 +19|23 +19|47 +19|67 +19|28 +19|85 +19|27 +19|86 +19|34 +19|65 +19|87 +19|88 +19|16 +19|49 +82|27 +82|68 +82|83 +82|39 +82|28 +82|73 +82|92 +82|49 +82|75 +82|89 +82|31 +82|45 +82|47 +82|18 +82|87 +82|53 +82|79 +82|23 +82|86 +82|81 +82|29 +82|59 +82|64 +82|76 +21|34 +21|19 +21|78 +21|57 +21|82 +21|51 +21|66 +21|35 +21|95 +21|62 +21|48 +21|84 +21|65 +21|69 +21|31 +21|56 +21|15 +21|67 +21|85 +21|16 +21|88 +21|94 +21|63 +21|43 +88|27 +88|29 +88|64 +88|75 +88|31 +88|59 +88|76 +88|39 +88|47 +88|28 +88|87 +88|23 +88|83 +88|81 +88|53 +88|86 +88|45 +88|18 +88|92 +88|79 +88|49 +88|57 +88|82 +88|89 +86|18 +86|28 +86|73 +86|75 +86|59 +86|26 +86|21 +86|69 +86|76 +86|79 +86|51 +86|92 +86|45 +86|83 +86|64 +86|49 +86|81 +86|68 +86|39 +86|53 +86|29 +86|84 +86|63 +86|89 +43|59 +43|64 +43|87 +43|47 +43|49 +43|57 +43|31 +43|86 +43|39 +43|27 +43|53 +43|88 +43|83 +43|89 +43|81 +43|79 +43|75 +43|82 +43|23 +43|76 +43|29 +43|28 +43|92 +43|45 +26|15 +26|82 +26|78 +26|67 +26|57 +26|88 +26|35 +26|43 +26|85 +26|21 +26|48 +26|84 +26|69 +26|62 +26|34 +26|19 +26|66 +26|65 +26|51 +26|16 +26|95 +26|94 +26|63 +26|56 +68|85 +68|65 +68|95 +68|35 +68|78 +68|67 +68|57 +68|51 +68|62 +68|56 +68|34 +68|21 +68|63 +68|88 +68|15 +68|48 +68|43 +68|26 +68|66 +68|84 +68|94 +68|19 +68|69 +68|16 +85|64 +85|27 +85|82 +85|43 +85|53 +85|48 +85|57 +85|86 +85|88 +85|29 +85|47 +85|87 +85|83 +85|75 +85|76 +85|28 +85|81 +85|49 +85|45 +85|39 +85|92 +85|31 +85|23 +85|79 +39|84 +39|76 +39|59 +39|67 +39|62 +39|92 +39|81 +39|69 +39|66 +39|26 +39|15 +39|75 +39|95 +39|63 +39|21 +39|73 +39|45 +39|51 +39|89 +39|53 +39|56 +39|68 +39|19 +39|18 +78|48 +78|87 +78|34 +78|29 +78|28 +78|79 +78|76 +78|43 +78|39 +78|85 +78|88 +78|49 +78|27 +78|86 +78|94 +78|64 +78|31 +78|83 +78|82 +78|16 +78|23 +78|47 +78|65 +78|57 +87|83 +87|26 +87|51 +87|29 +87|79 +87|45 +87|68 +87|75 +87|73 +87|21 +87|53 +87|81 +87|84 +87|39 +87|89 +87|92 +87|76 +87|59 +87|18 +87|86 +87|69 +87|49 +87|64 +87|28 +18|69 +18|95 +18|73 +18|16 +18|48 +18|21 +18|68 +18|85 +18|62 +18|34 +18|19 +18|65 +18|15 +18|94 +18|63 +18|51 +18|66 +18|84 +18|67 +18|43 +18|35 +18|26 +18|56 +18|78 +84|95 +84|62 +84|48 +84|35 +84|57 +84|31 +84|16 +84|78 +84|65 +84|88 +84|67 +84|34 +84|19 +84|43 +84|69 +84|15 +84|94 +84|63 +84|51 +84|66 +84|47 +84|56 +84|85 +84|82 +59|34 +59|69 +59|89 +59|19 +59|62 +59|84 +59|68 +59|73 +59|26 +59|66 +59|94 +59|67 +59|21 +59|85 +59|18 +59|95 +59|16 +59|15 +59|63 +59|56 +59|35 +59|51 +59|78 +59|65 +67|88 +67|27 +67|16 +67|28 +67|79 +67|64 +67|65 +67|29 +67|47 +67|83 +67|34 +67|48 +67|49 +67|43 +67|94 +67|23 +67|85 +67|35 +67|31 +67|82 +67|57 +67|87 +67|86 +67|78 +73|15 +73|88 +73|16 +73|69 +73|19 +73|34 +73|78 +73|95 +73|67 +73|26 +73|56 +73|66 +73|62 +73|94 +73|68 +73|21 +73|63 +73|65 +73|85 +73|43 +73|35 +73|51 +73|48 +73|84 +57|49 +57|75 +57|79 +57|45 +57|82 +57|23 +57|89 +57|29 +57|47 +57|59 +57|39 +57|28 +57|81 +57|83 +57|64 +57|87 +57|18 +57|53 +57|86 +57|76 +57|92 +57|27 +57|31 +57|73 +64|81 +64|69 +64|84 +64|95 +64|18 +64|29 +64|76 +64|75 +64|73 +64|56 +64|39 +64|15 +64|89 +64|68 +64|59 +64|45 +64|92 +64|62 +64|51 +64|63 +64|66 +64|21 +64|53 +64|26 +16|48 +16|29 +16|79 +16|47 +16|43 +16|49 +16|45 +16|87 +16|53 +16|83 +16|88 +16|28 +16|64 +16|75 +16|27 +16|86 +16|57 +16|76 +16|85 +16|23 +16|65 +16|39 +16|82 +16|31 +89|21 +89|16 +89|85 +89|69 +89|19 +89|63 +89|48 +89|18 +89|68 +89|73 +89|35 +89|84 +89|51 +89|65 +89|15 +89|94 +89|26 +89|78 +89|62 +89|95 +89|34 +89|66 +89|56 +89|67 +49|21 +49|59 +49|18 +49|69 +49|83 +49|56 +49|92 +49|81 +49|29 +49|39 +49|51 +49|75 +49|63 +49|53 +49|89 +49|79 +49|45 +49|73 +49|64 +49|28 +49|84 +49|68 +49|26 +49|76 +27|86 +27|29 +27|64 +27|18 +27|79 +27|49 +27|92 +27|76 +27|73 +27|83 +27|87 +27|39 +27|53 +27|51 +27|68 +27|75 +27|28 +27|81 +27|45 +27|59 +27|89 +27|84 +27|21 +27|26 +62|31 +62|85 +62|94 +62|87 +62|88 +62|82 +62|43 +62|67 +62|66 +62|34 +62|16 +62|47 +62|78 +62|86 +62|95 +62|23 +62|49 +62|65 +62|57 +62|35 +62|15 +62|19 +62|48 +62|27 +66|86 +66|85 +66|94 +66|95 +66|82 +66|27 +66|47 +66|35 +66|79 +66|31 +66|65 +66|49 +66|87 +66|88 +66|19 +66|23 +66|67 +66|57 +66|78 +66|83 +66|48 +66|34 +66|43 +66|16 +75|78 +75|92 +75|67 +75|89 +75|35 +75|73 +75|69 +75|95 +75|56 +75|84 +75|81 +75|62 +75|68 +75|19 +75|34 +75|66 +75|63 +75|15 +75|18 +75|26 +75|59 +75|53 +75|51 +28|69 +28|18 +28|26 +28|84 +28|59 +28|45 +28|56 +28|21 +28|63 +28|51 +28|53 +28|66 +28|81 +28|75 +28|89 +28|15 +28|76 +28|68 +28|62 +28|92 +28|39 +28|64 +95|94 +95|23 +95|49 +95|28 +95|35 +95|78 +95|86 +95|57 +95|43 +95|82 +95|79 +95|87 +95|65 +95|83 +95|27 +95|67 +95|47 +95|34 +95|31 +95|85 +95|88 +81|21 +81|62 +81|68 +81|59 +81|65 +81|19 +81|18 +81|73 +81|15 +81|67 +81|69 +81|63 +81|84 +81|35 +81|94 +81|66 +81|78 +81|34 +81|26 +81|89 +48|45 +48|39 +48|87 +48|29 +48|31 +48|43 +48|81 +48|75 +48|23 +48|76 +48|82 +48|47 +48|28 +48|27 +48|88 +48|49 +48|53 +48|79 +48|92 +15|86 +15|66 +15|27 +15|47 +15|94 +15|16 +15|67 +15|23 +15|57 +15|34 +15|79 +15|95 +15|78 +15|88 +15|87 +15|19 +15|85 +15|65 +83|51 +83|28 +83|53 +83|92 +83|21 +83|18 +83|75 +83|81 +83|76 +83|62 +83|73 +83|45 +83|39 +83|59 +83|29 +83|15 +83|89 +47|27 +47|76 +47|39 +47|68 +47|45 +47|86 +47|89 +47|26 +47|92 +47|73 +47|81 +47|75 +47|64 +47|49 +47|28 +47|21 +35|47 +35|87 +35|49 +35|27 +35|83 +35|82 +35|16 +35|57 +35|86 +35|31 +35|39 +35|29 +35|23 +35|88 +35|65 +34|27 +34|48 +34|31 +34|28 +34|23 +34|57 +34|79 +34|16 +34|64 +34|83 +34|43 +34|86 +34|29 +34|94 +92|94 +92|51 +92|66 +92|78 +92|63 +92|21 +92|89 +92|95 +92|62 +92|16 +92|81 +92|68 +92|56 +94|27 +94|16 +94|75 +94|23 +94|79 +94|65 +94|31 +94|87 +94|39 +94|86 +94|29 +94|45 +29|19 +29|45 +29|56 +29|69 +29|39 +29|21 +29|92 +29|68 +29|26 +29|84 +29|81 +69|62 +69|19 +69|47 +69|65 +69|27 +69|95 +69|23 +69|88 +69|67 +69|48 +63|47 +63|87 +63|15 +63|67 +63|82 +63|16 +63|95 +63|88 +63|31 +31|87 +31|68 +31|29 +31|75 +31|73 +31|39 +31|27 +31|18 +56|19 +56|66 +56|88 +56|27 +56|94 +56|15 +56|67 +23|18 +23|92 +23|75 +23|64 +23|49 +23|87 +65|75 +65|86 +65|83 +65|47 +65|57 +45|84 +45|75 +45|67 +45|18 +76|15 +76|84 +76|68 +53|95 +53|62 +51|57 + +94,68,73,78,15,65,43,66,62 +34,65,85,48,82,47,23,87,49,79,83,28,29 +57,82,27,87,83,28,29,39,76,45,75,53,92,81,18 +29,86,68,39,81,45,75,76,31,53,64,23,92 +31,28,83,49,87,79,82,64,16,48,86 +45,89,73,53,59,68,28,83,86,79,69,76,39 +31,19,88,35,23,43,86,79,48,16,57,82,27,87,67,65,78,34,49,47,66 +31,47,23,27,87,49,79,83,28,64,29,76,45,75,53,81,59,89,18,73,68 +26,95,73,56,81,89,59,34,92,94,21 +16,63,34,19,66,65,47,56,31,82,51,85,57,67,88,62,48,78,95,35,15 +62,15,66,95,19,67,35,78,94,16,65,48,43,88,82,31,47,23,27,87,86 +62,15,66,95,67,35,34,16,65,43,88,82,31,47,86 +28,68,83,31,59,89,29,73,39,75,92,86,76,45,49,64,18,81,87,27,79,23,47 +81,78,26,16,59,62,51,19,21,56,68,94,18,73,69,35,89,84,66 +83,76,75,53,92,81,73,26,63,56,62 +53,27,29,79,28,88,85,31,47 +29,75,43,31,83,57,49,27,48,64,23,87,86,76,79,53,45 +63,27,43,95,78,56,34 +83,59,89,81,18,84,68,76,69,26,62,63,56,75,73,92,64,53,28,51,29 +75,53,92,18,73,68,26,51,69,63,15,19,67,35,78 +48,31,23,27,87,86,28,64,29,76,75 +16,51,62,43,15,68,78,65,88,19,34,85,26,48,95,94,67,56,84,69,66 +65,82,23,87,86,75,48,49,31,16,57,45,43,47,29 +29,76,45,75,81,18,73,21,56,62,95 +18,67,21,15,63,59,84,66,69,26,34,68,35,95,81,92,19 +49,79,39,76,53,92,59,89,18,68,51,69,63 +85,15,43,62,84,88,57,16,31,95,69 +21,51,43,16,94,78,19 +87,86,49,79,83,28,39,76,45,53,92,89,18,68,26,21,51 +51,69,62,35,88,15,16,21,48,57,26,78,65,43,34,95,19 +49,78,16,94,31,23,65 +87,83,29,45,59,73,51 +34,94,16,85,48,43,88,57,82,23,87,86,79,83,28,29,76 +84,51,69,63,56,62,15,66,95,19,67,35,78,34,94,85,43,88,57,82,31 +53,69,49,84,51,89,28,63,29 +83,21,64,68,75,59,87,45,76,23,29,73,18,27,28,81,26,53,86,89,39,92,79 +62,15,67,35,16,43,86 +88,31,23,83,39 +27,87,86,49,83,64,39,76,75,53,89,73,26,21,84 +53,81,21,51,63,15,95,35,34 +95,51,31,84,15,94,43 +92,76,59,63,73,64,84,81,28,75,15,29,68,62,69 +89,18,62,15,94,65,85 +92,68,63,95,67,78,94 +94,68,95,84,16,63,15,35,26,34,62,73,19,51,56,67,18,21,69,65,66,59,78 +35,34,16,65,48,27,86,83,29 +15,66,95,67,34,94,85,48,43,82,23 +69,63,56,66,95,19,67,35,78,34,94,16,65,85,48,43,23 +85,27,66,19,43,62,86 +65,85,48,43,82,31,47,49,79,28,39,76,45,75,53 +86,49,79,64,39,76,45,75,59,89,84,51,69 +92,81,59,89,18,73,26,21,84,51,69,63,56,62,15,66,95,19,67,35,78,34,94 +26,84,69,63,56,62,66,19,67,78,34,94,16,85,43,88,57 +21,89,19,84,94,35,68,65,18,51,16,63,59,67,34,56,73,78,15,69,95,66,26 +83,23,39,27,76,47,49,29,48,86,82,53,88,64,92,75,81,45,31,43,57 +34,94,16,65,48,57,82,31,23,27,83,28,76 +95,51,62,63,16,34,65,66,69,19,57,82,47 +82,57,84,65,78,31,16,67,66 +64,39,92,81,89,69,66 +59,95,18,68,15,34,35,51,19,92,66,56,94,81,73,62,78 +83,28,64,29,39,76,45,75,53,92,81,89,73,68,26,21,51,69,63,56,62 +66,73,39,64,56,76,59 +68,26,69,56,85,43,88 +67,35,78,94,16,65,48,88,57,82,47,23,49,79,83,28,64 +92,81,26,51,69,63,62,15,95,19,78,34,94 +81,59,73,68,26,51,63,56,15,95,35,34,16 +79,83,64,45,53,81,68,26,84,51,69,63,56 +89,53,84,39,62,63,51,75,64,81,26,18,69,83,45,29,56 +82,87,39,88,23,57,48,85,76,83,92,47,43 +48,43,57,27,87,79,83,76,45,75,53,92,81 +82,81,75,39,88 +43,88,57,82,31,47,23,27,87,86,49,79,83,28,64,29,39,76,45,75,53,81,59 +88,87,86,49,79,83,28,39,76,45,92,81,89 +59,76,29,23,89,79,31,73,45,82,87,92,86 +66,95,19,67,35,78,34,94,16,85,48,43,88,57,82,31,47,23,27,87,86,49,79 +23,27,86,79,83,28,64,29,39,76,45,92,59,89,73,68,21 +23,31,39,53,89,64,79,73,59,45,92 +63,85,66,35,65,15,31,62,95 +35,88,31,78,23,87,15,49,95,27,57 +79,83,28,64,29,76,45,75,53,92,81,59,89,68,26,21,51,69,63 +43,16,73,34,19,66,62 +84,51,56,62,95,67,78,34,85,48,57,82,31 +76,45,75,53,92,81,59,18,73,26,21,51,69,63,56,15,66,95,19 +49,79,83,28,64,29,39,45,75,53,92,81,59,89,18,73,68,26,21,84,51,69,63 +63,51,34,19,15,65,31,57,48,95,88,66,56,67,62,16,35,94,78,84,43 +45,48,83,43,65,29,94,82,76,23,39 +83,49,47,45,88,64,85,28,27 +31,19,35,16,49,88,65,43,48,83,94,67,28 +84,65,88,51,85,43,78,19,21,69,48,66,15,35,68 +21,15,66,19,35,78,94,16,65,88,57 +19,67,78,34,94,65,85,48,43,88,57,47,23,27,87,86,49,83,28 +67,82,87,48,23,65,43,19,95,56,66,35,16 +88,82,31,47,23,27,87,86,49,79,83,28,64,29,39,76,45,53,81,59,89 +92,81,59,73,68,26,21,84,51,69,63,56,15,66,95,19,67,35,78,34,94 +79,76,29,21,68,86,83,53,59,26,49,89,27,87,45,28,81 +49,79,83,28,64,29,39,76,45,75,53,92,81,59,89,18,68,26,21,84,51,69,63 +88,57,82,31,47,23,27,87,86,49,79,83,28,29,39,76,45,75,53,92,81,59,89 +62,45,84,68,66,51,81,75,59,19,92,76,67 +87,79,45,86,85,29,94,16,49,48,27,28,82,39,47,88,31,43,65,64,83,57,23 +48,31,27,86,49,79,28,64,29,39,45,53,92 +56,81,21,59,95,75,89,62,69,66,26,68,67,35,45,73,63,19,51 +31,49,87,39,92,28,27 +45,86,57,64,49 +69,53,76,68,63 +45,29,53,79,88 +86,34,85,65,94,16,48,23,35,43,57,27,49,67,78,88,87,66,82 +59,89,68,39,49 +83,63,28,18,81,84,29,75,26,59,21,45,51,56,92 +66,56,18,51,69 +88,57,47,27,87,49,79,28,29,39,76,45,75,81,89 +39,76,18,53,75,27,68,23,81,92,47,86,73,59,87,89,29,28,26,64,49,79,83 +28,64,29,39,76,45,75,92,81,59,89,18,73,68,26,21,84,51,69,63,56,62,15 +56,62,66,19,67,35,78,94,16,65,85,48,43,88,57,82,47,23,87 +73,68,26,21,84,51,69,63,56,62,15,66,95,19,67,35,78,34,94,65,85,48,43 +15,66,19,35,78,65,85,48,43,88,57,82,47,23,87 +34,94,16,57,82,47,23,87,86,49,29 +23,27,87,86,49,83,64,29,39,76,53,81,59,89,18,73,68,26,21 +88,57,31,49,29,76,75,92,59 +43,88,82,31,87,86,49,79,29,39,92,81,59 +34,26,68,48,66,65,51,67,85,19,18,95,63,35,84,21,16,56,94,69,78 +59,28,29,27,21,92,68,53,86,83,76,87,73,45,64,49,81,18,26,89,39,23,75 +89,73,68,26,21,51,69,63,62,15,66,95,19,67,35,34,94,16,85 +67,65,88,82,79,28,64 +89,73,68,21,84,51,62,15,66,67,78 +56,82,84,48,57,63,16,62,21,78,65 +35,56,66,88,87,85,31 +47,62,78,69,94,56,35,57,48,67,88,95,66 +78,94,88,57,82,86,83,64,39 +28,45,48,79,16,82,88,39,47,87,75,85,29,43,86 +79,85,86,57,27,65,29 +19,67,35,78,34,16,85,43,88,57,82,31,47,27,87,86,79,83,28 +45,75,53,92,81,59,89,18,73,68,26,21,84,51,69,63,56,62,15,66,95,19,35 +73,84,69,15,67,35,78,94,43 +76,75,53,81,59,89,18,73,68,26,69,63,62,19,67 +49,34,35,64,87,65,85,23,78,28,67,48,79,83,82 +62,63,21,26,66,53,76 +67,35,16,82,47,87,64 +48,85,79,23,67,35,27,31,82,16,83,78,94,88,49,95,47 +48,47,23,27,87,49,83,64,29,45,81 +57,82,47,23,83,28,64,29,76,45,75,53,92,81,89 +68,84,51,63,66,19,67,35,94,16,65,48,88 +83,28,64,29,76,75,53,92,81,59,89,18,73,68,26,21,84,51,69,63,56 +95,47,56,34,94,31,66,57,69,16,67,62,48,15,65,23,78,85,19,43,35 +34,63,89,21,95,85,16 +45,75,92,81,89,18,73,21,84,56,62,66,35 +47,23,87,86,83,39,76,53,59,89,18,73,26 +23,28,64,29,39,45,92,81,59,89,18,73,21 +19,67,34,85,43,88,57,82,47,23,27,87,49,83,28 +62,15,66,67,78,34,94,85,43,47,27 +59,69,95,19,35 +57,82,31,47,23,27,86,49,79,83,28,29,39,76,45,75,53,92,81,89,18 +26,21,84,69,63,56,15,95,67,35,78,34,16,65,48,43,57 +27,85,57,65,43,15,47,49,95,16,82 +69,63,56,15,66,95,19,35,78,34,94,16,65,85,48,43,88,57,82,31,47 +45,68,56,62,15 +87,76,31,28,53,81,45,57,29,47,75,27,82,39,92,49,43,79,88 +28,29,39,76,89,68,21,69,15 +86,89,28,18,92,57,45,31,39 +29,27,92,68,86,26,28,39,49,83,59,76,45,64,84 +82,29,87,48,23,27,49,45,75,39,79,43,88,28,65,85,76,16,86 +34,65,51,94,69,62,73,68,66,85,67,48,18,15,63,95,21,78,84 +31,76,34,65,88,49,23 +59,19,68,67,69,62,16,65,78,56,15,66,94,34,26,35,84 +34,65,85,48,43,88,82,87,79,83,64,29,76 +62,67,69,48,73,15,19,94,43,95,66,63,35 +21,84,15,67,35,78,34,94,65,85,48,88,82 +47,16,48,87,39,78,88 +45,57,39,53,92,76,86,79,83,48,81 +85,57,82,23,27,49,64,39,76 +28,64,39,75,92,81,89,68,84,69,15 +51,63,62,15,65,48,47 +92,86,26,89,39,49,75,76,83,59,79,29,45,27,87,21,64,23,81,18,53,68,28 +31,47,23,27,87,86,49,79,83,28,64,29,76,45,75,53,92,81,59,89,18,73,68 +15,35,85,48,31,27,49 +15,66,95,67,34,27,49 +75,81,59,89,18,73,26,21,84,69,63,62,15,66,67,35,78 +63,35,65,67,26,21,57,56,95,48,94,84,15 +23,78,66,62,57,86,35 +76,75,92,81,59,73,26,21,66,19,67 +56,15,95,19,35,78,34,48,88,57,82,47,87 +45,53,29,88,65,48,47,43,39,23,83,27,79,57,76,86,75,28,82 +18,45,81,62,89,56,64,66,69,21,92,26,84,15,68,75,53 +45,75,53,92,81,59,18,73,68,26,69,63,56,62,66,95,19,67,35 +45,92,63,95,19 +69,63,56,62,15,66,19,67,78,16,65,85,48,43,88,57,82,31,47 +62,47,94,31,27,16,67,48,63,95,23,34,56,85,66,65,82 +63,56,19,67,78,34,65,85,48,43,88 +26,21,84,69,95,63,56,94,73,16,18,19,66,51,35,85,62,67,34,48,68 +65,88,23,87,79,83,28,29,53 +29,39,76,45,81,59,89,18,73,21,84,51,69,63,56,15,95 +47,27,79,65,19,66,87 +82,31,47,23,87,49,83,64,76,45,75,92,81,59,18 +86,28,64,39,76,45,75,92,81,59,73,21,69 +73,65,19,62,34,26,56,66,35,59,95,69,21,78,51,84,67 diff --git a/src/days/d05.rs b/src/days/d05.rs new file mode 100644 index 0000000..6fb1c1f --- /dev/null +++ b/src/days/d05.rs @@ -0,0 +1,82 @@ +use std::fs; + +pub fn solve() { + let path = "res/05/input"; + + let contents = fs::read_to_string(path).expect("Something went wrong reading the file"); + + let (rules_str, updates_str) = contents.split_once("\n\n").unwrap(); + + let rules: Vec<(usize, usize)> = rules_str + .lines() + .map(|s| { + s.split_once("|") + .map(|(n1, n2)| (n1.parse::().unwrap(), n2.parse::().unwrap())) + .unwrap() + }) + .collect(); + + let updates: Vec> = updates_str + .lines() + .map(|line| { + line.split(",") + .map(|n| n.parse::().unwrap()) + .collect::>() + }) + .collect(); + + let result: usize = updates + .iter() + .filter(|upd| { + upd.iter().enumerate().all(|(i, n)| { + rules + .iter() + .filter(|(n1, _)| *n1 == *n) + .all(|(_, n2)| upd.iter().take(i).all(|n| n != n2)) + }) + }) + .map(|upd| upd[(upd.len() / 2) as usize]) + .sum(); + + println!("Result 1: {}", result); + + let result: usize = updates + .iter() + .filter(|upd| { + !upd.iter().enumerate().all(|(i, n)| { + rules + .iter() + .filter(|(n1, _)| *n1 == *n) + .all(|(_, n2)| upd.iter().take(i).all(|n| n != n2)) + }) + }) + .map(|upd| { + let mut upd = upd.clone(); + while upd.iter().enumerate().any(|(i, n)| { + rules + .iter() + .filter(|(n1, _)| *n1 == *n) + .any(|(_, n2)| upd.iter().take(i).any(|n| n == n2)) + }) { + for i in 0..upd.len() { + let mut upd2 = upd.clone(); + rules + .iter() + .filter(|(n1, _)| *n1 == upd[i]) + .filter(|(_, n2)| upd.iter().take(i).any(|n| n == n2)) + .take(1) + .for_each(|(_, n2)| { + let pos = upd.iter().position(|n| *n == *n2).unwrap(); + upd2[pos] = upd[i]; + upd2[i] = *n2; + }); + upd = upd2; + } + } + upd + }) + .map(|upd| upd[(upd.len() / 2) as usize]) + .sum(); + + println!("Result 2: {}", result); +} diff --git a/src/main.rs b/src/main.rs index 6ad7161..bd9ccb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,11 +29,11 @@ fn _all_days() { days::d04::solve(); time = _print_elapsed(time); - /* println!("\nDay 5"); days::d05::solve(); time = _print_elapsed(time); + /* println!("\nDay 6"); days::d06::solve(); time = _print_elapsed(time);