From f194574da474c45fc34e4855c68b289a9e3bdf6d Mon Sep 17 00:00:00 2001 From: 0x01FE Date: Thu, 5 Dec 2024 09:50:13 -0600 Subject: [PATCH] solved day5 --- 2024/day5/input.text | 1386 ++++++++++++++++++++++++++++++++++++++++++ 2024/day5/main.py | 85 +++ 2024/day5/test.text | 28 + 3 files changed, 1499 insertions(+) create mode 100644 2024/day5/input.text create mode 100644 2024/day5/main.py create mode 100644 2024/day5/test.text diff --git a/2024/day5/input.text b/2024/day5/input.text new file mode 100644 index 0000000..433c5d2 --- /dev/null +++ b/2024/day5/input.text @@ -0,0 +1,1386 @@ +93|48 +45|93 +45|22 +29|13 +29|86 +29|79 +32|98 +32|22 +32|28 +32|16 +86|26 +86|11 +86|18 +86|83 +86|66 +22|77 +22|24 +22|95 +22|91 +22|53 +22|98 +67|22 +67|86 +67|36 +67|95 +67|76 +67|35 +67|65 +91|32 +91|97 +91|33 +91|62 +91|78 +91|77 +91|48 +91|18 +28|94 +28|79 +28|93 +28|53 +28|35 +28|71 +28|25 +28|84 +28|36 +18|53 +18|29 +18|76 +18|79 +18|71 +18|34 +18|98 +18|22 +18|25 +18|93 +13|48 +13|16 +13|17 +13|26 +13|74 +13|62 +13|83 +13|99 +13|23 +13|94 +13|18 +97|89 +97|35 +97|93 +97|98 +97|79 +97|53 +97|29 +97|51 +97|16 +97|14 +97|24 +97|74 +24|48 +24|65 +24|85 +24|83 +24|51 +24|21 +24|17 +24|99 +24|92 +24|32 +24|44 +24|86 +24|88 +17|16 +17|99 +17|44 +17|35 +17|66 +17|74 +17|26 +17|34 +17|25 +17|33 +17|21 +17|85 +17|14 +17|23 +51|11 +51|18 +51|85 +51|62 +51|59 +51|89 +51|32 +51|78 +51|21 +51|44 +51|86 +51|33 +51|23 +51|77 +51|91 +16|74 +16|86 +16|92 +16|79 +16|34 +16|65 +16|53 +16|89 +16|29 +16|84 +16|25 +16|51 +16|22 +16|98 +16|71 +16|76 +99|33 +99|26 +99|34 +99|23 +99|45 +99|28 +99|32 +99|14 +99|74 +99|62 +99|18 +99|44 +99|93 +99|97 +99|76 +99|67 +99|94 +77|28 +77|33 +77|62 +77|13 +77|94 +77|85 +77|78 +77|21 +77|74 +77|44 +77|97 +77|18 +77|59 +77|26 +77|67 +77|66 +77|83 +77|99 +84|51 +84|53 +84|26 +84|83 +84|99 +84|88 +84|79 +84|17 +84|86 +84|59 +84|91 +84|24 +84|78 +84|65 +84|23 +84|48 +84|77 +84|71 +84|62 +59|94 +59|32 +59|44 +59|97 +59|83 +59|99 +59|18 +59|78 +59|13 +59|26 +59|48 +59|85 +59|45 +59|88 +59|17 +59|74 +59|23 +59|21 +59|28 +59|33 +89|13 +89|44 +89|33 +89|77 +89|48 +89|28 +89|65 +89|86 +89|23 +89|91 +89|66 +89|17 +89|99 +89|62 +89|59 +89|85 +89|32 +89|78 +89|83 +89|21 +89|26 +74|53 +74|89 +74|98 +74|86 +74|25 +74|51 +74|92 +74|84 +74|76 +74|67 +74|36 +74|24 +74|29 +74|93 +74|79 +74|22 +74|14 +74|11 +74|34 +74|65 +74|45 +74|35 +66|16 +66|93 +66|24 +66|95 +66|14 +66|74 +66|29 +66|22 +66|34 +66|97 +66|67 +66|18 +66|76 +66|35 +66|45 +66|84 +66|98 +66|71 +66|33 +66|53 +66|25 +66|28 +66|94 +34|59 +34|91 +34|24 +34|65 +34|29 +34|95 +34|11 +34|79 +34|86 +34|71 +34|89 +34|98 +34|76 +34|92 +34|48 +34|77 +34|51 +34|13 +34|36 +34|35 +34|93 +34|83 +34|84 +34|53 +92|51 +92|83 +92|17 +92|62 +92|21 +92|26 +92|23 +92|78 +92|44 +92|32 +92|65 +92|86 +92|13 +92|79 +92|77 +92|85 +92|91 +92|48 +92|88 +92|11 +92|99 +92|66 +92|59 +92|89 +35|93 +35|95 +35|71 +35|86 +35|84 +35|98 +35|11 +35|92 +35|29 +35|79 +35|76 +35|24 +35|88 +35|51 +35|13 +35|77 +35|89 +35|36 +35|48 +35|91 +35|59 +35|53 +35|83 +35|65 +83|14 +83|78 +83|88 +83|17 +83|16 +83|26 +83|85 +83|97 +83|99 +83|33 +83|45 +83|62 +83|22 +83|23 +83|18 +83|44 +83|28 +83|32 +83|25 +83|74 +83|94 +83|21 +83|66 +83|67 +48|17 +48|83 +48|16 +48|14 +48|45 +48|33 +48|66 +48|21 +48|97 +48|67 +48|23 +48|28 +48|62 +48|94 +48|32 +48|74 +48|44 +48|78 +48|26 +48|88 +48|25 +48|85 +48|18 +48|99 +76|83 +76|79 +76|92 +76|36 +76|11 +76|86 +76|13 +76|51 +76|95 +76|29 +76|78 +76|89 +76|65 +76|77 +76|98 +76|84 +76|59 +76|88 +76|24 +76|91 +76|17 +76|71 +76|48 +76|53 +79|78 +79|32 +79|99 +79|86 +79|33 +79|83 +79|13 +79|17 +79|65 +79|51 +79|26 +79|11 +79|62 +79|89 +79|21 +79|44 +79|77 +79|66 +79|23 +79|88 +79|91 +79|48 +79|85 +79|59 +95|98 +95|59 +95|71 +95|13 +95|83 +95|51 +95|48 +95|77 +95|24 +95|65 +95|79 +95|89 +95|29 +95|36 +95|92 +95|84 +95|17 +95|53 +95|78 +95|86 +95|91 +95|85 +95|11 +95|88 +85|23 +85|97 +85|14 +85|62 +85|16 +85|26 +85|34 +85|76 +85|99 +85|44 +85|18 +85|74 +85|66 +85|35 +85|94 +85|25 +85|33 +85|21 +85|67 +85|45 +85|32 +85|22 +85|28 +85|93 +14|53 +14|24 +14|59 +14|84 +14|35 +14|89 +14|95 +14|29 +14|11 +14|86 +14|79 +14|36 +14|91 +14|98 +14|51 +14|71 +14|22 +14|77 +14|93 +14|76 +14|65 +14|25 +14|92 +14|34 +44|18 +44|71 +44|34 +44|97 +44|25 +44|22 +44|53 +44|74 +44|93 +44|98 +44|66 +44|95 +44|35 +44|94 +44|67 +44|28 +44|76 +44|36 +44|84 +44|45 +44|16 +44|14 +44|33 +44|29 +98|92 +98|88 +98|48 +98|24 +98|79 +98|36 +98|78 +98|71 +98|77 +98|83 +98|99 +98|13 +98|11 +98|51 +98|91 +98|59 +98|53 +98|65 +98|89 +98|85 +98|29 +98|86 +98|84 +98|17 +94|84 +94|98 +94|93 +94|79 +94|35 +94|95 +94|29 +94|74 +94|22 +94|71 +94|89 +94|14 +94|24 +94|97 +94|34 +94|45 +94|67 +94|16 +94|36 +94|25 +94|92 +94|51 +94|53 +94|76 +78|33 +78|18 +78|35 +78|85 +78|26 +78|14 +78|99 +78|22 +78|28 +78|67 +78|66 +78|21 +78|16 +78|97 +78|34 +78|44 +78|93 +78|23 +78|94 +78|62 +78|45 +78|25 +78|74 +78|32 +36|99 +36|86 +36|91 +36|24 +36|11 +36|29 +36|48 +36|53 +36|13 +36|71 +36|26 +36|88 +36|65 +36|83 +36|89 +36|77 +36|92 +36|79 +36|51 +36|84 +36|59 +36|17 +36|78 +36|85 +65|48 +65|26 +65|97 +65|62 +65|94 +65|99 +65|28 +65|78 +65|23 +65|88 +65|83 +65|44 +65|59 +65|77 +65|13 +65|66 +65|32 +65|21 +65|18 +65|11 +65|33 +65|91 +65|17 +65|85 +88|21 +88|67 +88|78 +88|32 +88|94 +88|14 +88|74 +88|22 +88|16 +88|44 +88|66 +88|28 +88|17 +88|18 +88|85 +88|45 +88|26 +88|25 +88|62 +88|34 +88|23 +88|33 +88|99 +88|97 +26|74 +26|45 +26|95 +26|98 +26|14 +26|23 +26|35 +26|34 +26|66 +26|67 +26|76 +26|16 +26|25 +26|93 +26|22 +26|62 +26|33 +26|94 +26|32 +26|28 +26|97 +26|21 +26|18 +26|44 +71|77 +71|13 +71|65 +71|79 +71|48 +71|89 +71|99 +71|85 +71|32 +71|23 +71|86 +71|62 +71|91 +71|24 +71|11 +71|26 +71|59 +71|51 +71|78 +71|21 +71|83 +71|17 +71|92 +71|88 +33|92 +33|45 +33|24 +33|53 +33|94 +33|22 +33|71 +33|29 +33|95 +33|74 +33|97 +33|36 +33|18 +33|67 +33|76 +33|25 +33|35 +33|14 +33|98 +33|16 +33|93 +33|34 +33|84 +33|28 +23|18 +23|16 +23|21 +23|34 +23|94 +23|22 +23|76 +23|74 +23|32 +23|35 +23|44 +23|93 +23|62 +23|36 +23|25 +23|66 +23|95 +23|97 +23|98 +23|33 +23|14 +23|28 +23|45 +23|67 +53|78 +53|92 +53|51 +53|48 +53|77 +53|99 +53|24 +53|79 +53|59 +53|71 +53|26 +53|13 +53|86 +53|62 +53|89 +53|65 +53|17 +53|91 +53|88 +53|21 +53|85 +53|11 +53|83 +53|23 +21|16 +21|34 +21|29 +21|22 +21|45 +21|95 +21|84 +21|97 +21|94 +21|28 +21|74 +21|44 +21|14 +21|76 +21|93 +21|33 +21|25 +21|35 +21|67 +21|66 +21|18 +21|36 +21|32 +21|98 +11|59 +11|26 +11|62 +11|13 +11|16 +11|33 +11|28 +11|83 +11|17 +11|94 +11|78 +11|23 +11|18 +11|21 +11|32 +11|85 +11|91 +11|97 +11|66 +11|77 +11|48 +11|88 +11|99 +11|44 +25|98 +25|86 +25|22 +25|51 +25|95 +25|89 +25|13 +25|71 +25|36 +25|91 +25|77 +25|92 +25|35 +25|24 +25|34 +25|53 +25|59 +25|65 +25|84 +25|93 +25|11 +25|76 +25|29 +25|79 +62|32 +62|76 +62|67 +62|21 +62|35 +62|66 +62|29 +62|74 +62|18 +62|25 +62|45 +62|36 +62|22 +62|98 +62|44 +62|14 +62|95 +62|16 +62|93 +62|28 +62|34 +62|33 +62|97 +62|94 +93|13 +93|77 +93|89 +93|76 +93|36 +93|98 +93|17 +93|53 +93|79 +93|29 +93|88 +93|92 +93|91 +93|51 +93|84 +93|95 +93|24 +93|65 +93|11 +93|83 +93|59 +93|86 +93|71 +45|11 +45|84 +45|51 +45|79 +45|86 +45|76 +45|77 +45|89 +45|95 +45|65 +45|35 +45|14 +45|29 +45|71 +45|36 +45|91 +45|98 +45|24 +45|92 +45|53 +45|25 +45|34 +29|53 +29|78 +29|48 +29|88 +29|65 +29|83 +29|59 +29|99 +29|51 +29|71 +29|91 +29|89 +29|92 +29|24 +29|77 +29|85 +29|84 +29|17 +29|23 +29|26 +29|11 +32|93 +32|34 +32|29 +32|95 +32|84 +32|66 +32|18 +32|94 +32|44 +32|76 +32|14 +32|53 +32|25 +32|74 +32|45 +32|33 +32|35 +32|36 +32|67 +32|97 +86|23 +86|33 +86|77 +86|99 +86|44 +86|17 +86|94 +86|32 +86|28 +86|59 +86|65 +86|91 +86|78 +86|48 +86|21 +86|85 +86|13 +86|88 +86|62 +22|36 +22|11 +22|89 +22|84 +22|92 +22|48 +22|34 +22|51 +22|93 +22|35 +22|59 +22|13 +22|65 +22|86 +22|76 +22|29 +22|71 +22|79 +67|92 +67|89 +67|79 +67|71 +67|24 +67|91 +67|11 +67|29 +67|51 +67|53 +67|25 +67|45 +67|34 +67|84 +67|93 +67|14 +67|98 +91|21 +91|88 +91|99 +91|83 +91|26 +91|28 +91|59 +91|13 +91|16 +91|17 +91|23 +91|44 +91|66 +91|74 +91|94 +91|85 +28|29 +28|76 +28|74 +28|92 +28|16 +28|98 +28|67 +28|95 +28|34 +28|97 +28|51 +28|24 +28|22 +28|14 +28|45 +18|45 +18|94 +18|16 +18|74 +18|95 +18|92 +18|28 +18|36 +18|14 +18|84 +18|35 +18|24 +18|97 +18|67 +13|33 +13|14 +13|67 +13|66 +13|97 +13|85 +13|88 +13|28 +13|45 +13|21 +13|32 +13|44 +13|78 +97|25 +97|71 +97|34 +97|95 +97|76 +97|92 +97|22 +97|36 +97|84 +97|45 +97|67 +97|86 +24|11 +24|13 +24|26 +24|23 +24|62 +24|59 +24|78 +24|79 +24|89 +24|91 +24|77 +17|32 +17|18 +17|28 +17|45 +17|97 +17|94 +17|22 +17|67 +17|62 +17|78 +51|66 +51|13 +51|17 +51|99 +51|65 +51|88 +51|83 +51|26 +51|48 +16|45 +16|14 +16|67 +16|24 +16|35 +16|36 +16|93 +16|95 +99|16 +99|21 +99|35 +99|25 +99|22 +99|66 +99|95 +77|88 +77|48 +77|17 +77|16 +77|23 +77|32 +84|11 +84|92 +84|13 +84|89 +84|85 +59|62 +59|66 +59|16 +59|67 +89|11 +89|18 +89|88 +74|95 +74|71 +66|36 + +77,83,99,62,44,97,74 +33,18,97,16,67,14,22,93,95,36,29,84,53 +95,21,76,22,32,36,29 +11,59,77,13,86,88,99,32,23,83,26,48,91,92,51,89,65,21,62,85,17,44,79 +93,84,53,92,65,77,48,83,88 +62,32,44,18,74,67,93,76,36 +21,32,44,66,33,18,28,94,97,74,67,45,14,25,22,34,35,93,76,95,98,36,29 +45,34,28,22,66,26,85,93,18 +29,25,74,14,45,93,76,84,95,36,98,22,89,79,71,65,53,35,67,86,92 +88,97,83,23,74 +98,36,84,53,71,92,79,51,89,86,65,11,77,59,83,88,17,78,85 +92,79,51,89,86,65,11,91,59,78,99,62,44 +35,93,29,86,77 +85,99,26,23,62,21,32,44,66,33,18,28,94,97,16,74,67,45,14,25,22,35,93 +71,24,79,51,86,65,11,77,59,13,48,17,78,85,23,62,21 +34,86,92,76,53,29,79,98,36,22,25,84,71,74,65,51,45,14,93,89,67,24,35 +71,24,79,51,89,86,65,91,77,59,13,83,88,17,78,85,99,26,23,62,21 +26,23,62,21,44,18,28,94,95 +21,22,25,18,34,66,45,67,36,33,16,28,32,29,44 +32,17,65,48,26,11,23,99,13,44,62,21,94,77,88,78,28,83,91 +71,14,98,25,93,35,33,66,18,28,22,76,84,95,97,53,94,29,67,74,36,34,16 +25,35,76,95,98,29,84,71,24,92,51,89,86,65,91,77,59 +16,74,67,25,22,76,95,36,84,71,89 +35,76,95,98,36,29,84,53,71,79,51,89,65,11,91,59,13,48,83 +17,99,36,79,78,77,85,48,71 +18,74,45,97,67,34,28,32,94,14,25,84,16,33,95,22,93,98,44 +25,11,67,24,89,95,79 +95,98,36,29,53,71,92,89,86,59,83,88,78 +44,33,18,28,94,97,16,67,45,34,35,93,76,95,98,84,53 +33,28,97,16,74,67,45,14,25,22,34,35,93,76,95,98,36,84,53,71,24 +91,77,59,13,48,83,88,17,78,85,26,23,62,21,32,44,66,33,28,94,16 +17,86,65,51,11,92,76,71,59,89,91,83,84,79,48,88,24 +77,13,48,83,88,78,23,21,32,44,33,18,97,16,74 +98,36,29,84,53,71,92,79,51,89,86,65,11,91,77,59,13,48,83,88,17,78,85 +59,83,65,36,35,89,29,79,11 +95,36,71,86,91,48,83,88,17 +71,24,79,51,89,11,91,77,59,13,48,88,85,26,23,62,21 +35,24,59,11,29,83,93,84,95,48,89,36,86,98,65 +92,22,13,86,89,93,79 +29,53,24,79,51,65,11,77,59,13,48,83,17,78,26 +76,11,93,25,77,95,98,35,53,79,51,59,36,84,91,89,34 +62,21,32,44,66,33,28,94,45,25,22,35,93,76,95,98,36 +26,23,94,16,74,45,14,25,22,35,95 +33,23,74,16,66,99,32 +85,78,94,28,33,14,21,66,35,67,16,97,32,99,18,25,34,26,74 +24,51,65,11,59,13,48,88,78,85,26,62,21 +17,78,99,26,23,62,32,44,66,18,28,94,16,74,67,45,14 +11,65,76,93,91,48,13,53,71,29,51,59,79,98,77,95,92 +17,26,91,62,16,78,28,88,94 +65,11,91,59,48,88,17,78,85,99,26,23,62,32,33,18,28 +35,99,26,67,23,74,33 +83,48,97,18,85,88,17,66,77,59,78,62,94,26,74,13,28,33,44 +53,71,25,94,34,29,14,51,97,45,93 +86,71,62,59,21,92,13,48,24,85,83,17,88 +17,85,26,32,66,14,34 +16,14,25,22,95,98,36,29,84,53,24,92,51 +99,23,62,21,32,33,18,94,97,16,74,67,93 +48,74,85,23,26,88,18,17,59,28,32,13,94,67,62 +17,26,51,65,59,91,85,99,83,77,33,11,44,62,13,48,86 +36,29,84,53,71,24,92,79,51,89,65,77,59,13,48,88,17,85,99 +45,14,22,34,35,93,76,95,98,36,29,53,24,92,79,51,89,86,65,11,91 +93,23,33,28,18,21,45,14,32,67,94,25,76,95,97,74,26,35,66,44,16,34,22 +99,26,23,62,44,18,28,94,74,67,14,22,34,93,76 +91,77,59,13,48,83,88,17,78,85,99,26,23,62,21,32,66,33,18,28,94,97,16 +98,36,35,76,93,97,34,16,67,25,53,95,74,22,45,29,94,44,66,14,28,84,33 +84,95,86,92,65,71,98,51,74 +59,65,99,32,79,48,86,91,77,78,51,11,13,85,23,88,17,21,92 +95,36,29,84,53,79,89,86,65,11,59,83,78 +98,65,84,11,86,48,24,71,91,51,79,17,29,83,77,89,13,92,53 +88,78,85,99,26,23,62,21,32,44,33,18,28,94,97,74,67,45,14,25,22 +99,77,53,13,48,65,23,11,17,71,62 +33,45,22,88,25,74,97,99,44 +86,44,91,28,33,17,66 +35,93,76,95,98,36,29,84,53,71,24,92,79,89,86,11,77,59,13,48,83 +44,28,74,67,25,22,35,36,53 +65,59,99,33,23,89,62,13,18,88,78,11,21,86,44 +45,44,23,66,25,14,32,16,74,33,18,17,85,88,28,99,26 +97,16,74,67,45,14,25,22,35,93,76,95,98,36,29,84,53,71,24,92,79,51,89 +67,45,98,53,71,24,51 +48,83,88,17,85,26,23,62,21,66,33,28,94,45,14 +66,33,28,94,97,74,14,93,76,95,29 +71,76,86,95,98,89,11,79,53,25,22,35,65,51,77,92,59 +74,67,66,36,95,45,44,93,33,62,16,32,35 +98,18,25,97,36,84,95,32,28,35,34,44,45,16,33 +22,34,35,76,98,36,71,24,92,79,89,65,59 +85,23,66,18,94 +92,14,29,76,93,36,74,18,35,95,84 +24,86,77,59,13,78,23 +33,21,62,45,97,35,25,18,67,78,74 +78,33,62,85,89,17,51,65,48,26,13,83,99 +29,84,53,71,24,92,79,51,86,65,11,91,77,59,13,48,83,88,17,78,85,99,26 +95,74,28,44,33,16,67,93,32,34,84,22,97,98,35,25,18,45,76,14,66 +83,88,99,23,18,45,25 +74,67,14,22,35,76,95,53,71,92,79,51,89,86,65 +24,91,29,48,86,88,71,53,36 +78,85,99,26,23,62,21,44,33,28,94,97,16,74,67,45,14,25,22,34,35 +33,18,28,94,97,16,74,67,45,14,25,22,34,35,93,76,36,29,53,71,24 +28,17,26,45,33,67,14,74,18 +21,32,23,62,97,28,78,18,48,44,33,74,88,67,59,66,85 +33,28,94,97,16,74,67,45,14,34,93,98,84,71,24 +14,22,34,93,76,98,36,84,53,71,24,92,79,89,11,91,77 +89,34,59,22,29,77,86,98,92,11,95,84,13,79,91,93,53,35,51,76,71,36,65 +13,48,83,88,17,78,85,99,26,23,62,21,32,44,66,33,18,28,94,97,16,74,67 +53,71,92,86,51,11,83,17,95,29,88,98,78,84,89,79,77,65,13 +98,65,71,14,76,45,91,92,51 +17,77,21,97,66,78,74,33,32,44,18 +16,35,34,62,33,22,21,45,95 +18,85,91,44,83,86,48,17,59,26,89 +51,95,71,25,67,16,76,84,35,74,98,89,97 +79,89,99,62,24,51,77,71,13,88,17,65,85,59,26,83,53,23,11 +62,67,25,99,18,34,44,28,97,26,78 +88,32,62,24,48,59,26 +84,71,24,51,89,91,59,83,23 +11,25,14,91,36,45,86,93,51,35,34 +11,91,59,13,48,83,88,17,26,21,44,66,33,28,97 +93,76,95,98,36,71,24,92,51,89,65,91,59,13,88 +97,36,62,22,45,14,34,21,33,16,32,35,93,25,76 +53,45,93,74,92,97,71,25,89,35,24 +18,74,45,14,34,53,92 +25,97,26,99,33,23,66,83,85,45,74,14,44 +45,76,98,29,84,51,89,65,91 +32,44,66,33,18,28,94,97,16,74,67,45,14,25,22,34,35,76,95,29,84 +94,97,74,67,25,34,93,98,84,53,24,79,51 +32,83,26,74,59,16,33,78,94,85,13,99,44,88,23,77,97,48,28 +88,17,78,85,26,23,62,21,32,44,66,33,18,28,94,97,16,74,67,45,14,25,22 +95,35,59,93,91,83,24,86,77,92,29 +66,21,45,74,97,62,25,35,26,14,28,93,67,34,18,22,94,33,95,16,32 +23,62,21,44,66,28,94,97,16,67,45,25,22,34,35,93,76,95,98 +16,67,45,14,22,34,93,98,29,24,92,79,86 +98,36,29,84,53,79,89,86,65,77,59,83,17 +16,74,14,25,76,98,24,51,89 +48,62,13,85,66,59,67,28,99,44,33,94,21,78,18,26,16,83,97,17,23 +74,32,66,97,76,94,45,23,99 +25,98,44,16,93,18,33,32,94,76,45,14,22 +26,23,66,33,18,28,97,16,74,45,25,34,35,93,95 +78,62,32,33,67,14,35 +29,84,71,24,79,86,65,11,91,59,13,48,83,88,78,99,26 +53,71,92,51,89,65,11,77,59,13,48,83,88,17,78,85,99,23,62 +76,95,33,45,16,97,28,18,34,21,22,23,67,35,44,94,26,93,74,62,25,14,66 +84,71,24,79,89,86,13,83,88,78,85 +18,28,74,25,22,29,92 +74,67,45,14,25,22,34,35,93,76,95,36,84,53,71,24,92,79,51,86,65 +17,78,85,99,23,62,32,44,66,18,28,94,97,16,74,67,45,14,25,22,34 +98,71,16,93,66,25,76,28,45,18,35 +17,33,78,99,77,62,86,23,65,51,13 +28,94,23,21,11,26,85,88,48,77,32,78,97,91,66 +62,67,28,44,14,94,18,34,74,22,45,97,76,25,16,66,21,32,33,93,95 +21,66,97,67,14,34,93,95,29 +11,66,17,48,18,86,99,78,91,21,23,32,44,65,26,59,85,28,77,83,88 +51,77,85,26,11,29,88,92,48,17,59,99,53,89,13,84,86,65,24 +11,51,65,85,48,36,71,83,86,53,88,77,91,89,78,79,17,24,13,92,29,99,59 +62,21,32,44,66,18,28,97,16,14,22,34,35,93,76,95,36 +83,78,65,85,66,79,86,26,21 +28,94,16,67,22,35,84,92,79 +44,66,33,18,28,94,97,74,67,14,25,22,34,35,93,76,95,29,53 +66,18,28,94,97,16,74,67,45,14,25,22,34,35,93,76,95,98,36,29,84,53,71 +29,51,86,77,88,85,26 +66,74,33,83,26,62,99,23,28,78,48 +26,94,14,99,45,33,23,97,35,32,18,25,34,76,67,62,66,44,28,93,74,22,21 +65,11,91,77,59,13,83,88,17,78,85,99,26,23,62,21,32,44,66,33,18,28,94 +78,13,59,44,66,18,28,26,62,17,85,99,88 +28,35,53,18,84,34,98,93,33,25,97,74,71,22,24,76,16,67,14,29,45 +89,86,65,91,77,48,83,88,78,85,99,26,23,62,21,44,66,33,18 +11,77,59,13,83,88,17,85,99,26,23,62,21,32,44,66,33,18,28,94,97 +97,85,13,28,94,62,59,26,16 +98,65,71,11,67,76,93,84,79,53,86,29,45,14,92,51,89,24,22,35,25 +88,44,33,66,74,67,94,99,62,32,28,45,17,97,18,13,48 +17,92,32,24,77,65,79,11,86 +16,78,94,85,91,23,88 +71,29,17,88,85,36,77,84,89,65,92,86,59,13,11,83,79 +45,25,34,29,71,24,51 +62,67,16,17,28,23,99,14,85 +65,59,83,17,18,28,94 +21,32,44,66,33,18,28,97,16,74,45,14,93,95,29 +89,91,36,92,86,29,71,51,76,95,98,24,77,79,53,65,25,93,84,59,34,11,35 +44,66,33,28,16,74,67,45,25,34,35,98,36,84,53 +28,32,34,44,21,97,62,93,98,74,35,18,14,67,36,94,76,25,45,22,16 +16,67,45,14,25,34,93,76,98,36,29,24,92 +24,36,95,93,91,76,92 +36,93,71,89,34,11,13,29,24,95,65,48,77,51,79,84,76,86,98,91,53 +98,22,18,34,93,97,21,66,28,16,35,23,94,32,45,14,95,33,62,67,25 +92,79,51,89,86,11,91,77,59,13,48,83,88,78,85,99,23,62,21,32,44 +28,94,16,76,95,24,79 +33,26,85,51,48,89,86,11,78,23,65,99,83,88,66 +89,13,23,26,21,33,11,51,99,77,32,59,66,44,86,48,91,17,83,85,78 +78,22,44,74,34,35,14 +94,45,22,35,84,53,51 +89,53,11,59,23,24,99,13,78,79,83,91,48,85,92,26,84,71,65 +84,92,51,89,65,91,77,59,13,78,85,99,26 +22,91,79,76,11,29,59,84,25,95,86,51,24,98,34 +17,78,85,99,26,23,21,32,44,66,33,18,28,94,97,16,74,67,45,14,25,22,34 +65,11,91,77,17,78,85,62,32,18,28 +28,99,25,78,97,33,18,16,34,67,14,85,74,32,94,44,45,23,17,21,26,22,66 +94,22,35,33,74,16,34 +13,48,17,85,23,62,32,44,66,33,28,94,16,74,45 +29,17,65,76,79,24,84,88,36,13,95,83,86 +86,65,13,88,85,23,44 +23,62,21,32,44,66,33,18,28,94,74,25,22,34,35,93,76,95,98 +59,13,48,88,17,78,85,99,26,23,62,21,32,66,33,28,97,74,67 +92,51,99,91,77,21,26,89,48,24,59 +88,17,23,62,33,94,16,74,67,45,22 +91,77,59,48,83,88,17,78,85,99,26,23,62,21,32,44,66,33,18,94,16 +14,35,29,84,53,24,89,91,77 +65,93,89,29,22,53,91,36,79,59,71,98,77,95,86,35,92,34,51,76,24,84,13 +53,71,24,92,79,51,89,86,65,11,91,77,59,13,48,83,17,78,85,99,26,23,62 +17,85,79,91,51,88,77,24,78,86,11,71,65,53,99,59,83,36,13,29,84,92,48 +28,16,25,29,67,97,71,94,79,98,45,35,14,92,22,95,24,34,76,53,93,36,74 +79,51,89,86,65,11,91,77,59,13,48,83,88,17,78,85,99,26,23,62,21,32,66 +86,65,11,91,77,59,13,83,88,78,99,23,21,33,28 \ No newline at end of file diff --git a/2024/day5/main.py b/2024/day5/main.py new file mode 100644 index 0000000..d112ff4 --- /dev/null +++ b/2024/day5/main.py @@ -0,0 +1,85 @@ +with open('input.text', 'r') as file: + data: list[str] = file.readlines() + +# Parse Data + +class Rule: + subject: int + constraint: int + + def __init__(self, n: int, other: int): + self.subject = n + self.constraint = other + + def __str__(self) -> str: + return f'{self.subject}|{self.constraint}' + +class Update: + nums: list[int] + + def __init__(self, ns: list[int]): + self.nums = ns + + def check_rule(self, rule: Rule) -> bool: + if rule.subject in self.nums and rule.constraint in self.nums: + if self.nums.index(rule.subject) > self.nums.index(rule.constraint): + return False + + return True + + def check_ruleset(self, ruleset: list[Rule]) -> Rule: + for rule in ruleset: + if not self.check_rule(rule): + return rule + + return None + + def fix_rule(self, rule: Rule) -> None: + if rule.subject not in self.nums and rule.constraint not in self.nums: + return None + + si: int = self.nums.index(rule.subject) + ci: int = self.nums.index(rule.constraint) + + self.nums[si] = rule.constraint + self.nums[ci] = rule.subject + + def get_middle_num(self) -> int: + return self.nums[int(len(self.nums) / 2)] + + def __str__(self) -> str: + return str(self.nums) + + +rules: list[Rule] = [] +updates: list[Update] = [] + +for line in data: + if '|' in line: + n1, n2 = [int(n) for n in line.split('|')] + rules.append(Rule(n1, n2)) + elif ',' in line: + nums = [int(n) for n in line.split(',')] + updates.append(Update(nums)) + +# Part 1 +total = 0 +for update in updates: + if update.check_ruleset(rules): + total += update.get_middle_num() + +print(f'Part 1: {total}') + +# Part 2 +total = 0 +for update in updates: + fixed = False + while r := update.check_ruleset(rules): + update.fix_rule(r) + fixed = True + + if fixed: + total += update.get_middle_num() + +print(f'Part 2: {total}') + diff --git a/2024/day5/test.text b/2024/day5/test.text new file mode 100644 index 0000000..d4d4441 --- /dev/null +++ b/2024/day5/test.text @@ -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 \ No newline at end of file