From 2a202242d870111e087c256f5c0a6152a15d24df Mon Sep 17 00:00:00 2001 From: Naomi Amethyst Date: Fri, 20 Dec 2024 06:20:44 +0000 Subject: [PATCH] +day05 part1 --- 2024/day05/input | 1379 +++++++++++++++++++++++++++++++++++++++++++ 2024/day05/part1.cc | 93 +++ 2 files changed, 1472 insertions(+) create mode 100644 2024/day05/input create mode 100644 2024/day05/part1.cc diff --git a/2024/day05/input b/2024/day05/input new file mode 100644 index 0000000..69ec929 --- /dev/null +++ b/2024/day05/input @@ -0,0 +1,1379 @@ +31|94 +98|37 +98|49 +25|17 +25|22 +25|44 +89|84 +89|66 +89|32 +89|72 +97|31 +97|33 +97|51 +97|67 +97|23 +94|96 +94|11 +94|53 +94|47 +94|36 +94|89 +56|23 +56|76 +56|33 +56|88 +56|64 +56|62 +56|11 +67|47 +67|72 +67|56 +67|87 +67|54 +67|33 +67|62 +67|84 +87|42 +87|19 +87|98 +87|47 +87|11 +87|24 +87|71 +87|53 +87|21 +17|72 +17|18 +17|51 +17|94 +17|62 +17|49 +17|27 +17|84 +17|37 +17|68 +32|56 +32|72 +32|87 +32|67 +32|15 +32|94 +32|96 +32|71 +32|76 +32|31 +32|78 +49|23 +49|33 +49|79 +49|68 +49|88 +49|15 +49|87 +49|71 +49|36 +49|85 +49|96 +49|53 +64|97 +64|78 +64|36 +64|59 +64|89 +64|25 +64|79 +64|98 +64|34 +64|44 +64|24 +64|53 +64|55 +96|64 +96|71 +96|47 +96|53 +96|21 +96|44 +96|77 +96|25 +96|42 +96|79 +96|66 +96|17 +96|87 +96|55 +53|17 +53|59 +53|79 +53|14 +53|78 +53|51 +53|32 +53|24 +53|55 +53|44 +53|84 +53|19 +53|34 +53|67 +53|77 +55|24 +55|77 +55|59 +55|89 +55|66 +55|13 +55|51 +55|25 +55|42 +55|84 +55|34 +55|97 +55|14 +55|98 +55|44 +55|31 +54|25 +54|24 +54|88 +54|44 +54|97 +54|64 +54|11 +54|19 +54|47 +54|32 +54|42 +54|14 +54|55 +54|79 +54|21 +54|89 +54|77 +51|71 +51|84 +51|13 +51|33 +51|15 +51|68 +51|31 +51|76 +51|85 +51|37 +51|27 +51|87 +51|22 +51|64 +51|18 +51|94 +51|72 +51|23 +85|79 +85|22 +85|55 +85|89 +85|54 +85|68 +85|87 +85|88 +85|96 +85|47 +85|21 +85|62 +85|64 +85|23 +85|94 +85|11 +85|27 +85|59 +85|15 +22|68 +22|79 +22|14 +22|59 +22|77 +22|94 +22|55 +22|47 +22|23 +22|71 +22|87 +22|53 +22|62 +22|27 +22|21 +22|54 +22|36 +22|15 +22|96 +22|42 +21|89 +21|14 +21|98 +21|59 +21|67 +21|13 +21|55 +21|42 +21|24 +21|34 +21|19 +21|17 +21|88 +21|79 +21|66 +21|78 +21|51 +21|53 +21|97 +21|77 +21|84 +68|89 +68|19 +68|24 +68|25 +68|27 +68|11 +68|77 +68|59 +68|44 +68|79 +68|21 +68|64 +68|36 +68|54 +68|71 +68|55 +68|88 +68|47 +68|87 +68|53 +68|14 +68|96 +62|47 +62|59 +62|54 +62|88 +62|25 +62|42 +62|44 +62|53 +62|27 +62|79 +62|96 +62|94 +62|87 +62|97 +62|55 +62|68 +62|36 +62|21 +62|64 +62|89 +62|14 +62|71 +62|11 +15|87 +15|88 +15|14 +15|53 +15|96 +15|89 +15|47 +15|68 +15|27 +15|21 +15|64 +15|44 +15|11 +15|54 +15|36 +15|42 +15|94 +15|71 +15|62 +15|25 +15|59 +15|79 +15|77 +15|55 +78|62 +78|87 +78|31 +78|18 +78|94 +78|49 +78|84 +78|85 +78|76 +78|67 +78|22 +78|72 +78|23 +78|56 +78|13 +78|27 +78|37 +78|54 +78|68 +78|15 +78|51 +78|96 +78|33 +78|71 +84|87 +84|49 +84|23 +84|33 +84|94 +84|47 +84|85 +84|27 +84|62 +84|68 +84|76 +84|15 +84|18 +84|31 +84|36 +84|22 +84|56 +84|11 +84|72 +84|71 +84|37 +84|54 +84|96 +84|64 +36|55 +36|79 +36|42 +36|77 +36|34 +36|25 +36|14 +36|17 +36|97 +36|44 +36|53 +36|21 +36|89 +36|88 +36|24 +36|51 +36|32 +36|67 +36|19 +36|59 +36|66 +36|13 +36|98 +36|78 +79|34 +79|37 +79|18 +79|59 +79|98 +79|17 +79|13 +79|89 +79|66 +79|97 +79|19 +79|24 +79|78 +79|25 +79|84 +79|14 +79|31 +79|32 +79|77 +79|55 +79|51 +79|67 +79|42 +79|44 +88|34 +88|78 +88|59 +88|31 +88|42 +88|37 +88|66 +88|32 +88|79 +88|55 +88|25 +88|98 +88|51 +88|89 +88|77 +88|19 +88|67 +88|17 +88|97 +88|44 +88|14 +88|24 +88|84 +88|13 +47|36 +47|19 +47|79 +47|51 +47|14 +47|17 +47|89 +47|21 +47|88 +47|66 +47|77 +47|78 +47|24 +47|97 +47|42 +47|53 +47|25 +47|32 +47|59 +47|34 +47|13 +47|98 +47|55 +47|44 +72|62 +72|68 +72|85 +72|64 +72|36 +72|11 +72|71 +72|22 +72|56 +72|47 +72|49 +72|53 +72|76 +72|21 +72|87 +72|88 +72|27 +72|54 +72|79 +72|15 +72|94 +72|23 +72|33 +72|96 +19|33 +19|49 +19|72 +19|84 +19|17 +19|15 +19|31 +19|94 +19|34 +19|67 +19|76 +19|23 +19|18 +19|22 +19|66 +19|85 +19|32 +19|62 +19|13 +19|78 +19|37 +19|56 +19|51 +19|98 +18|56 +18|11 +18|72 +18|88 +18|87 +18|53 +18|96 +18|62 +18|49 +18|15 +18|27 +18|33 +18|64 +18|76 +18|22 +18|85 +18|21 +18|54 +18|71 +18|23 +18|47 +18|94 +18|36 +18|68 +71|14 +71|88 +71|17 +71|19 +71|44 +71|42 +71|77 +71|54 +71|11 +71|79 +71|66 +71|59 +71|36 +71|55 +71|64 +71|53 +71|97 +71|24 +71|21 +71|25 +71|89 +71|47 +71|34 +71|98 +33|23 +33|94 +33|11 +33|71 +33|54 +33|68 +33|47 +33|55 +33|62 +33|22 +33|96 +33|87 +33|27 +33|89 +33|64 +33|59 +33|88 +33|77 +33|76 +33|15 +33|53 +33|21 +33|36 +33|79 +23|59 +23|11 +23|25 +23|68 +23|42 +23|47 +23|27 +23|79 +23|55 +23|64 +23|62 +23|21 +23|36 +23|77 +23|54 +23|53 +23|14 +23|89 +23|15 +23|71 +23|88 +23|96 +23|94 +23|87 +77|42 +77|19 +77|37 +77|18 +77|17 +77|85 +77|44 +77|51 +77|72 +77|31 +77|32 +77|84 +77|14 +77|98 +77|25 +77|24 +77|67 +77|97 +77|13 +77|49 +77|34 +77|66 +77|56 +77|78 +24|32 +24|33 +24|98 +24|22 +24|49 +24|37 +24|31 +24|13 +24|23 +24|51 +24|78 +24|66 +24|34 +24|85 +24|19 +24|56 +24|62 +24|18 +24|15 +24|76 +24|17 +24|67 +24|84 +24|72 +44|22 +44|13 +44|51 +44|76 +44|23 +44|19 +44|32 +44|56 +44|97 +44|17 +44|24 +44|84 +44|66 +44|18 +44|78 +44|34 +44|31 +44|37 +44|85 +44|72 +44|33 +44|98 +44|67 +44|49 +59|24 +59|77 +59|44 +59|25 +59|67 +59|14 +59|51 +59|78 +59|18 +59|72 +59|17 +59|37 +59|56 +59|66 +59|34 +59|84 +59|19 +59|31 +59|13 +59|42 +59|89 +59|32 +59|98 +59|97 +13|54 +13|18 +13|72 +13|27 +13|11 +13|62 +13|68 +13|94 +13|87 +13|67 +13|64 +13|15 +13|33 +13|37 +13|76 +13|84 +13|31 +13|56 +13|96 +13|49 +13|85 +13|22 +13|71 +13|23 +11|32 +11|21 +11|77 +11|34 +11|17 +11|89 +11|98 +11|36 +11|79 +11|97 +11|78 +11|42 +11|66 +11|88 +11|24 +11|19 +11|51 +11|47 +11|55 +11|14 +11|59 +11|25 +11|53 +11|44 +14|51 +14|97 +14|78 +14|33 +14|72 +14|25 +14|31 +14|17 +14|44 +14|42 +14|24 +14|84 +14|66 +14|19 +14|56 +14|13 +14|37 +14|18 +14|98 +14|34 +14|32 +14|67 +14|85 +14|49 +34|31 +34|78 +34|37 +34|23 +34|15 +34|68 +34|49 +34|67 +34|51 +34|76 +34|85 +34|96 +34|56 +34|33 +34|94 +34|84 +34|87 +34|22 +34|27 +34|72 +34|18 +34|13 +34|32 +34|62 +42|18 +42|51 +42|76 +42|56 +42|66 +42|44 +42|97 +42|13 +42|33 +42|72 +42|25 +42|34 +42|17 +42|24 +42|31 +42|84 +42|85 +42|37 +42|78 +42|19 +42|49 +42|98 +42|67 +42|32 +76|59 +76|71 +76|77 +76|15 +76|54 +76|23 +76|22 +76|96 +76|53 +76|14 +76|62 +76|79 +76|21 +76|55 +76|27 +76|64 +76|87 +76|68 +76|36 +76|11 +76|47 +76|89 +76|88 +76|94 +27|25 +27|79 +27|71 +27|42 +27|47 +27|14 +27|53 +27|36 +27|66 +27|11 +27|87 +27|55 +27|21 +27|64 +27|88 +27|54 +27|19 +27|97 +27|59 +27|24 +27|89 +27|77 +27|44 +27|96 +66|32 +66|84 +66|68 +66|98 +66|76 +66|94 +66|15 +66|33 +66|22 +66|72 +66|37 +66|56 +66|85 +66|49 +66|13 +66|31 +66|34 +66|78 +66|51 +66|67 +66|18 +66|23 +66|62 +66|17 +37|27 +37|22 +37|15 +37|11 +37|33 +37|76 +37|23 +37|36 +37|21 +37|49 +37|96 +37|56 +37|68 +37|87 +37|71 +37|62 +37|54 +37|31 +37|64 +37|72 +37|18 +37|94 +37|47 +37|85 +31|47 +31|27 +31|72 +31|23 +31|49 +31|56 +31|54 +31|87 +31|68 +31|71 +31|15 +31|96 +31|22 +31|85 +31|76 +31|36 +31|64 +31|11 +31|18 +31|53 +31|62 +31|33 +31|21 +98|62 +98|32 +98|13 +98|31 +98|85 +98|51 +98|72 +98|27 +98|15 +98|67 +98|22 +98|23 +98|18 +98|33 +98|84 +98|78 +98|94 +98|68 +98|96 +98|56 +98|34 +98|76 +25|67 +25|33 +25|32 +25|13 +25|84 +25|49 +25|72 +25|34 +25|78 +25|98 +25|24 +25|37 +25|85 +25|51 +25|97 +25|66 +25|18 +25|76 +25|19 +25|56 +25|31 +89|49 +89|17 +89|42 +89|67 +89|56 +89|37 +89|97 +89|51 +89|34 +89|77 +89|44 +89|31 +89|25 +89|19 +89|24 +89|98 +89|78 +89|14 +89|18 +89|13 +97|78 +97|66 +97|49 +97|34 +97|17 +97|56 +97|85 +97|37 +97|32 +97|24 +97|19 +97|15 +97|13 +97|18 +97|72 +97|22 +97|98 +97|84 +97|76 +94|42 +94|88 +94|21 +94|27 +94|44 +94|14 +94|77 +94|64 +94|79 +94|87 +94|97 +94|24 +94|68 +94|25 +94|54 +94|59 +94|55 +94|71 +56|85 +56|15 +56|79 +56|21 +56|53 +56|96 +56|47 +56|94 +56|36 +56|54 +56|49 +56|27 +56|87 +56|68 +56|71 +56|22 +56|55 +67|31 +67|18 +67|71 +67|11 +67|96 +67|37 +67|85 +67|15 +67|22 +67|76 +67|27 +67|68 +67|49 +67|94 +67|64 +67|23 +87|77 +87|79 +87|88 +87|17 +87|36 +87|54 +87|25 +87|66 +87|44 +87|14 +87|55 +87|97 +87|59 +87|89 +87|64 +17|22 +17|13 +17|23 +17|67 +17|76 +17|33 +17|31 +17|56 +17|85 +17|98 +17|78 +17|15 +17|34 +17|32 +32|23 +32|84 +32|49 +32|22 +32|62 +32|68 +32|85 +32|27 +32|51 +32|13 +32|37 +32|18 +32|33 +49|54 +49|27 +49|47 +49|11 +49|55 +49|21 +49|64 +49|22 +49|62 +49|94 +49|59 +49|76 +64|21 +64|11 +64|77 +64|19 +64|66 +64|17 +64|47 +64|32 +64|88 +64|14 +64|42 +96|88 +96|54 +96|19 +96|97 +96|59 +96|24 +96|36 +96|89 +96|14 +96|11 +53|25 +53|66 +53|98 +53|37 +53|42 +53|13 +53|97 +53|88 +53|89 +55|32 +55|72 +55|18 +55|17 +55|67 +55|19 +55|37 +55|78 +54|36 +54|98 +54|53 +54|34 +54|66 +54|17 +54|59 +51|62 +51|49 +51|56 +51|67 +51|96 +51|54 +85|33 +85|53 +85|71 +85|76 +85|36 +22|11 +22|64 +22|89 +22|88 +21|44 +21|25 +21|32 +68|42 +68|97 +62|77 + +11,71,68,89,88,79,21,96,47,55,14,27,15,87,23,42,62,64,54,77,94,59,36 +87,89,59,36,96,71,44,19,47,55,11,25,54,64,88,14,42,27,97,24,21 +79,19,89,59,53,32,13,66,24,98,25,88,44,17,97,21,77,14,51,78,36,55,34 +56,49,85,33,76,22,23,15,62,94,68,27,96,87,64,11,36,21,53,88,79 +42,25,44,97,24,19,98,34,32,78,13,84,37,31,18,72,56,85,33 +47,21,53,88,55,89,77,14,42,25,44,97,19,66,17,98,34,32,51 +13,31,56,33,23,27,96,54,64 +53,88,55,59,42,25,44,97,24,19,66,17,98,34,32,78,13,67,84 +44,68,71,14,64,87,53,27,97,54,94,59,77 +77,47,19,34,53 +71,19,21,24,11,77,88,25,98,66,89,54,42,53,64 +87,71,54,64,36,21,53,59,77,14,42,25,17 +37,31,76,96,32,34,49,23,27,51,94,68,18 +84,67,23,49,31,51,56,98,33,15,94,76,17,22,13,66,62,32,34 +22,23,15,62,27,96,87,71,54,11,47,21,53,79,55,59,89,77,14 +33,51,27,94,68,85,23,67,22,13,84,76,15,31,34,49,56,72,18,78,62 +79,55,89,14,44,24,98,13,31 +85,49,22,56,23,62,71,72,76,68,11,15,94 +22,23,15,17,34,68,76 +71,87,36,53,68 +87,47,36,21,79,55,77,14,42,19,66 +94,87,27,33,21,89,76 +42,25,44,97,24,19,66,17,98,32,78,51,13,67,37,31,18,72,56,49,85 +71,36,79,55,59,89,77,42,24,17,98 +19,32,67,18,72,56,49,85,22,15,62 +76,85,22,31,18,23,98,15,56,78,66,67,17,51,37,49,34,33,24 +27,76,85,22,54,11,96,71,72,87,94,56,36,18,47,33,68,49,53 +84,37,31,18,72,56,85,33,76,22,23,15,62,94,68,27,96,87,71,54,64,11,47 +67,84,31,72,56,85,76,22,15,94,96,87,71,64,11 +64,79,59,71,62,68,21,55,22 +49,85,33,22,23,87,71,64,11,47,21,53,55 +23,15,68,27,96,87,71,64,47,36,21,88,79,55,59,77,42 +19,77,51,31,42,32,34,24,13,97,98,78,67,44,55,89,84,25,66 +55,77,24,19,66,34,67,84,37 +66,25,89,77,42,13,21,17,32,59,67,53,79,55,24,34,19,97,14 +62,68,21,76,54,64,47,87,88,53,96,56,15,72,22,27,11 +97,24,19,17,34,32,78,51,13,67,84,31,18,72,56,49,85,33,76,22,23 +85,72,87,22,76,33,49,32,51 +15,94,27,96,87,54,11,36,21,53,55,59,77,14,42 +68,27,96,87,71,54,64,11,47,36,21,53,79,55,59,89,77,14,42,25,44,97,24 +32,78,51,13,67,37,18,72,56,76,22,62,27 +72,56,49,85,22,62,27,54,11,47,88 +88,14,19,87,11,54,25,97,89,21,24,36,59,55,77,71,27,47,96,44,79,53,64 +87,76,13,22,15,78,37,51,67,23,18,84,56,72,31,85,33,27,96,62,32,94,68 +44,97,24,66,17,98,34,78,13,67,84,37,31,18,72,56,49,85,33,76,22 +53,55,59,89,77,25,44,97,24,19,17,98,34,32,78,51,13,67,84 +89,25,66,98,78,37,56 +44,25,79,98,55,11,24,17,42,71,14,36,54 +77,14,54,87,89 +19,66,17,98,34,32,78,51,13,67,84,37,31,18,56,33,76,22,23,15,62 +33,31,84,18,72,62,13,68,37,27,85,94,87,76,96,67,54,71,51 +49,96,78,51,33,62,84,27,32,13,15,56,87,67,37,31,85,22,18,72,94,76,23 +22,11,36,88,89,77,14 +18,19,84,24,25,44,32,98,85,76,17 +84,22,67,18,34,49,76,56,98,37,72 +44,97,66,98,32,18,56,85,22 +33,76,22,23,15,62,94,68,27,96,87,54,64,11,47,36,21,53,88,79,55,59,89 +31,13,98,33,72,84,42,32,51,97,19 +32,15,23,66,24,78,76,17,85,34,18 +51,84,19,23,78,98,67,72,85,66,24,17,31,97,18,13,56,32,76,37,33 +98,78,24,51,77,36,19,47,14,97,66,17,42,34,21,59,44,53,88,25,89 +23,67,84,15,13,78,71,37,22 +19,66,98,67,31,49,85,23,15 +55,66,19,97,34,21,89,17,54 +98,13,67,84,37,31,18,76,22,62,68 +27,96,54,53,79,55,25 +31,18,56,49,33,76,22,23,62,94,68,27,71,64,21 +25,79,64,42,53,68,87,15,54,96,94,88,27 +17,25,49,72,32,42,18,78,13,19,34,85,33 +68,37,23,33,71,85,76,94,62,31,56 +53,88,89,42,25,24,19,66,17,78,51,67,84 +51,67,84,37,31,18,72,56,49,85,76,23,15,62,94,68,27,96,87,71,54 +13,84,31,18,56,49,33,76,22,62,94,68,27,96,71,54,64 +37,84,68,94,23,96,15 +96,32,84,62,13,27,68,85,37,34,56,31,18,22,49 +36,56,68,87,37,85,47,64,49 +77,19,17,89,56,42,34 +18,76,34,85,97,17,66,98,37,31,51,24,67,32,33,25,78,56,49 +42,25,97,24,17,34,78,51,84,18,72,56,85 +32,49,66,67,17,72,13,44,22,51,31,78,34,33,76,18,19 +55,14,42,44,34,67,84,31,18 +96,87,71,64,11,47,21,53,88,79,55,59,89,77,14,42,25,44,97,24,66 +55,96,47,44,42,25,66 +71,97,17,47,36,14,89,42,44,24,77,66,64,54,11,98,55,19,25 +62,36,53,55,14 +78,98,19,72,66,31,51,25,49,44,76,32,84,24,18,37,67,97,33 +25,97,24,17,98,32,56 +97,66,32,49,85,22,23 +55,89,77,14,42,25,44,97,17,32,78,51,84,31,18 +31,56,85,27,96,87,21 +33,76,15,62,87,71,47,36,88,59,89 +85,62,37,51,18,31,94,22,32,72,76,34,98,66,33,84,67,17,56,49,78 +76,56,49,34,31,67,66,23,62,98,17,18,94,51,78,85,15,33,13 +14,42,44,97,24,19,66,98,34,32,37,72,85 +15,62,68,27,96,87,71,54,11,21,79,55,59,89,77,14,25 +32,78,51,13,84,37,31,18,72,33,76,22,23,15,62,94,68,96,87 +11,23,88,59,68,15,47,27,55,22,94,71,33,85,54 +84,27,56,11,76,47,37,72,31,64,33 +14,42,44,24,98,34,32,78,13,84,31,18,72,56,85 +71,23,55,11,79,54,96,33,68,53,36,59,89 +18,49,19,84,51,37,32,44,72,56,24,14,77 +85,76,22,23,15,62,94,68,27,96,87,54,11,47,36,21,53,88,79,55,59 +22,94,27,96,64,11,36,88,79,55,77 +66,34,17,53,44,78,11,42,98,79,77,14,59,19,89,25,97 +77,14,42,44,97,24,19,66,17,98,34,32,78,51,13,84,31,18,72,56,49 +47,36,88,14,44,66,34 +89,77,14,42,25,44,97,24,19,66,17,98,34,32,78,51,13,67,84,37,18,72,56 +54,53,36,85,11,68,18,76,72,22,21,64,49,27,96 +77,59,88,24,47,55,89,66,36,44,25,79,19 +23,15,87,71,53,77,42 +89,77,14,42,25,44,97,24,19,66,17,78,51,67,84,37,31,72,56 +56,94,11,53,64,87,33,96,22,71,47,23,27,79,54 +17,32,84,37,18,22,68 +49,62,96,36,79 +71,94,87,18,64,49,13 +17,98,34,32,78,51,13,67,84,37,31,18,56,49,76,23,62 +87,68,14,27,89,21,54,79,44,77,88,25,42,36,59,71,62,64,53 +64,11,47,36,21,53,88,79,55,59,89,77,14,42,44,97,24,19,66,17,98,34,32 +55,14,25,97,24,66,17,51,13,67,18 +62,22,33,23,37,72,54,67,18,64,56,15,13,68,84,27,94 +67,84,18,33,76,22,23,62,27,96,11 +78,51,13,18,72,56,49,85,33,76,23,15,62,94,68,96,71 +54,36,59,14,17,98,34 +71,64,21,88,79,89,25,97,24,19,98 +33,62,87,23,76,51,71,68,22,96,85,31,67,84,54,49,94,27,37,13,72,15,18 +31,18,56,23,15,62,94,54,64,47,21 +25,78,13,24,88,42,32,44,14,98,89,34,77 +51,78,67,55,89,79,77,97,17,88,34,84,98,53,42,14,13,19,44 +96,71,54,64,11,47,36,21,53,88,59,89,77,14,42,25,44,97,66 +33,84,22,85,23,19,66,34,56,31,72 +78,62,84,34,96,37,76,31,51,85,18,94,13,23,67,49,15,27,68 +11,22,27,53,68,72,33,23,96,21,94,36,87,85,56,64,49,54,18,76,47,71,62 +66,98,24,97,44,42,11,89,64,17,19,21,79,77,34,14,59,47,53,36,88,32,25 +94,68,96,87,71,54,64,11,47,36,21,53,88,79,55,59,89,77,14,42,25,44,97 +36,15,87,53,54,21,62,33,89,47,68,94,96,64,71 +54,97,59,94,88,53,25 +23,49,62,15,68,18,76,33,53 +79,59,77,14,66,34,31 +14,98,84,31,13,55,25,18,77,24,59 +64,36,49,76,88,21,94,87,53,72,15,68,47,56,27 +97,14,24,79,44,42,89,66,19,47,17,53,55,21,51,98,25,32,78,59,88,34,77 +13,96,62,68,78,72,18,27,87,49,51,67,22,56,37,15,84,31,94,71,76,33,23 +13,31,18,72,56,49,22,23,15,62,94,68,96,54,64 +37,33,64,85,18,62,36 +22,85,96,31,21,72,56,62,76,33,87,23,54,64,15 +78,24,44,19,34,14,84,53,32 +55,59,25,24,32,84,18 +64,47,36,21,88,79,55,59,89,77,25,44,97,98,34 +98,78,51,13,67,84,37,31,18,72,56,33,76,23,62,94,68 +88,79,55,59,89,14,25,97,24,66,98,32,78,13,67,84,37 +11,47,36,21,88,55,59,89,77,14,42,25,44,97,17,98,34,32,78 +27,56,72,21,68,76,87,85,71,49,23,94,88,54,64 +66,32,17,67,42,25,79,44,51,53,19,89,14,13,55,78,77,21,34,98,59,24,88 +22,87,11,27,64,96,68,62,89,15,54 +98,13,37,25,14,56,85,34,72,97,19,44,49,17,42 +77,42,36,47,55,32,97,51,88 +44,84,37,97,66,17,77,32,72,78,51,13,18,25,67,14,59 +53,97,36,59,13 +79,71,11,94,54,56,21 +87,71,54,64,11,47,36,21,53,79,55,59,89,77,14,42,25,44,97,24,19,66,17 +34,32,78,67,72,49,76,22,96 +37,13,51,24,84,72,66,42,77,32,14,25,31,17,67,97,56,98,34,44,89,78,19 +77,42,51,72,97,49,19,56,67 +98,34,32,78,51,13,67,84,37,31,18,72,56,49,85,33,76,23,15,62,94,68,27 +84,31,85,76,23,15,62,94,96,71,47 +22,68,53,11,77,59,76,79,89,88,27,62,87,47,71,54,36 +19,78,25,79,84,59,24 +51,13,67,31,72,56,49,15,27,96,87,71,54 +66,98,34,32,67,37,31,18,49,85,23,15,94 +53,89,11,54,34,25,47 +42,44,97,24,19,34,32,13,67,37,31,18,72,56,49 +68,15,27,71,62 +96,97,36,24,64,54,66 +19,66,17,67,31,18,56,22,23,15,62 +47,22,11,76,85,68,62,49,18,21,96,33,27,23,64,15,94,56,87 +62,94,27,87,71,54,64,47,36,21,53,88,55,89,77,14,44 +32,51,13,67,84,37,18,56,85,33,22,23,62,94,87 +89,14,25,44,24,17,78,13,84,37,31,18,72 +59,89,77,14,42,32,78,51,13,67,37,31,72 +68,49,15,96,54,27,88,79,87,22,94,64,76,23,55 +13,37,31,49,33,22,15,62,94,68,27,96,71,54,64 +14,51,67,88,55,98,37,13,25 +88,79,59,89,14,42,25,44,97,24,19,98,34,32,78,13,67 +88,55,89,71,76,62,21,22,47,15,87,59,77,53,79,23,94 +55,37,77,19,34,13,51,67,44,32,98,24,78,17,14 +96,15,94,84,11,87,72 +31,11,47,22,54,23,94,56,87,18,71,27,15 +66,17,51,84,37,31,49,33,76,22,94 +42,66,34,32,13,37,18,85,33 +55,11,36,87,77,47,68,42,62,44,79,96,59,21,25 +44,59,24,87,64,53,42,11,68,27,47,79,14,71,25 +25,44,24,19,66,17,34,32,78,13,84,37,31,18,72,49,85,33,76 +31,18,72,56,85,33,76,23,62,27,54,36,21 +25,24,66,17,51,31,49,85,76 +98,78,51,13,67,84,37,31,18,72,56,49,33,15,68 +78,13,19,84,22,98,23 +78,25,37,17,24,97,34,88,66,13,77,51,32,98,89,14,84,59,19,55,67 +18,51,84,13,24,59,98,17,97,32,34,44,89,77,19,42,72,25,78 +15,62,94,68,27,96,87,71,54,64,11,47,36,21,53,88,55,59,89,77,14,42,25 +15,21,55,59,89,14,25 +84,56,33,76,23,68,96,64,47 +71,66,89,36,87,54,21,55,14,42,19,17,25,88,97,44,47 diff --git a/2024/day05/part1.cc b/2024/day05/part1.cc new file mode 100644 index 0000000..978efe6 --- /dev/null +++ b/2024/day05/part1.cc @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include + +class print_job { + std::vector page_order; + std::set pages; +public: + print_job(std::stringstream& ss); + bool before(int before, int after) const; + bool contains(int page) const; + int middle() const; +}; + +print_job::print_job(std::stringstream& ss) { + int page; + while (ss >> page) { + page_order.emplace_back(page); + pages.emplace(page); + ss.ignore(1, ','); + } +} + +bool print_job::before(int before, int after) const { + return std::distance(page_order.begin(), std::find(page_order.begin(), page_order.end(), before)) + < std::distance(page_order.begin(), std::find(page_order.begin(), page_order.end(), after)); +} + +bool print_job::contains(int page) const { + return pages.contains(page); +} + +int print_job::middle() const { + return page_order[page_order.size() / 2]; +} + +class rule { + int before; + int after; +public: + rule(std::stringstream& ss); + bool valid(const print_job& job) const; +}; + +rule::rule(std::stringstream& ss) { + ss >> before; + ss.ignore(1, '|'); + ss >> after; +} + +bool rule::valid(const print_job& job) const { + return !job.contains(before) || !job.contains(after) || job.before(before, after); +} + +class rule_set { + std::vector rules; +public: + rule_set(std::istream& is); + bool valid(const print_job& job) const; +}; + +rule_set::rule_set(std::istream& is) { + std::string line; + while (std::getline(is, line)) { + if (line == "") { + return; + } + std::stringstream ss(line); + rules.emplace_back(ss); + } +} + +bool rule_set::valid(const print_job& job) const { + return std::ranges::all_of(rules, [&](auto rule) { return rule.valid(job); }); +} + +int main() { + rule_set rules(std::cin); + std::string line; + int sum = 0; + while (std::getline(std::cin, line)) { + std::stringstream ss(line); + print_job job(ss); + if (rules.valid(job)) { + sum += job.middle(); + } + } + std::cout << sum << std::endl; + return EXIT_SUCCESS; +}