diff --git a/2024/5/Makefile b/2024/5/Makefile new file mode 100644 index 0000000..638e325 --- /dev/null +++ b/2024/5/Makefile @@ -0,0 +1,2 @@ +a.out: main.cpp + clang++ -std=c++2b -g -O0 main.cpp diff --git a/2024/5/data.txt b/2024/5/data.txt new file mode 100644 index 0000000..3370a8d --- /dev/null +++ b/2024/5/data.txt @@ -0,0 +1,1387 @@ +46|53 +25|43 +25|66 +43|65 +43|35 +43|61 +54|83 +54|15 +54|46 +54|92 +84|23 +84|16 +84|11 +84|74 +84|88 +16|99 +16|65 +16|61 +16|66 +16|28 +16|46 +86|88 +86|61 +86|34 +86|31 +86|35 +86|27 +86|95 +61|84 +61|88 +61|92 +61|51 +61|45 +61|55 +61|34 +61|74 +23|18 +23|97 +23|99 +23|58 +23|54 +23|43 +23|89 +23|66 +23|39 +68|12 +68|55 +68|51 +68|92 +68|98 +68|74 +68|96 +68|42 +68|75 +68|14 +98|55 +98|92 +98|42 +98|45 +98|23 +98|34 +98|74 +98|73 +98|96 +98|51 +98|31 +58|86 +58|18 +58|98 +58|66 +58|25 +58|61 +58|54 +58|68 +58|43 +58|26 +58|28 +58|75 +99|51 +99|49 +99|53 +99|86 +99|66 +99|39 +99|26 +99|96 +99|98 +99|15 +99|61 +99|35 +99|65 +39|88 +39|42 +39|84 +39|53 +39|15 +39|51 +39|45 +39|92 +39|65 +39|75 +39|83 +39|12 +39|34 +39|35 +34|16 +34|45 +34|89 +34|14 +34|66 +34|74 +34|23 +34|55 +34|88 +34|12 +34|99 +34|26 +34|73 +34|62 +34|72 +65|27 +65|34 +65|55 +65|97 +65|42 +65|83 +65|22 +65|45 +65|58 +65|35 +65|12 +65|92 +65|14 +65|73 +65|64 +65|89 +88|22 +88|97 +88|12 +88|72 +88|52 +88|89 +88|64 +88|62 +88|23 +88|49 +88|26 +88|13 +88|66 +88|73 +88|18 +88|16 +88|58 +97|39 +97|43 +97|98 +97|86 +97|46 +97|16 +97|72 +97|49 +97|68 +97|26 +97|66 +97|58 +97|28 +97|22 +97|11 +97|61 +97|62 +97|18 +64|86 +64|22 +64|97 +64|18 +64|73 +64|39 +64|43 +64|26 +64|66 +64|58 +64|89 +64|46 +64|13 +64|62 +64|25 +64|68 +64|15 +64|72 +64|99 +55|26 +55|43 +55|99 +55|74 +55|86 +55|16 +55|89 +55|49 +55|97 +55|23 +55|64 +55|62 +55|25 +55|72 +55|39 +55|54 +55|58 +55|22 +55|73 +55|18 +73|16 +73|28 +73|89 +73|97 +73|25 +73|61 +73|54 +73|68 +73|43 +73|86 +73|18 +73|22 +73|58 +73|15 +73|49 +73|11 +73|72 +73|62 +73|26 +73|66 +73|13 +89|39 +89|66 +89|13 +89|62 +89|99 +89|75 +89|49 +89|16 +89|25 +89|15 +89|53 +89|98 +89|26 +89|46 +89|96 +89|72 +89|86 +89|11 +89|68 +89|43 +89|61 +89|54 +52|54 +52|55 +52|89 +52|66 +52|13 +52|11 +52|25 +52|64 +52|72 +52|74 +52|22 +52|18 +52|23 +52|97 +52|99 +52|39 +52|86 +52|62 +52|14 +52|49 +52|58 +52|73 +52|16 +18|99 +18|13 +18|35 +18|62 +18|53 +18|54 +18|28 +18|65 +18|86 +18|96 +18|49 +18|61 +18|16 +18|39 +18|15 +18|68 +18|43 +18|26 +18|98 +18|46 +18|25 +18|66 +18|75 +18|72 +66|96 +66|15 +66|98 +66|46 +66|35 +66|75 +66|92 +66|86 +66|51 +66|43 +66|83 +66|31 +66|53 +66|49 +66|39 +66|42 +66|84 +66|13 +66|28 +66|95 +66|61 +66|68 +66|54 +66|65 +74|16 +74|97 +74|73 +74|13 +74|54 +74|86 +74|26 +74|22 +74|25 +74|99 +74|66 +74|39 +74|72 +74|46 +74|11 +74|62 +74|23 +74|89 +74|18 +74|58 +74|49 +74|15 +74|64 +74|43 +95|64 +95|31 +95|97 +95|92 +95|11 +95|89 +95|12 +95|58 +95|16 +95|45 +95|52 +95|73 +95|84 +95|14 +95|72 +95|88 +95|23 +95|74 +95|55 +95|25 +95|22 +95|34 +95|18 +95|27 +27|62 +27|52 +27|64 +27|45 +27|11 +27|14 +27|12 +27|16 +27|97 +27|88 +27|66 +27|89 +27|22 +27|34 +27|73 +27|55 +27|25 +27|18 +27|74 +27|99 +27|72 +27|58 +27|23 +27|26 +14|15 +14|66 +14|64 +14|55 +14|86 +14|54 +14|58 +14|73 +14|25 +14|99 +14|13 +14|22 +14|16 +14|26 +14|89 +14|97 +14|39 +14|49 +14|62 +14|23 +14|11 +14|18 +14|72 +14|74 +96|83 +96|95 +96|35 +96|34 +96|45 +96|23 +96|97 +96|74 +96|84 +96|55 +96|88 +96|51 +96|14 +96|64 +96|31 +96|92 +96|27 +96|42 +96|12 +96|22 +96|73 +96|52 +96|65 +96|53 +75|84 +75|83 +75|65 +75|27 +75|74 +75|53 +75|88 +75|23 +75|97 +75|14 +75|92 +75|34 +75|64 +75|35 +75|51 +75|31 +75|96 +75|55 +75|52 +75|42 +75|45 +75|95 +75|73 +75|12 +13|15 +13|39 +13|98 +13|86 +13|65 +13|68 +13|61 +13|46 +13|84 +13|95 +13|28 +13|42 +13|92 +13|75 +13|53 +13|51 +13|35 +13|31 +13|43 +13|54 +13|34 +13|96 +13|27 +13|83 +49|42 +49|46 +49|95 +49|13 +49|83 +49|43 +49|54 +49|53 +49|39 +49|65 +49|86 +49|27 +49|92 +49|75 +49|31 +49|98 +49|68 +49|28 +49|96 +49|61 +49|35 +49|51 +49|84 +49|15 +45|49 +45|16 +45|11 +45|55 +45|99 +45|22 +45|58 +45|97 +45|73 +45|62 +45|74 +45|14 +45|66 +45|72 +45|25 +45|18 +45|13 +45|64 +45|26 +45|52 +45|86 +45|23 +45|89 +45|12 +42|88 +42|14 +42|74 +42|55 +42|51 +42|22 +42|34 +42|58 +42|92 +42|12 +42|52 +42|95 +42|31 +42|18 +42|83 +42|84 +42|97 +42|27 +42|45 +42|11 +42|64 +42|73 +42|89 +42|23 +35|55 +35|42 +35|58 +35|14 +35|95 +35|88 +35|52 +35|31 +35|12 +35|92 +35|51 +35|83 +35|34 +35|27 +35|89 +35|97 +35|64 +35|84 +35|11 +35|73 +35|74 +35|23 +35|22 +35|45 +51|45 +51|11 +51|97 +51|74 +51|12 +51|92 +51|83 +51|55 +51|14 +51|89 +51|22 +51|25 +51|27 +51|52 +51|84 +51|23 +51|34 +51|18 +51|95 +51|58 +51|64 +51|73 +51|31 +51|88 +11|65 +11|16 +11|61 +11|13 +11|99 +11|39 +11|28 +11|43 +11|66 +11|54 +11|26 +11|98 +11|62 +11|49 +11|53 +11|15 +11|96 +11|68 +11|72 +11|86 +11|18 +11|25 +11|75 +11|46 +26|13 +26|65 +26|54 +26|28 +26|35 +26|86 +26|42 +26|96 +26|43 +26|66 +26|15 +26|68 +26|51 +26|95 +26|92 +26|49 +26|53 +26|83 +26|75 +26|46 +26|39 +26|84 +26|61 +26|98 +53|22 +53|65 +53|97 +53|95 +53|74 +53|45 +53|84 +53|12 +53|34 +53|35 +53|73 +53|52 +53|27 +53|88 +53|23 +53|14 +53|31 +53|55 +53|92 +53|51 +53|64 +53|58 +53|83 +53|42 +12|13 +12|97 +12|66 +12|49 +12|55 +12|16 +12|23 +12|26 +12|86 +12|14 +12|18 +12|52 +12|11 +12|89 +12|62 +12|99 +12|22 +12|54 +12|74 +12|58 +12|73 +12|25 +12|64 +12|72 +92|23 +92|27 +92|25 +92|22 +92|18 +92|34 +92|11 +92|89 +92|88 +92|55 +92|97 +92|52 +92|72 +92|62 +92|12 +92|74 +92|31 +92|45 +92|73 +92|14 +92|16 +92|58 +92|99 +92|64 +62|98 +62|26 +62|39 +62|96 +62|49 +62|95 +62|53 +62|65 +62|54 +62|51 +62|61 +62|42 +62|66 +62|46 +62|15 +62|83 +62|43 +62|35 +62|86 +62|68 +62|75 +62|13 +62|84 +62|28 +22|86 +22|98 +22|18 +22|54 +22|99 +22|61 +22|75 +22|13 +22|28 +22|25 +22|72 +22|43 +22|16 +22|58 +22|49 +22|11 +22|26 +22|66 +22|15 +22|68 +22|89 +22|39 +22|46 +22|62 +28|84 +28|96 +28|42 +28|65 +28|95 +28|45 +28|64 +28|98 +28|61 +28|31 +28|52 +28|27 +28|92 +28|55 +28|14 +28|34 +28|74 +28|53 +28|35 +28|51 +28|75 +28|88 +28|12 +28|83 +72|53 +72|96 +72|39 +72|42 +72|43 +72|35 +72|86 +72|54 +72|51 +72|62 +72|65 +72|46 +72|83 +72|28 +72|66 +72|26 +72|75 +72|68 +72|13 +72|99 +72|61 +72|98 +72|49 +72|15 +83|45 +83|92 +83|64 +83|14 +83|97 +83|31 +83|73 +83|88 +83|22 +83|16 +83|95 +83|27 +83|12 +83|84 +83|55 +83|74 +83|18 +83|11 +83|25 +83|89 +83|34 +83|23 +83|58 +83|52 +31|52 +31|64 +31|14 +31|74 +31|88 +31|72 +31|27 +31|58 +31|26 +31|23 +31|99 +31|11 +31|45 +31|89 +31|73 +31|34 +31|12 +31|16 +31|55 +31|22 +31|97 +31|25 +31|62 +31|18 +15|61 +15|88 +15|84 +15|28 +15|96 +15|95 +15|35 +15|27 +15|53 +15|51 +15|45 +15|52 +15|75 +15|42 +15|65 +15|12 +15|83 +15|68 +15|34 +15|46 +15|43 +15|31 +15|98 +15|92 +46|34 +46|84 +46|52 +46|95 +46|83 +46|55 +46|61 +46|28 +46|65 +46|31 +46|98 +46|42 +46|12 +46|75 +46|92 +46|45 +46|35 +46|96 +46|51 +46|27 +46|68 +46|88 +46|14 +25|53 +25|26 +25|46 +25|49 +25|54 +25|35 +25|61 +25|98 +25|75 +25|68 +25|15 +25|99 +25|86 +25|72 +25|28 +25|65 +25|13 +25|62 +25|39 +25|96 +25|42 +25|16 +43|45 +43|52 +43|96 +43|53 +43|12 +43|51 +43|92 +43|98 +43|83 +43|46 +43|84 +43|68 +43|42 +43|88 +43|31 +43|75 +43|14 +43|27 +43|95 +43|34 +43|28 +54|95 +54|84 +54|43 +54|39 +54|45 +54|27 +54|35 +54|51 +54|42 +54|31 +54|75 +54|61 +54|34 +54|65 +54|88 +54|68 +54|96 +54|98 +54|53 +54|28 +84|27 +84|64 +84|34 +84|58 +84|73 +84|31 +84|97 +84|72 +84|52 +84|99 +84|14 +84|22 +84|55 +84|12 +84|45 +84|92 +84|25 +84|18 +84|89 +16|42 +16|39 +16|51 +16|98 +16|75 +16|53 +16|13 +16|35 +16|62 +16|54 +16|86 +16|49 +16|96 +16|26 +16|43 +16|15 +16|68 +16|72 +86|28 +86|15 +86|65 +86|46 +86|98 +86|43 +86|39 +86|42 +86|84 +86|83 +86|68 +86|96 +86|51 +86|54 +86|75 +86|92 +86|53 +61|31 +61|64 +61|42 +61|65 +61|52 +61|96 +61|95 +61|75 +61|12 +61|83 +61|98 +61|23 +61|27 +61|14 +61|35 +61|53 +23|22 +23|13 +23|26 +23|86 +23|16 +23|46 +23|28 +23|25 +23|11 +23|15 +23|73 +23|68 +23|62 +23|49 +23|72 +68|28 +68|53 +68|34 +68|65 +68|35 +68|45 +68|88 +68|83 +68|84 +68|31 +68|27 +68|52 +68|95 +68|61 +98|88 +98|27 +98|75 +98|53 +98|52 +98|35 +98|83 +98|14 +98|64 +98|12 +98|84 +98|65 +98|95 +58|16 +58|96 +58|13 +58|46 +58|11 +58|62 +58|89 +58|49 +58|72 +58|39 +58|15 +58|99 +99|54 +99|43 +99|46 +99|75 +99|95 +99|28 +99|83 +99|68 +99|42 +99|62 +99|13 +39|61 +39|98 +39|95 +39|28 +39|43 +39|46 +39|27 +39|68 +39|96 +39|31 +34|58 +34|18 +34|52 +34|25 +34|64 +34|22 +34|11 +34|49 +34|97 +65|74 +65|95 +65|31 +65|51 +65|88 +65|52 +65|23 +65|84 +88|99 +88|11 +88|55 +88|25 +88|14 +88|74 +88|45 +97|89 +97|15 +97|99 +97|54 +97|25 +97|13 +64|16 +64|11 +64|23 +64|54 +64|49 +55|15 +55|66 +55|11 +55|13 +73|99 +73|46 +73|39 +89|18 +89|28 +52|26 + +97,58,11,72,99,62,13,86,54,39,43,46,68,28,61 +74,64,23,73,97,22,58,89,11,25,72,99,62,26,66,49,13,86,39,15,43 +96,35,42,95,92,12,74,64,97 +74,23,97,58,89,11,18,25,16,72,99,62,26,66,49,13,86,54,39,15,43 +12,72,52,14,23,62,49,89,11,66,45,25,22,18,13 +64,25,11,14,62,99,55,26,97,74,34,22,66,58,73 +26,49,13,86,54,39,28,61,96,35,42,51,83,95,84 +66,49,13,86,39,15,43,46,68,28,61,75,96,53,65,35,42,51,95,84,92 +64,58,89,25,99,62,86,39,46 +68,28,61,98,75,96,65,35,51,95,84,92,27,34,88,45,12 +25,62,49,15,28,65,35 +84,92,31,27,34,88,45,12,52,14,55,74,73,97,22,58,89 +51,88,14,64,84,58,83,34,22,27,92,55,12,42,95,74,73,65,97,35,31,45,23 +52,45,66,74,55,64,34,16,58 +26,13,68,61,98,75,96,42,84 +74,64,23,73,25,16,72,26,49,86,54,15,43 +73,99,26,72,62 +61,98,96,53,42,51,83,84,31,27,34,88,45,12,55,74,64 +16,72,99,26,66,49,13,54,39,15,43,46,68,28,75,53,65,35,42 +97,73,15,39,72,54,25,28,16,66,68 +12,25,74,99,14,34,45 +89,11,18,25,16,72,99,62,26,66,49,13,86,54,39,15,46,68,28,61,98,75,96 +88,12,73,22,31,16,84,18,34,23,11,72,45,55,27,14,74,89,92,64,97,58,52 +53,65,42,51,83,84,92,27,12,52,55,74,22 +64,97,86,26,49,23,22,14,73,16,11,13,89,99,18 +89,11,18,25,16,72,26,13,54,39,43,28,98,75,96 +99,64,11,34,58,72,25,74,18,26,97,23,45,12,88,55,89,14,66,62,16,52,22 +86,54,39,15,43,46,68,28,61,98,75,96,53,65,35,42,51,83,84,92,31,27,34 +11,73,12,95,89,88,45,16,23,34,74,97,22,18,31,92,64,84,55 +68,25,46,65,61,86,96,15,35 +99,66,49,13,86,54,39,15,43,61,98,75,96,53,65,35,42,51,83 +31,42,14,95,84,97,51,27,45,88,55,64,96,34,73,53,12,74,65,35,83,92,23 +95,52,96,53,27,51,14,75,42,98,23,34,88,74,55,84,65,12,31 +27,16,12,99,25,89,55,62,14,52,18,23,97,22,31,11,72,34,64,73,58 +23,42,51,27,65,34,74,88,96,83,95,52,55,31,64 +23,97,22,58,89,11,18,16,72,99,62,26,66,13,54,39,43,46,68 +12,52,74,23,73,97,22,58,11,18,16,72,99,62,49,13,86 +49,73,43,25,86,22,89,54,62,16,15,39,11,72,13,18,64 +89,11,18,25,16,72,99,26,66,49,13,86,54,39,15,43,46,68,28,61,98,75,96 +73,97,22,89,11,18,25,16,72,99,62,66,49,13,86,54,39,43,46 +42,92,34,23,73 +98,75,96,53,65,35,42,51,83,84,92,31,27,34,88,45,12,52,14,55,74,64,23 +66,49,86,62,96,72,46,43,68,53,99,35,28,51,15 +58,72,86,66,49,18,25,89,61,22,68,62,13,98,26,54,99,46,15,39,11,16,43 +13,42,61,49,68,86,31,83,92 +64,52,86,14,66,72,89,11,54 +34,89,14,74,55,73,72,25,16,18,11,58,92 +62,26,49,54,15,43,61,98,75,96,42,51,95 +99,13,22,72,46,54,39,28,15,89,62,11,18,25,73,26,66 +14,27,34,72,84,16,55 +18,72,26,13,46,68,28,75,96,53,65 +46,68,75,96,53,42,83,95,84,34,88,45,12,52,14 +49,97,18,58,25,13,89,68,54,43,73,16,11,99,23,62,86,72,15 +86,42,51,61,43,83,92,53,46,98,68,15,75,96,34,84,35 +58,11,92,34,14,45,31,25,23,64,97,95,84,73,55 +25,26,68,98,43,28,16,66,15,54,22,13,46,61,89 +75,96,53,65,35,42,51,83,95,84,92,31,27,34,88,45,12,52,14,55,64,23,73 +12,52,14,55,74,64,23,73,97,22,58,11,25,16,72,62,26,49,86 +31,95,45,22,23,73,88,58,34,12,97 +28,98,42,46,27,53,83,88,92,12,35,84,96,61,95,14,45 +35,55,12,52,96,97,14 +96,92,12,34,75,52,27,84,73,55,14,83,23,51,95,64,74,53,65,31,42 +23,16,88,89,64,22,72,99,31,74,11 +89,99,54,22,18,72,13,58,62,39,16,15,11,66,43 +83,95,84,92,31,27,34,88,45,12,52,14,55,74,64,23,73,97,22,58,89,11,25 +46,51,84,92,13,27,35 +45,12,11,25,72,49,13 +35,65,55,12,68,31,45,98,51,61,14 +42,83,84,31,27,34,88,45,12,52,14,64,97,89,11 +83,43,27,39,35,98,28,53,75,92,46,68,95,31,51,86,42,13,54,84,61 +89,11,25,16,62,26,54,46,28,98,96 +11,16,99,62,26,66,49,86,54,39,15,43,46,68,61,98,75,96,53 +46,61,96,42,95 +15,43,58,61,26,99,18,97,72 +43,68,28,35,51,84,34,88,52 +18,16,72,99,62,26,49,13,54,39,43,46,68,28,75,53,65 +54,68,35,49,72,53,15,61,98,51,13,99,66 +61,53,65,35,51,83,31,27,34,88,12,14,55,74,64 +55,74,73,97,22,89,25,16,99,62,66,13,86,54,15 +13,86,46,75,96,65,83,92,27 +88,75,12,15,51,28,83,46,43,35,42,53,98,68,27,65,61 +51,62,28,46,15,68,53,99,75,49,72,96,39,61,42,65,66 +75,53,51,43,98,99,15,66,72,46,49 +35,42,51,83,95,84,92,31,34,88,45,12,52,14,55,74,64,23,73,97,22,58,89 +74,62,99,22,58,14,16,18,89,31,55,72,27,88,23,45,11,12,34 +28,46,45,68,51,88,35,39,31,42,95 +42,97,92,14,53,45,55,51,83,65,84,95,73,22,35 +68,96,54,53,42,46,15,13,66,98,28,26,39 +58,89,11,18,25,16,72,99,62,26,66,49,13,86,54,39,15,46,68,28,61,98,75 +96,15,42,35,26,99,75,39,72,13,53 +68,39,62,58,11,89,99,54,61,22,66,49,72,25,43,98,46,13,26,28,86,16,18 +31,88,45,14,74,25,16,99,62 +23,97,58,89,11,72,62,26,49,13,43,46,68 +58,73,64,34,12,31,84,14,27,22,35,55,65 +28,51,61,45,88,68,15,53,98,95,96,75,42,46,34,31,27,35,65,83,92,12,84 +92,34,14,74,97,22,89,16,99 +83,95,12,89,74 +53,28,86,66,15,49,61,25,96,13,46,72,62,54,11 +64,22,86,43,99,18,54,25,23,66,72,73,89,46,15,97,11,62,13 +66,45,64,74,58,97,52,73,25,16,99,49,62,18,22,23,88 +53,35,51,84,31,27,34,55,73,97,22 +15,53,61,51,83,68,75,28,39,86,65,92,42,27,98,95,84 +42,68,61,88,14,75,52,53,95,84,46,98,96 +26,72,14,88,25,66,34 +34,96,95,74,55 +46,49,68,15,13,98,28,72,54,35,96,42,26 +52,64,23,73,18,16,26,66,13 +62,26,66,49,13,86,54,39,15,46,68,28,61,98,75,96,53,65,35,42,51,83,95 +61,98,75,65,51,83,95,84,92,31,34,88,45,12,52,74,64 +83,12,95,52,53,14,22,64,45,35,74,97,42,51,73,34,65 +86,11,49,97,62,55,64,18,73 +73,97,22,18,25,16,99,66,13,86,15,46,28 +88,45,12,52,14,55,74,64,97,22,18,72,99,62,26,66,49 +16,72,49,54,98 +52,14,64,62,12,97,34,45,58,73,72,11,22,55,31 +55,83,34,73,64,75,95 +64,89,51,74,31,22,92,45,27,97,11 +18,49,86,43,98,96,65 +31,97,14,11,34,23,58,27,62,45,64,52,16,12,74,72,89,55,25 +64,12,34,25,27,83,18 +64,86,16,74,54,97,23,13,22,18,55,39,11,26,99,15,58,62,89,66,25,73,72 +18,39,28,26,15,98,54,43,61,62,89,75,99,58,16,66,49 +28,27,31,98,61,96,46,83,45,15,34 +12,84,83,14,74,31,92,97,96,55,95 +12,28,51,15,34,88,27,31,75,45,43,68,42 +68,28,75,96,65,35,42,51,83,84,92,27,12,52,55 +96,35,88,92,65,15,98,39,84,54,83,46,75,68,51 +46,68,28,61,98,75,96,65,35,42,51,83,95,84,92,31,27,34,88,12,14 +54,15,96,46,43,42,26,99,13,61,98,49,86,72,68,53,28,66,16 +43,26,62,39,11,49,54,89,13,28,15 +45,84,98,15,27,34,31,35,53,51,42,75,12,61,95,65,96,92,83,46,88 +97,58,11,25,16,62,26,66,49,86,54,39,43,46,68,28,61 +52,23,97,22,11,25,54 +18,25,72,99,62,26,66,49,86,54,39,15,43,68,98,75,96 +61,97,13,66,15,72,39,28,18,46,54,43,68,26,86,22,99,62,89,58,16 +68,96,35,51,83,84,31,45,12,52,55 +53,65,35,42,83,95,92,31,45,12,52,14,74,64,23,97,22 +97,52,83,22,25,58,64 +61,42,98,88,31,92,51,54,84,68,95,39,65,46,83,28,75 +14,64,23,22,89,11,25,72,99,62,26,49,13,54,39 +73,86,49,39,14,72,99,22,25,23,16,74,62,89,64,58,54,13,97,55,66 +49,16,97,26,13,15,89,28,86,66,43,62,22,73,68,11,54 +95,53,35,86,42 +25,66,49,39,43,98,35 +65,35,42,92,31,27,88,12,64,97,58 +42,51,95,84,92,34,88,45,55,74,64,23,73,22,11 +62,49,25,46,16 +46,96,65,51,12,52,88,42,14 +11,72,99,66,46 +11,18,25,72,99,62,26,49,86,15,46,96,53 +51,65,28,92,88,98,43,61,42,96,54 +95,54,35,34,27,86,39,83,92,15,96 +66,15,98,26,46,39,28,83,54,49,35,61,51,53,86 +34,42,43,28,61,65,68,83,12,92,15,98,95 +74,97,22,89,11,16,99,49,39,15,43 +15,46,28,61,98,75,96,53,65,35,42,51,95,84,92,27,88,45,12 +46,26,53,54,18,68,11,13,98,99,25,39,16,61,49,62,72,15,86,28,66 +18,99,62,86,39,46,68,28,61,53,65 +14,51,96,92,95,53,35,55,27,84,42,75,64,74,52,65,88,45,61 +26,49,86,28,35,95,84 +55,22,58,18,66,49,13,86,54,39,15 +13,86,15,75,35,83,95,84,92 +14,74,64,72,62,26,39 +84,92,34,88,45,14,55,73,97,89,11,25,72 +72,99,62,26,66,49,54,39,15,43,68,61,75,53,65,35,42 +88,45,12,52,14,55,74,64,23,73,97,22,58,89,11,18,25,16,72,99,62,26,49 +14,74,64,23,73,97,22,58,89,11,18,25,16,72,99,62,26,66,49,13,86,54,39 +11,18,25,16,49,13,54,15,98,96,53 +14,64,52,12,55,11,89,51,18 +16,72,99,66,49,86,54,15,43,68,28,98,96,53,65,35,42 +65,75,53,99,46,42,28,61,66,68,86,54,43,39,13 +18,39,13,72,62,55,23,22,64,14,26,49,58,66,11,74,97 +72,11,86,89,15,99,55,97,73,25,16,13,58,18,49,23,54 +92,28,27,95,13,46,68,42,75 +83,61,15,99,46,86,35,68,53 +83,95,92,31,34,45,12,52,14,55,64,23,97,22,58,89,11,18,25 +88,12,52,14,97,22,89,72,62,26,49 +86,84,96,42,28 +92,27,34,45,12,14,55,74,64,23,73,97,22,58,89,11,18,16,99 +28,61,98,53,65,51,84,34,88,45,74 +88,14,89,22,97,23,84,83,73,58,12,55,27 +61,43,28,98,31,84,52 +75,96,88,84,27,46,28,34,35,83,42,65,98,61,68,31,54,53,43 +15,18,16,72,62,22,25,99,54 +98,54,13,66,86,62,25,35,99,26,68,43,53 +86,54,46,28,75,35,51,92,31,27,34 +26,66,13,86,39,43,61,53,83 +23,97,58,11,18,72,49,86,54,46,68 +35,42,51,83,95,84,92,31,27,34,88,45,12,52,55,74,64,23,73,97,22,58,89 +83,84,98,86,95,65,26 +97,55,22,11,23,45,88,18,84,72,92,73,74,16,58,64,34 +83,95,84,92,31,27,34,88,45,12,52,14,55,74,64,23,73,22,58,89,11,18,25 +97,18,72,99,62,13,86 +28,13,89,98,96,16,49 +14,27,26,73,55,18,34,72,99,45,52,23,74,88,58,25,97,22,12,89,62 +18,25,16,72,99,62,26,66,49,13,86,54,39,15,43,46,68,28,98,75,96,53,65 +58,89,11,18,72,62,26,66,54,39,15,68,61,98,75 +68,72,11,39,58,25,54,86,61,49,75 +98,54,39,28,26,18,11,22,68,43,62,66,86 +45,99,73,97,58,92,89,25,11,14,52,74,23,27,88 +45,12,55,74,64,23,73,97,58,18,25,16,72,99,62,66,13 +27,22,14,84,73,95,58 +64,34,95,88,11,12,14,97,83,73,55 +89,11,45,31,73,14,97,34,58,92,55,51,64,22,23,27,74,84,52,12,95,83,88 +52,97,83,92,22,35,55,51,84,88,27,23,89 +88,42,27,55,84,14,95,98,96,65,74,83,51,34,61,53,12,45,28 +64,45,12,14,22,74,95,97,92,52,31,18,55,25,23,27,34,16,58 +26,51,49,54,75,28,98,42,62,61,46,53,66,96,68,39,43,13,83,65,86 +27,97,52,72,73,64,26,25,16,18,74 +27,52,74,23,73,97,22,58,89,11,18,25,16,72,99,62,26 diff --git a/2024/5/data_test.txt b/2024/5/data_test.txt new file mode 100644 index 0000000..9d146d6 --- /dev/null +++ b/2024/5/data_test.txt @@ -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/2024/5/main.cpp b/2024/5/main.cpp new file mode 100644 index 0000000..c1accf9 --- /dev/null +++ b/2024/5/main.cpp @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + const std::string filename = "data.txt"; + std::ifstream ifs(filename); + if(!ifs.is_open()) + { + std::cerr << "Missing " << filename << "." << std::endl; + return -1; + } + + unsigned long total = 0; + unsigned long total_pt2 = 0; + + std::map> rules; + std::vector> production; + + bool reading_page_numbers = true; + for(std::string line; std::getline(ifs, line); ) + { + if(line == "") + { + // one blank line is the break between reading page numbers and records. + if(reading_page_numbers) + reading_page_numbers = false; + + continue; + } + + std::istringstream input(line); + if(reading_page_numbers) + { + // for each value in the line: + std::vector numbers; + for(std::string value; std::getline(input, value, '|'); ) + { + try { + numbers.push_back(std::atoi(value.c_str())); + } catch (const std::exception &e) { + std::cout << "Error parsing rule number from " << value << std::endl; + exit(-1); + } + } + if(numbers.size() != 2) + { + std::cout << "Error: Incorrect amount of page numbers (" << numbers.size() + << ") in rules import sequence." << std::endl; + exit(-1); + } + rules[numbers[0]].insert(numbers[1]); + } + else + { + // for each value in the line: + production.push_back({}); + for(std::string value; std::getline(input, value, ','); ) + { + try { + production.back().push_back(std::atoi(value.c_str())); + } catch (const std::exception &e) { + std::cout << "Error parsing production number from " << value << std::endl; + exit(-1); + } + } + } + } + + // // Debug: + // std::cout << "RULES:" << std::endl; + // for(auto rule : rules) + // { + // std::cout << rule.first << " prints before "; + // for(auto page : rule.second) + // std::cout << page << ","; + // std::cout << std::endl; + // } + // std::cout << std::endl; + // std::cout << "PRODUCTION:" << std::endl; + // for(auto row : production) + // { + // for(auto num : row) + // std::cout << num << ","; + // std::cout << std::endl; + // } + + // For each production run: + for(auto row : production) + { + std::set already_passed; + bool bad = false; + // For each page number in that production run: + for(auto num : row) + { + // Check against all page numbers it shouldn't print after + for(auto before : rules[num]) + { + // If found, it's a bad row! + if(std::find(already_passed.begin(), already_passed.end(), before) != already_passed.end()) + { + bad = true; + break; + } + } + + // Keep track of numbers we've looked at already: + already_passed.insert(num); + } + + if(!bad) + total += row[row.size() / 2]; + // else + // std::cout << "not "; + // std::cout << "safe: "; + // for(auto num : row) + // std::cout << num << ","; + // std::cout << std::endl; + } + + std::cout << " Total: " << total << std::endl; + std::cout << "PT2 Total: " << total_pt2 << std::endl; + + return 0; +}