From 3b9ca8cf2e05192eeef64d724c511f457818ac38 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Thu, 4 Dec 2025 11:02:51 +0100 Subject: [PATCH] added day04a --- Cargo.lock | 5 ++ Cargo.toml | 1 + README.md | 16 +++-- src/day04/Cargo.lock | 7 ++ src/day04/Cargo.toml | 6 ++ src/day04/input04.txt | 138 +++++++++++++++++++++++++++++++++++++++ src/day04/src/lib.rs | 3 + src/day04/src/part04a.rs | 55 ++++++++++++++++ src/day04/src/part04b.rs | 16 +++++ src/day04/story04a.txt | 29 ++++++++ src/day04/story04b.txt | 25 +++++++ src/main.rs | 44 +++++++++---- 12 files changed, 324 insertions(+), 21 deletions(-) create mode 100644 src/day04/Cargo.lock create mode 100644 src/day04/Cargo.toml create mode 100644 src/day04/input04.txt create mode 100644 src/day04/src/lib.rs create mode 100644 src/day04/src/part04a.rs create mode 100644 src/day04/src/part04b.rs create mode 100644 src/day04/story04a.txt create mode 100644 src/day04/story04b.txt diff --git a/Cargo.lock b/Cargo.lock index 12a373e..4d8c16d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "day01", "day02", "day03", + "day04", ] [[package]] @@ -26,6 +27,10 @@ dependencies = [ "iter-first-max", ] +[[package]] +name = "day04" +version = "0.1.0" + [[package]] name = "iter-first-max" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index 5e098bf..cfcc2cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" day01 = {path = "src/day01"} day02 = {path = "src/day02"} day03 = {path = "src/day03"} +day04 = {path = "src/day04"} diff --git a/README.md b/README.md index eeda2c6..8575bec 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Advent of Code 2025 ```bash -day01:A => 1150 ( 72us) -day01:B => 6738 ( 98us) -day02:A => 31839939622 ( 8141us) -day02:B => 41662374059 ( 64109us) -day03:A => 16812 ( 152us) -day03:B => 166345822896410 ( 298us) +day01:A => 1150 ( 130us) +day01:B => 6738 ( 161us) +day02:A => 31839939622 ( 14191us) +day02:B => 41662374059 (135384us) +day03:A => 16812 ( 154us) +day03:B => 166345822896410 ( 356us) +day04:A => 1518 ( 304us) +day04:B => 0 ( 9us) ---------- - 72992us + 150768us ``` \ No newline at end of file diff --git a/src/day04/Cargo.lock b/src/day04/Cargo.lock new file mode 100644 index 0000000..de1e82f --- /dev/null +++ b/src/day04/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day04" +version = "0.1.0" diff --git a/src/day04/Cargo.toml b/src/day04/Cargo.toml new file mode 100644 index 0000000..a3cc735 --- /dev/null +++ b/src/day04/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day04" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/day04/input04.txt b/src/day04/input04.txt new file mode 100644 index 0000000..658f304 --- /dev/null +++ b/src/day04/input04.txt @@ -0,0 +1,138 @@ +@@@..@@.@.@@@..@...@@@@.@.@@@..@@.@@@@...@@@@@.@@@.@@@@.@..@@@@....@@@.@@@..@@..@.@@@.@@@@.@.@@@....@@@@@@.@...@.@@@@@.@@.....@@@@@@@.@.@. +@@@@..@@@@.@@@@..@.@..@@@@@@@@.@@@@@@@.@.@@@.@..@..@@.@@@@@@..@..@...@@@@@.....@@@@@..@@@.@@@.@.@@@...@..@.@.@.@@@.@@@@@@..@@@@.@@@@@@@@.. +@.@.@@.@@@.@@@@@@@@@@@@.@..@.@.@@.@..@@..@@@..@@.@@.@.@..@.@@...@@@@@@....@....@....@@.@@.@@@@@@@.@.@...@@@@@@@...@.@@.@..@@@@@.@.@.@@.@@@ +...@@@@@.@@@@@@@@@@..@@...@..@@@.....@@@@@@....@@.@@@@@@..@@@.@@@@@.@..@@@@.@.@@@@.@@@@@.@@.@@@@@.@@@.@..@@@@@.@@.@.@..@@.@@@.@..@@@...@@@ +...@@@@@@.@.@@@@@@..@.@@@@@@....@@..@..@@@@@@@@@....@@@@.@.@.@.@@...@@.@.@.@@@..@...@.@@.@..@@@@@.@@@..@@@@@@@@@@@@.@...@@@@@@@..@@@@.@@.@ +@@@@@...@.@..@@@@..@@@@@@@.@.@@.@..@@@..@@.@@@.@.@@@@@@@@..@@@@.@..@@@@@@@@.....@...@@@@.@@.@.@@...@@@.@.@@@@@@@...@@@@.@@...@@@@....@@..@ +@@.@@@@..@@....@@@@@@@@@@@..@@@@.@@@@@.@@@@..@.@@@@@@@@@@.@.@@@@@.@.@.@@@@.@@@...@@@@...@@@@.@@.@.@.@@.@.@.@@@.@.@@@@@.@.@@@..@@@@.@@@@.@. +@@@@...@.@@.@@..@@@.@.@@@..@@..@@@@@@@@.@@@@....@@@@@..@.@@@@@@.@.@@.@@@@@@.@.@.@@.@@...@..@.@@.@@@@@....@@.@@@@.@@@.@@.@@..@@@@@@.@.@@@@@ +@@.@@@......@@@.@@.@@.@...@@@.@.@..@@@@@@@@....@@@@.@..@.@@.@@@@.@.@.@.@@@@@@@@@@@.@@.@@..@@.@@@@@@@.@@@@.@@@.@.@.@@@..@@@@@@@.@....@.@@@@ +.@@...@.@@.@@@@..@@@@.@.@.@...@.@@@@@@.@.@@.@@@.@.@@..@....@.@@.@.@@.@@@@@.@.@@@..@@@.@@.@@@@@@@@.@.@@@@.@@@..@@@..@@@.@@@@@@.@@@@@...@@@. +@.@.@@.@@........@.@.@@@@@@@.@..@@.@.@.@.@.@.@.@@@@@...@@.@@@@@@@...@@@..@@.@.@@@@@.@@.@@@@@...@@@.@..@@@@.@@.@.@.@@@...@@.@@@@.@@@@@..@.@ +@@@@@...@@@@.@.@@@..@@.@@@@.@.@@@@...@@.@@@@@@@@@.@@..@@@@@.@.@@@....@@@@@@..@@..@@@@...@@@@@.@..@@@@@@@.@@@.@...@.@.@.@@@..@@.@.@@@@..@@. +@.@.@.@@@@@@.@@@@.@.@@...@@@@@..@@@..@..@@.@.@@@.@@.@.@@@.@@.@..@.@@.@.@@..@.@@.@@@@.@@@@@.@.@@.@..@@@@@@@@@@@@@@...@@@@@@@@.@@@...@@@.@@. +@.@.@@@@.@@@@@@@.@@@@..@.@@@@..@@..@@.@.@@@@.@@.@@@@@.@@@..@.@@.@@@.@@@@@@@.@..@.@@@@@.@@@@@..@@@.@@.@@@@.@@@@.@.@@@@@@@@@...@@@@.@@@..@.. +@@@.@@@.@@@.@@@.@@@.@...@.@.@@..@@.@@@.@@@@....@@@.@..@.@@@@.@@@@..@...@@@@@.@.@...@..@@...@@.@..@.@..@.@@@@.@@@@@@.@@@@.......@@@@@@@@@.. +...@@@@...@@..@.@@@@.@.@@..@.@..@.@.@@@@@@@@.@@@.@.@@..@.@..@@@.@@@@.@.@@@@@@@.@@...@.@@.@@.@@.@@@@@@@@@.@@@@..@@@.@@@@@.@.@.@@.@..@@@@@@. +.@@@@.@@@@@...@@@.@@@@@@@@..@.@@..@@@@@@@@@...@.@.@...@@@@@@@.@@@@@@@..@........@@@@@..@@.....@@...@@@.@@@.@..@...@..@@@@..@.@@@..@@@@.@.@ +@@@.@@..@..@@@.@.@.@@.@@@@.@@@.@@...@.@..@@@@@@.@.@@.@@@@@.@@....@@@@..@.@@@@.....@@@.@.@.@@@@@@..@@....@@@@@@@@@@@@.@.@@.@@@.@@@@@@@@@@.. +.@@@.@@.@@@.@@@@.@...@..@@@.@@@..@@@@...@@.@.@@.@@@@..@..@@@@@..@.@..@...@@@@.@@@@.@@..@@@@...@@.@@@.@.@.@@..@..@@.@@@.@@.@@@@@@.@@..@@@.@ +@.@@@.@..@@@@@@@@@..@.@.@@@@@@@@.@@.@.@@@.@@.@@@@@@@@.@..@@@@.@@.@.....@..@@@@@@@.@@@@.@@@.@.@@@.@.@@@@@...@@@..@@@@@@@@.@.@@@@@.@@.@@@@@@ +@.@.@.@@@@@@..@..@..@@@.@..@......@@@@..@..@...@@@@@@@@@@@@.@.@.@@..@@@.@@@.@@.@.@.@@@@.@@@@...@.@@@@@@@.@..@@..@.....@@.@@@.@.@@@....@@.@ +..@@..@@.@@.@.@@@@@.@@..@..@.@.@.@@..@..@.@@@@@@.@.@.@.@@@@@@@@.@@..@@.@@@@.@@@@@@.@@@.@...@@..@@.@@@..@..@..@...@@.@...@.@..@@@@@@.@.@@@@ +@@@@@@.@@.@@@@..@...@@@@@.@@.@@.@@@@@@.@..@.@@@@...@@.@@@.@@@....@@.@.@@@.@@@.@...@@..@@..@@..@@@@@.@@.@@@@@.@...@@@.@@@.@@.@@@@.@@@.@@.@@ +@@.@@@@@.@@.@.@.@@@.@.@@...@..@@@@@..@@@@...@@@..@..@@@.@.@.@@@@@.@@.@@@@.@@@..@@@@...@@@@@.@.@@@@.@@@@@@..@@@.@@.@.@....@@@.@@@@@@@.@@@@@ +.@@@@@@....@@@.@@@@.@.@@@..@.@.@.@@@..@@@@...@@.@@@@@@@.@@.@@.@@@..@@@.@@.@@@.@.@@@@@.@@@.@.@@@@@@@@.@.@@@@@@.@@@@.@@@@.@@@@@..@@.@@.@@@@@ +.@...@@..@@@@@@@@@@@.@@@.@@.@...@..@@.@.@.@.@.@@@@.@...@.@.@.@.@@@@@@@....@@@@.@@@.@@@..@@@@@..@@@@@..@@.@@..@..@@@@@.@..@@....@@@@@@.@.@@ +@@.@@@@@@@...@@.@..@.@@.@@.@.@@@@@@.@.@@...@.@@@.@@@@.@.@.@.@@..@.@@@@@@..@..@@.@.@@@@.@@.@...@@.@.@@@@@..@.@....@@@@.@@@@@.@@@@..@..@@@@@ +.@@@@.@@.@.@...@@@@@@@@@@..@...@@@.@@@.@.@..@@@.@@@@@@..@@@..@.@..@@@@@.@.@@@@@@@@..@@@.@.@@@...@@@.@..@@@@.@@@@@@@@@@@...@@@@@@.@@@..@@.. +@...@@@@.@.@@@@@@.@@.@@@..@.@@@.@@@@@@@..@@@@@@@.@.@.@.@.@@@@.@@.@..@.@@...@@@@@.@..@@@@.@.@@...@@@..@.@..@@@@.@@@@..@@..@@@@@..@@@@.@@@@@ +.@.@@.@@.@@@.@.@@@@@@.@@@@.@@.@@..@@@@..@@@@.@.@@@@@@@..@@.@@...@@...@@@..@@..@@...@@@@@@@.@.@@@@@.@...@@.@@@@@...@.@.@.@@.@@@@@@@@..@@.@@ +.@@...@@@@@.@.@@@@@@@.@...@.@@@.@..@@@.@.@.@@.@@@..@.@@.......@@@@@.@@.@@@.@@....@@@@@@..@@@@.@@.@@.@@.@@.@.@@@...@@.@@@@@@..@..@@@@..@@.@ +..@@@..@.@@...@@@@..@.@@@..@@.@.@.@@.@.@..@@...@@...@@@.@@....@@@@@.@@..@@@@..@.@@@@@@.@@.@@..@.@@@@@@@.@@...@..@.@@@.@@@@@@@@@@@@.@.@...@ +@@@.@@@.@@..@@@..@@@.@@.@....@@...@.@@@@@.@...@@....@.@.@@@@@.@@@..@@..@.@@@@@@..@.@....@@.@@@.@@@@@..@@.@.@.@@...@@@...@@@.@@..@@.@.@.@@. +..@@@@@@.@.@.@@.@@@.@@@@@@@...@..@.@..@@.@...@@.@@@@@@..@@@...@.@@@@@@.@.@@@@@..@@@.@@@@...@.@..@.@.@@.@.@@.@@@@.@.@..@.@@@@@@@@..@@.@..@@ +@.@@..@@@@@@@@@.@@@@@.@@@.@@@...@..@@@@@@.@@@@..@@..@@@.@@@@@@@@@.@..@@@..@.@@...@...@@@.@@.@.....@.@@@.@@@@@@.@.....@@.@@@@.@@@...@@@..@@ +@@@@@@.@@@.@@@@@@@@@@.@.@@.@...@@...@@...@@@@.@.@@@@@@..@@@..@@.@@.@@.@.@@@@.@@.@@@..@@@@.@@@@@@.@@.@@@..@@@.@.@..@.@@@@@...@@@@..@@...@.@ +@@@@@@.@@@@..@@.@.@..@.@.@@.@.@@@.@@@@@@..@@@...@@.@....@..@..@..@@@.@@..@@@@@@@.@.@@@@@@...@@@@.@@@@....@@@@@@..@.@@..@@@....@@@@@@.@@@.@ +@..@@@@@@@@@.@.@@@...@@@@@@@@@...@.@@@.@@.@..@@.....@..@.@@@@@@.@.@...@@.@..@@@@.@.@@@@.@@@@@@@@.@@.@@@@@@...@@.@@@@@@@.@@@@@@@@.....@.@@. +@.@..@@@.@@@@@@@.@..@.@@@@@.@..@...@.@.@.@@@@.@.@.@.@.....@@.@@.@..@@@@.@..@@@@@..@.@@@@.@@@...@....@@@.@@@@@@.@@...@@.@.@@.@..@@@....@.@@ +.@.@@....@.@@@@@@@@@@..@@@..@@@@@.@.@@@@@@@@.@.@@@..@@@@@@@.@.@..@@@.@@@@@@@@@@@@@...@.@@@..@.@..@@@.@@.@@@@.@.@@@@...@@..@@@@@@@@@@@@.@@@ +@@@..@@@@@..@@@.@@@@@.@...@...@..@@@@@@@..@@..@@@.@@...@@.@@@.@@@...@.@@@@@@.@@@@@..@@.@@.@.@..@@.@..@@@.@.@@@@@@@..@@.@.........@.@@@.... +@@@@@.@@.@@@.@@@@..@@......@@@@@@@@@..@@@@@..@@@@...@.@@@@...@.@@@@@..@@@@@@@.@@.@...@.@@...@@...@@.@@@@@..@@@@...@...@..@.@..@@@@@..@..@@ +.....@.@@@@@..@@@.@@@@@.@.@@..@@...@@@@@@....@@@.@@..@@@@@.@..@@@@@@@.@@..@@@@@@.@.@.@.@@@.@@..@@@.@@@.@@@@@@@.@.@@@@@@@@@@.@.@..@@@@@@.@. +@@...@.@@...@@@.@.@@..@.....@@@..@@@@@@@..@@.@@.@@.@@@@@@@@.@@@....@@@@.@@@...@@@.@@@@@@@.@@.@@.@@.@@..@@@@.@..@.@.@.....@@@.@.@@@@@.@@@@. +@@@@@@@..@@.@.@@@@.@@@@@@@..@..@@@@..@@@@.@@@@..@@@@.@@@@@@@@@.@@..@@@@@@@@@@@@.@.@@.....@@@.@..@.@@@@....@@@..@..@.@..@..@.@@@.@.@.@.@@@. +@@@@@@@@@..@@@.@@@.@.@@@...@@@@.@@@.@@@@.@......@.@...@@.@..@..@.@.@@@@@@@@@@.@..@.@..@@.@@@...@.@@@@@@.@.@@..@..@.@@.@...@@.@@@@.@@.@@@.@ +@.@@...@.@@@@@.@.@.@@.@@@..@@@@.@@@@@....@.@..@.....@.@@@@@@.@@@@.@@@..@@.@.....@@.@@@@@@.@@@@@.@..@...@.@@..@@..@@@.@@@@.@@@...@.@@@@@@@. +..@...@@.@@@@@@@.@@.@@@@.@@.@...@@@@.@@@@.@@@..@.@.@@@@..@@@@@.@@@@@.@@@@@@@.@@@.@@..@@..@@.@@@@..@..@@@@@@.@@@@@@@.@@@@.@.@@.@.@@.@@..@@@ +..@@@..@.@@@@.@@@@@@..@.@.@@@.@@..@@@@@@@@@@@@.@@.@@@@.@@@.@@@@@@@@.@@@@.@.@@@@@@.@@@@@..@@@.@@@@@@@...@@@@@....@..@...@.@@@@@@@@@@@@@.@@@ +@@@.@@@.@@.@@@.@@@.@@@..@@@.@@.@@..@.@@.@@@@...@@@@@@@@..@@.@..@@@@.@@@...@@@@@@@@@...@..@@@@@@@@@.@@@.@.@..@.@@.@.@@@@@@@@@.@@..@.@@.@@.@ +@..@.@@.@@.@..@.@@@@@@@@.@@@@...@..@.@@..@.@..@@@@@@@..@@@.@..@.@@@@@..@@.@@@.@.@@@@@..@@@.....@.@..@@.@.@@@@@@@@.@@@@@@@@..@.@...@@@@@@@@ +@@@@@@.@.@.@@@@.@@.@@@@@@@.@@@@@.@@@.@.@..@@@@..@@@@@.@@@@@@.@@@.@.@.@.@@.@@@@.@.@@.@..@.@@.@@.@@@@@@@@@.@@@@@@@.@.@.@.@@.@@@.@.@@......@@ +.@@@@.@@@@.@@.@..@@@@.@@@@@@@@@@.@@@@@..@@@@.@..@@..@@@@@@@@@.@....@@....@@@@.@.@.....@@@.@@..@.@@..@@.@@.@.@@@@...@@@..@.@@.@@@@@@@.@@.@@ +..@@@@..@..@@.@@@@.@.@@@@.@@@@@.@@@@.@.@.@@.@@@.@@@@@@..@@.@@@@@@@@@@@.@@.@@..@@..@.@@@@.@@@@@...@@@@@@@@...@.@..@@@@..@@@@.@.@.@.@.@@@@@@ +@@@..@@.@...@.@.@.@@@@@@@@@.@@.@@@..@..@@@@@@@@.@@@.@@@@@@@@@@.....@.@@.@@@.@@.@@..@@@@@@@@@.@@@@@@@@@@@@@.@@.@..@@@@@@..@.@@.@@@@@..@.@@. +@.@@@@@@@@@@@...@...@@@@@.@.@@.@@....@.@.@..@.@.@@.@@.@@...@@.@@.@@.@.@..@.@@...@@.@.@@@.@@@@@@..@@.@@.@@@..@@@.@@@.@@@@@@@..@@.@.@@@@.@@. +@.@@@@.@.@@@@..@@@@@@.@.@.@@.@@@@.@@.@.@@..@@.@.@@@@@.@@@@@@@.@@@@@.@@@.@@@@@@@@@@..@.@@...@.@.@.@@@.@...@@@@....@.@@..@@@.@.@.@@@@....@@. +..@@@@@@.@@@@@.@.@@@.@@@@@@@@....@....@@@.@@@@@...@.@.@@..@..@@.@@@@@..@@@@..@.@@@..@..@.@@@@@@@...@@@@.@@@.@@@@@@.@@@.@@..@@.@@@@.@.@@@@@ +.@..@.@@.@@....@@@...@@@@@@@@.@@@.@..@@@@...@.@.@@.@.@@@@@.@@@@@.@@..@.....@@@@..@@..@@..@@..@..@.@@...@@@.@@@@@.@@@.@@.@.@.@.@..@@@@@@.@@ +.@@.@.@@@.@@.@@@..@@@..@@@@@..@@..@..@..@@.@@.@@.@.@@...@@@...@@.@@@@@.@@@@.@@@..@@.@@..@@@@@@@@.@@@@..@@@@..@@.@@@@@@@@@@.@.@..@@..@@@@.@ +.@@.@@@..@@...@@@.@...@@@.@@.@@@@.@@@.@@@...@.@@@@@.@@.@.@@@@@..@@@.@@@.@.@@@.@@@@@.@@.@@@@...@@@.@@@@@..@.@@@.@@@@@@@@.@.@@@.@@.@@@@..@@. +@@@@@@@@.@@@..@.@@@@..@.@@..@@.@...@..@@..@@@@@.@@@@@.@..@@...@.@@.@@@@@.@.@@@@@.@@@@.@@@.@.@.@@@@@@@.@@@.@@.@.@@.@@.@@@@..@..@.@@@@@@...@ +@..@..@@@...@@@@@.@@.@@@@@.@.@@@@@.@@..@..@..@@@@@@@.@@.@.@@.@@@..@@@@@@@.@@@@.@.@@..@@@.@@@@@@@@@@@@@@@@@@@@.@@..@@.@@@@@.@@@.@@@..@..@@@ +@....@@@@@@@@@@.@@@@@@@..@@@@..@@@@@@@@...@..@@@@@@.@@..@@.@@@@@@...@@.@@@.@.@@@@@.@...@..@@..@@@.@.@..@@@@@@@@@@..@.@@@@@@@@..@@@...@.@@. +.@@@@.@.@.@@@@@.@@@@.@@.@.@@@@@@..@@.@@@.@.@.@@@@@...@@@@@.@@.@@@@@@.@@@@@.@@@@@@@@@@@@.....@....@@@..@@.@.@@..@@@..@.@@@.@@@@@@@.@@..@@@. +.@@..@.@@@@.@.@@@@@....@@@.@@....@@@.@.@.@@......@@@@@@@@.@@@@@.@@@@@@.@@.@.@@@.@@@@@@.@..@@@@@@..@@.@@@.@@.@@@.@.@.@@@@.@@@@@.@.@@@..@@.. +.@@.@.@.@@..@@@@...@@..@.@....@.@@..@@@.@@.@..@@@..@@@@.@@..@.@@@@@@.@@..@@.@@..@@@.@@@.@@..@@@.@@.@..@@@@@@.@..@.@@@@..@..@..@..@....@.@@ +.@.@@@@.@..@@.@.@@@@.@....@..@@@@@.@@.@.@@@.@@@@@@@.@@@.@@@@@@@..@@@.@.@@....@@@@@@@@@@@@@@@.@@@.@@@@@@.@@..@..@@@.@.@..@@@@.@@.@@....@... +.@....@..@@.@@@.@@@@@.@@..@@.@@...@@...@.@.@.@@@@@@@@...@@@@@@@@@@.@@@@@..@..@.@..@..@@@@@@.@@@@@@@@@@@.@@@@@@@.@..@.@@@@@@@@.@@@@@@@@@@.. +.@.@@@@.@.@.@.@.@.@@.....@.@..@@.@.@@@..@@.@@@@.@@@@.@@@@@@@@.@@@@.....@@@.@@@.@@@@@.@.@@@@@.@..@@@@@.@@.@@.@.@@@@.@@@.@@.@@@.@@..@@@@@... +@@@.@.@@..@.@...@.@@.@@@@@@@@@@@@.@@@@.@...@.@@@@@@@@@@@@@.@.@@@@@@.@@@@@.@@@@@@.@.@@@@@.@@........@@.@.@@@@@@@@@@@@@@@@@.@@@.@..@@@@@@@@@ +@.@@@@@@.@@@@.@@@@.@.@@..@@@@.@.@....@@.@..@@@.@@.@@@@.@@@@@@.@...@.@@@@@..@@.@@.@@..@.@@..@@@@@@.@.@.@.@.@@.....@@@.@@@@@@.@@@@@@@@@@.@.@ +@@@@....@@@@..@.@@@@@@.@@.@@@@@..@@..@@@.@.@@@.@@@@@..@@@...@.@..@@@@@@.@@@..@@@.@@@@@@.@@@..@@@@@@@@@.@@@.@@@@@@.@.@@@.@@..@@@@@@@..@@@@. +@@@@.@@@@@..@.@@@.@@@@@@@@@.@@.@@..@.@.@..@@..@@..@.@@.@..@.@@@@.@@..@..@.@@@@@.@@@...@.@..@@@.@.@.@@@@@@@@...@..@@@@@.@@.@@.@@@.@@@.@.@.@ +...@@.@@@@@..@.@.@@.@@@@@@..@@......@@@@@@.@.@@.@@@.@@.@@@@@.....@@@@.@@@@@..@@@.@@.@......@.@@@.@@....@@.@.@.@@..@.@.@@@@@.@.@@@..@@@@@@@ +.@@@@.@@@.@@.@@@.@@@@@@.@@@@@@.@@@@@@..@@@.@.@@.@@@.@@@@@@@.@.@.@..@@@@..@@@@@@.....@@@..@@@...@@@@.@@.@.@....@@..@@@@@@.@@@@.@@.@.@..@@@. +@@...@...@@@@@@@@.@....@@@.@@@.@@@@@..@@.@@@@@@.@..@@..@.@.@@@@.@@@@.@@...@@.@@.@.@.@@.@@..@@@@.....@@@@@@...@.@@@@@@.@.@@@@@@.@@@@@...@.@ +...@@.@@@..@@.@..@@.@@@.@@@.@@.@@@.@.@@@.@.@.@@@@...@@.@..@.@@@..@@@.@.@.@@@@..@@@@.@@.@.@@@@@@@@@..@.@..@.@..@@@@@.@..@..@@@@@@.@@.@@@@.. +@.@.@.@@@..@@@@@.@.....@@@@.@@@.@@@@.@@@@.@@.@.@@..@@@@.@@@.@@..@@.@@@..@@@@.@@@@.@@@.@@@.@@@.@@@@@.@.@@@..@@.@@@@@@..@...@..@@.@@@@..@@.. +@@@@@@@@@..@..@.@@....@@@@@@@@.@@@.@@@.@.@@.@@@@@@...@@@@@.@.@@@..@......@@@.@@@.@@@.@.@@@@@.@.@@.@@..@@@..@@.@@@.@..@@@..@.@@@@@@@@@...@@ +...@@@.@@@..@..@@@@.@@@@@@@@@.@...@@@@@.@@@@@@@@.@@@@...@@..@.@.@.@@@.@@.@.@@@@...@@@.@@.@.@.@@.@.@@@.@@@@@@..@@.@@@.@@@..@.@.@@.@@@@.@@@. +@@..@@@@@@..@.@....@@.@.@@@...@@@@@....@@@@.@.@..@@@.@@@.@@@...@@@@@..@.@@@@@@.@@@..@@@..@.@@@@@@@@...@@@@.@..@..@@@@.@..@@@@@...@.@.@.@@. +@.@@.@..@@@@@@.@@..@@@@@@..@@.@@@@..@@@..@@@@.@.@@@.@@.@@.....@@@@.@..@@.@@@@@@@@.@.....@@.@.@.@.@@@@@..@@...@@@..@..@@@@@@@@.@@@..@...@.. +.@@.@@@@@.@@@.@@.@.@.@@....@@.@@...@@.@..@.@@@@@@@@@@@@.@@@@@.@@.@@@.@@..@@@@..@@@.@@.@@..@...@.@@@@@...@@@@.@@.@@@@.@@.@@.@@@@@@@@@@.@@.@ +@@@@.@@@.@@.@@.@@@@@.@@@.@@@@..@.@@@.@@@.@..@..@@@@@@@@@@@@...@@@@.@@@@@@@@....@..@.@@..@@@@@@...@@@...@@@@@@@.@..@@@@..@@..@@@@..@@@.@@@@ +@@@..@@.@@..@@@@@@@@@@@@@@.@.@@@.@@@@....@@@.@@@.@.@....@@@@@@.@@.@@@.@@@@.@@@.@..@..@@@..@@..@@@@.@@....@@...@..@@@@@@@@..@@..@@@..@.@@@@ +.@.@@.@@@@@..@@.@@@@@@..@@.@@@@@@.@@@@@@@.@.@@@.@@.@@@@@.@..@@@...@.@..@..@@@@@@@.@@@.@@@.@@@@.@@@@@@@@@@@.@@@@@..@@@@.@@.@.@@@........@@@ +.@@.@@..@@@@@@@@.@@@@.@@@@@@..@.@.@@@..@.@@.@.@.@@@@@@.@@@@@..@@..@@.@@@@@..@.@@@@@@.@@@@.@..@.@.@.@@@.@@@@.@@.@@.@.@@@@@..@.@.@@@@.@@.@.. +.@@@..@@@...@...@@.@..@.@@@..@@..@@.@@..@@..@@@.@@..@....@.@@@.@@@.@@.@@..@@@@@@.@@@@@@@.@..@@@@@@.@.@.@@@.@@@@..@@.@@..@@@@@@@@.@@@@@.@@@ +...@@@@@@@@.@@@@.@@@.@.@.@@@.@..@.@..@@@.@..@.@@@@@@..@.@@.@@......@@@.@.@@@@@@@.@@@@...@@.@@..@...@@@.@@.@@@.@@..@.@.@@@@@@@.@@@@@.@@.@.. +@@..@@@@@@@.@@@.@@@@@@@.@@@@@@@@@.@@.@@@....@.@@@@@.@@@@.@@.@..@@@@@@@@@@.@@@.@@.@.@@.@@@@@..@@..@@@@@@.@@@@.@@@..@....@@@@@@@@@..@@@@@.@@ +@@...@@.@.@@.@@@@@.@@.....@@@@@@.@.@@@@@@..@@@@@.@.@@@@@...@..@@.@@@@@@.@.@.@@@@@@@.@@@..@@...@@@@..@.@.@@@..@@@@@@...@@@..@..@@.@.@@..@@. +..@@@@@@@@@@@@.@@@..@@@..@@..@@@....@@.@@..@@.@@..@@@.@..@.@@@@@.@@.@.@.@@@.....@.@@.@@@..@@..@@.@@..@@@.@@@.@@.@.@.@@.@@...@.@@..@@..@@@@ +@..@@@@@@@@.@@..@.@..@@.@@@@@.@.@@@@@@.@.@.@.@..@.@....@..@@@.@.@@@@@@@..@@@@@@@@@.@@@@@.@@@@@@.@@@@.@@@@@@@.@@@@.@@.@@@.@.@@.@...@@...@@@ +@@@.....@.@..@@@@....@@.@..@@@@@@@...@.@.@@@@@..@..@.@.@@@.@.@@@.@...@..@@@@@.@.@@...@..@@@@.@@.@@@.@@@@@..@@@@@...@@@@.@.@@@@.@..@....@@@ +.@..@.@...@@@@@.@@@..@@@@@..@@.@@@@@.@@.@.@@@@@.@.@@...@.@..@.@.@@.@@.@@....@.@..@@@@.@@@.@.@@..@@@@@@..@@.@..@@@@@@...@@@@.@@@@@..@@.@@@. +..@.@.@.@@.@@@@@..@@.@@..@.@@.@@@.@@@@@@.@@@@@.@@..@.@.@.@@..@.@.......@@@@@@@@.@@@@@....@..@@@.@@@..@.@...@@@@.@@@.@@@.@@@@@@..@..@@@.@@. +@@@.....@@..@@@.@.@@@@@@@.@..@.@@.@...@@@.@..@@@@.@...@.@@.@@.@@..@@@....@@@.@..@@.@...@@@@@@@.@@@@@@@@.@.@@..@@@@@@@@@...@@@.@@@.@@.@@.@. +@@.@@@@.@..@.@@...@.@@@@.@@@.@..@.@.@@@@@@.@..@@@@@@.@.@@@@@@@@@@@@@@.@.@@.@@@@.@.@@@@@@.@...@.@@.@@@.@@..@@@.@@@@@..@.@@..@@..@@@@@@.@..@ +@@.@....@.@.....@.@@@@@@@@@.@.@..@@.@.@@@@@@.@.@..@@@.@....@..@@@.@@@.@.@.@..@@@@@@@@@@@@..@@@.@@@@..@@@.@@.@@@.@@@.@@@@.@@..@@@@.@@@@.@@. +.@@@..@@..@@.@..@.@.@.@@@@..@.@.@@@@@@.@@@@.@.@.@@@@.@@@@...@@..@@@@@.@@@.@.@.@@@@.@@.@.@@@@@.@.@.@..@@@....@@@@.......@@@@@@.@@@@@@@@@.@@ +.@.@@.@.@.@.@@@@@@...@@..@@..@.@@@@..@.@@..@@@@@@@@.@@.@@@@.@..@@@@.@.@@@.@.@@@.@@.@.@@@@.@.@..@@@@..@@.@@@...@@...@@@@@@@@@@@.@@@@@.@.@@. +@.@@.@@.@.@@@.@@@@@....@@..@@@@@@@@.@@.@@@@@.@.@@.@.@@...@@.@@@@@.@@.@@.@@.@@@@@@@@@..@@...@@..@@@..@@@@.@@@@..@..@@@@@@.@.@@@..@@@@.@@@@@ +@.@@@@@.@@@@....@@@@@@@@@..@@@..@@@@.@@@@@@@@@.@.@@@..@@@.@.@@.@@.@@.@@@...@@@@@.@@.@@@@@.@.@@@@...@..@.@@..@@@@@..@@@@@..@@@@@...@@.@...@ +@@@.@@.@@@@@@.@@.@@.@@@.@.@@@.@....@@@..@.@@@.@.@@.@.@.@@.@@@.@@@.@@@@@@.@@@@@@@@@@@@@@@.@@@@@@@@@.@.@@@.@.@@@.@@@@@@@..@@.@.@@.@....@.@@@ +@.@.@@@@@.....@@@@@.@@@@@..@@@..@.@@@@@...@...@@@.@@@.@@@.@@.@@.@@@..@@.@@@@.@.@@..@@@.@@.@.@.@@.@.@@@.@@@.@.@...@.@@@@@.@.@@@@@.@@.@@@.@. +@.@.@@@@@@@@@.@@@@....@@.@@@..@@@.@@@.@.@@.@@@..@.@.@..@@@..@@.@@@@@@@@@..@.@.@@@@@.@.@@@@@..@@@.@@@@@.@@@.@@.@.@@@@@@@@@@..@..@@@...@@..@ +@@@@@@.@.@@.@@@.@@..@..@@@@.@@@@.@.@@@@@@...@@@.@.@@@.@@..@...@.@@@@...@@..@.@@@@@@@@.@.@@@@@.@@@..@@@@@...@@@@@@..@@@.@@@@@@@@..@@@@@@@.@ +@.@@..@@@@@@@@@@.@..@@..@.@.@.@@@@.@@..@..@.@@.@@@@@@.....@..@@@.@@@.@@@@.@.@.@@@@.@.@.@@@.@..@.@@@@..@@@.@@.@.@@.@@@....@@@.@.@@.@@@@.@@@ +@.@.@.@@@@@.@..@.@@.@@@@@.@@@@@@@@@.@.@.@.@@@.@....@.@@@@@.@@.@@@@.@@@@.@.@@@@..@.@@@@....@@@@@..@.@@@@@@@.@@@@..@@@@...@@...@@@@@..@@@... +@@..@...@@..@.@@.@@@@@@@@@.@@@.@@.@@@@@@.@.@@@@.@.@.@@@@@...@@.@@.@.@..@@.@...@.@@@@.@.@@@@@..@@@.@@@@@@@.@.@@@@@@@@.@@@@.@@@...@.@.@@@.@. +@@@@@@@@@..@.@..@@@.@.@@@@.@.@@@@@..@..@@@.@@..@@@.@.@@@.@.@@@@@.@@.@@@.@@@@@.@@.@...@@@@..@.@@.@..@@...@.@@@.@@..@@@.@@@.@.@.@@@...@@@@@. +..@.@..@@@@@@..@@@.@@@@@.@@@@.@@.@@..@@@.@.@@.@@.....@@.@..@@..@.@@@@@.@@...@@@@@@@.@@...@@@@.@@@@..@@.@.@@@@@..@@@...@..@@@@@.@.@.@@@@@@. +.@.@@.@@.@@@.@@@..@@@@@.@@@@@@@@@.@@@@.@@@.@@.@@.@.@..@.@@@@.@@.@@@....@.@@@..@@@...@@.@@.@@....@@@.@@@.@@@..@@@@@@@..@@@..@@...@@...@.@@. +.@.@@@..@..@@.@@.@.@.@@@@@@@@@.@..@.@@.@.@@@@.@@@.@..@.@@@@.@.@@.@@@.@@.@.@@@.@@@..@.@@@@@@@@.@@.@.@@@@@@...@@.@@@...@.@@.@@..@@@..@..@@.@ +@@@@@.@@@@.@@@@@@@..@@@@@@@@.@.@.@@@@@@@.@@....@@.@@@@@@@@@@@@@@@@@@@@@@@@.@@@.@@@@..@.@..@.@.@@@@@@@@.@.@@@.@@@@@...@@.@.@@...@@@.@.@@..@ +@@@.@@@@.@....@@@@.@@@@.@@@@@.@.@.@@@@.@.@..@@@.@...@.@.@@@...@@@@@.@@@@@.@.@@@@.@.@@@.@@.@@.@@@.@..@@@@.@@@.@@@@@...@@@..@@@@.@...@...@@@ +.@.@...@@@.@@..@.@@.@@@..@@.@@.@..@@..@@@@@@..@.@@@.@@@@.@@@@.@.@@@@@@..@@.@@@..@...@@@@@.@@@@@@@@.@@@.@.@@@.@@@@@.@..@.@@..@@@@@@@.@@@@@. +....@.@...@@@@@@..@@@@@@@@@@@.@.@@@@@.@@@@@@@@.@...@@@.@.@@@@@.@@@@@@@.@.@.@@.@@@@..@...@..@@@.@@@@.@@...@@@@@@@@.@..@.@@@@@@..@@@.@@.@.@@ +@.@@@..@@.@@@.@@@@@....@@@@..@@@@.@.@...@@.@..@@@..@@...@@@..@@.@@.....@@@@.@@@@@@@@@@@@@@.@.@.@@@@@..@@@@@@..@@@@@@@@.@.@.@.@@..@.@.@.@.@ +@@@..@@@....@@.@@@@.@@....@@@@..@.@.@@.@@..@@@.@@@.@@@@@@@@..@@.@@@@@@...@@@..@.@@@.@@@@.@@@..@@@@@@@@@@@@@@.@@@@@@.@@@..@..@@...@@@@@@@.. +@@@...@..@.@..@@@@..@.@@@@@..@@@@.@....@@..@.@.@.@@@@@@@@.@@@@@.@.@...@@@.@@@..@@@@.@@@.@@@@.@.@@.@...@@@@@..@@.@@@...@..@@@@..@@@.@@@@@@@ +.@@@@@@@.@..@.@@..@@@@@@@.@@...@@@@@@.@..@@..@.@@@@@@..@.@@@@@.@@@@.@.@@.@@@...@@@..@@..@@@.@@@@@@@..@@@..@....@@@.@@@.@.@@@@@@@@@@.@@@@.. +.@@@@@@@@@@..@@.@@@.@@@.@@.@@@@.@..@.@@@@.@@@@@@@@@@@@@@.@@..@@.@@@@@@@@@@@..@.@@.@@.@@@@.@@..@@@@@@@@.@@..@@@.@.@@@...@@@@@.@@@.@..@@@.@@ +.@..@@@.@@@@@@@@@@.@@@@@@@@@@@@@@@@@.@..@@@@.@.@.@.@@.@@.@@..@.@@@@@@@@.@@@...@@@.@@@@@@@.@.@..@@@@@@@..@@@..@@@.@@@@@.@@@@.@..@.@@@@.@.@@ +.@@@@.@.@@@.@@@..@@...@.@@..@@.@@@@@@@@.@@@@.@@@@.@@.@@..@@...@@@@.@@@.@@.@.@@.@@.@.@.@@@.@@@...@@@...@@@@@@@@.@.@@..@.@@@@@..@@@..@.@@.@. +..@.@@....@@@.@@@@@...@.@@@@@@@....@@.@@@@@@@@.@@@@.@@...@.@@@@...@@@@.@@..@@@@@@.@@@.@@@@@@.@.@@@@.@....@@@@.....@@@..@@@.@@..@.@@@.@@.@@ +..@@@.@@@.@.@@@@@@@@...@@@@@@@@.@@@.@@@@@.@@@.@@@@..@@@..@.@@@@@@.@.@.@@@@@@@@@...@@@@@@@.@@@@@@...@@@@@@@@@.@@..@.@.@@@@@.@@.@@.@.@@@@@@. +@.@.@@..@@.@@.@@.@@@@.@@@.@@@@@.@.@.@@@@@@.@..@@.@.@@@.@....@.@@.@@.@@@@@@@.@@@.@@@.@@@@@@@.@@.@@..@@@@@@@......@..@.@@..@..@..@...@@@.@@@ +@@@.@....@@@@@@.@@@@@@@@@..@@@@.@@..@.@@.@@.@.@@@.@.@@.@.@....@@...@.@.@@@@@@@@@.@.@@.@.@@..@@.@.@@@@@@@.@@@.@.@.@@@..@@.....@@@@@@@@..@.. +@.@@.@@.@@@@@@@@.@.@@@@..@@@@@..@@@@..@@@@.@.@@..@@@@@@.@.@@...@@@..@.@@@.@.@@..@.@.@@@..@@@.@.@..@@@.@@@.@@.@@.@...@.@....@@.@..@@@@@.@.@ +@@.@@@@@@@.@@@..@@@@@.@@.@.@@@..@@@@@.@..@.@@@.@.@@@@@@@@...@@.@@...@@.@.@@.@@.@@@@@@@.....@.@.@..@@.@@.@.@..@@...@@.@..@.@@@@.@@@@.@@@.@@ +..@@@.@@@@@.@..@@@@@@@.@@@@@@@..@@@...@@@@@@..@.@....@@@@.@@@@.@.@@@@@..@@@@@....@@@@@@.@.@.@@@@..@@@@@.@@@@@.@@....@@@@..@@.@@...@@@@@@@. +@@..@@@@@.@.@@@@@@@@@@@@@@.@@@.@.@@@.@.@@.@.@@@@@@.@.@@@..@.@@.@..@@@.@..@@..@.@@@.@@@@.@@@@.@@@.@@.@@.@.@@@@.@@.@@@..@@@@@..@@@@@@@...@@@ +@.@@....@.@@@@@@@@@@@@@.@@.@@@@@.@@@@..@@@@@.@.@@@@..@.@.@@@.@@.@..@@.@@.@.@...@@@@..@..@...@@@..@@.@@@.@@.@.@.@.@..@..@@@..@..@@..@@@.@.@ +@.@.@.@@.@.@.@@..@@@..@@@@@@..@@@.@....@..@.@@@@@.@@...@@@..@@.@@.@@..@..@@@@@@.@@..@@@@@@@.@.@@@.@..@.@.@@...@@...@.@..@.@@@.@..@.@...@@@ +@@@....@@@..@.@.@@@.@@.@@@@@@..@@.@.@@@@@..@@.@@@@..@@.@...@@.@@@@@@@...@.@@@@@.@.@...@@@@@@@.@@..@..@@@..@.@@.@@@.@.@@..@@@.@..@@@.@@..@@ +@@@@@.@.@@@@.@...@@.@@@.@.@@.@.@@@.@.@@.@@@@@@@.@@@@@.@@@@..@@@@@@.@@@@.@.@@@.@@.@@...@@@...@..@@@@@@@..@@.@@.@@.@@@.@.@..@@@@@@....@.@.@. diff --git a/src/day04/src/lib.rs b/src/day04/src/lib.rs new file mode 100644 index 0000000..b2d3085 --- /dev/null +++ b/src/day04/src/lib.rs @@ -0,0 +1,3 @@ +pub mod part04a; +pub mod part04b; + diff --git a/src/day04/src/part04a.rs b/src/day04/src/part04a.rs new file mode 100644 index 0000000..dd6fd22 --- /dev/null +++ b/src/day04/src/part04a.rs @@ -0,0 +1,55 @@ +use std::fs::File; +use std::io::Read; + +pub fn solve() -> u64 { + let mut solution: u64 = 0; + + let mut file: File = File::open("src/day04/input04.txt").unwrap(); + let mut file_content: String = String::new(); + file.read_to_string(&mut file_content) + .expect("Can't read file"); + + let mut rows: Vec> = Vec::with_capacity(file_content.len() + 2); + rows.push(vec![0u8; file_content.len()]); + rows.append( + &mut file_content + .lines() + .map(|line| { + let mut col: Vec = Vec::with_capacity(line.len() + 2); + col.push(0u8); + col.append( + &mut line + .chars() + .map(|c| match c { + '@' => 1u8, + _ => 0u8, + }) + .collect(), + ); + col.push(0u8); + col + }) + .collect(), + ); + rows.push(vec![0u8; file_content.len()]); + + rows.windows(3).for_each(|rows| { + rows[0] + .iter() + .zip(rows[1].iter()) + .zip(rows[2].iter()) + .map(|((a, b), c)| (*a, *b, *c)) + .collect::>() + .windows(3) + .for_each(|cols| { + if cols[1].1 != 1u8 { + return; + } + if cols.iter().map(|(a, b, c)| *a + *b + *c).sum::() - 1 < 4 { + solution += 1; + } + }); + }); + + solution +} diff --git a/src/day04/src/part04b.rs b/src/day04/src/part04b.rs new file mode 100644 index 0000000..fc9e012 --- /dev/null +++ b/src/day04/src/part04b.rs @@ -0,0 +1,16 @@ +use std::fs::File; +use std::io::Read; + +pub fn solve() -> u64 { + let mut solution: u64 = 0; + + let mut file: File = File::open("src/day04/input04.txt").unwrap(); + let mut file_content: String = String::new(); + file.read_to_string(&mut file_content) + .expect("Can't read file"); + + solution +} + + + diff --git a/src/day04/story04a.txt b/src/day04/story04a.txt new file mode 100644 index 0000000..63d136e --- /dev/null +++ b/src/day04/story04a.txt @@ -0,0 +1,29 @@ +--- Day 3: Lobby --- + +You descend a short staircase, enter the surprisingly vast lobby, and are quickly cleared by the security checkpoint. When you get to the main elevators, however, you discover that each one has a red light above it: they're all offline. + +"Sorry about that," an Elf apologizes as she tinkers with a nearby control panel. "Some kind of electrical surge seems to have fried them. I'll try to get them online soon." + +You explain your need to get further underground. "Well, you could at least take the escalator down to the printing department, not that you'd get much further than that without the elevators working. That is, you could if the escalator weren't also offline." + +"But, don't worry! It's not fried; it just needs power. Maybe you can get it running while I keep working on the elevators." + +There are batteries nearby that can supply emergency power to the escalator for just such an occasion. The batteries are each labeled with their joltage rating, a value from 1 to 9. You make a note of their joltage ratings (your puzzle input). For example: + +987654321111111 +811111111111119 +234234234234278 +818181911112111 + +The batteries are arranged into banks; each line of digits in your input corresponds to a single bank of batteries. Within each bank, you need to turn on exactly two batteries; the joltage that the bank produces is equal to the number formed by the digits on the batteries you've turned on. For example, if you have a bank like 12345 and you turn on batteries 2 and 4, the bank would produce 24 jolts. (You cannot rearrange batteries.) + +You'll need to find the largest possible joltage each bank can produce. In the above example: + + In 987654321111111, you can make the largest joltage possible, 98, by turning on the first two batteries. + In 811111111111119, you can make the largest joltage possible by turning on the batteries labeled 8 and 9, producing 89 jolts. + In 234234234234278, you can make 78 by turning on the last two batteries (marked 7 and 8). + In 818181911112111, the largest joltage you can produce is 92. + +The total output joltage is the sum of the maximum joltage from each bank, so in this example, the total output joltage is 98 + 89 + 78 + 92 = 357. + +There are many batteries in front of you. Find the maximum joltage possible from each bank; what is the total output joltage? \ No newline at end of file diff --git a/src/day04/story04b.txt b/src/day04/story04b.txt new file mode 100644 index 0000000..64d1758 --- /dev/null +++ b/src/day04/story04b.txt @@ -0,0 +1,25 @@ +--- Part Two --- + +The escalator doesn't move. The Elf explains that it probably needs more joltage to overcome the static friction of the system and hits the big red "joltage limit safety override" button. You lose count of the number of times she needs to confirm "yes, I'm sure" and decorate the lobby a bit while you wait. + +Now, you need to make the largest joltage by turning on exactly twelve batteries within each bank. + +The joltage output for the bank is still the number formed by the digits of the batteries you've turned on; the only difference is that now there will be 12 digits in each bank's joltage output instead of two. + +Consider again the example from before: + +987654321111111 +811111111111119 +234234234234278 +818181911112111 + +Now, the joltages are much larger: + + In 987654321111111, the largest joltage can be found by turning on everything except some 1s at the end to produce 987654321111. + In the digit sequence 811111111111119, the largest joltage can be found by turning on everything except some 1s, producing 811111111119. + In 234234234234278, the largest joltage can be found by turning on everything except a 2 battery, a 3 battery, and another 2 battery near the start to produce 434234234278. + In 818181911112111, the joltage 888911112111 is produced by turning on everything except some 1s near the front. + +The total output joltage is now much larger: 987654321111 + 811111111119 + 434234234278 + 888911112111 = 3121910778619. + +What is the new total output joltage? \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e6f0838..39d2a62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,44 +1,60 @@ -use std::fmt::format; -use std::time::Instant; use day01::{part01a, part01b}; use day02::{part02a, part02b}; use day03::{part03a, part03b}; +use day04::{part04a, part04b}; +use std::fmt::format; +use std::time::Instant; use std::fs::OpenOptions; -use std::io::Write; use std::io::Result; +use std::io::Write; fn main() { let mut file = OpenOptions::new() - .write(true) // Open the file for writing - .create(true) // Create the file if it doesn't exist - .truncate(true) // Clear the file if it already exists - .open("README.md").expect("Cannot open or create file"); + .write(true) // Open the file for writing + .create(true) // Create the file if it doesn't exist + .truncate(true) // Clear the file if it already exists + .open("README.md") + .expect("Cannot open or create file"); - file.write_all(b"# Advent of Code 2025\n```bash\n").expect("Cannot write to file"); + file.write_all(b"# Advent of Code 2025\n```bash\n") + .expect("Cannot write to file"); - let exercises: Vec<(&str, fn () -> u64)> = vec![ + let exercises: Vec<(&str, fn() -> u64)> = vec![ ("day01:A", part01a::solve), ("day01:B", part01b::solve), ("day02:A", part02a::solve), ("day02:B", part02b::solve), ("day03:A", part03a::solve), ("day03:B", part03b::solve), + ("day04:A", part04a::solve), + ("day04:B", part04b::solve), ]; let start: Instant = Instant::now(); exercises.iter().for_each(|(day, func)| { let day_start: Instant = Instant::now(); - let solution = format!("{:7} => {:15} ({:6}us)\n", day, func(), day_start.elapsed().as_micros()); + let solution = format!( + "{:7} => {:15} ({:6}us)\n", + day, + func(), + day_start.elapsed().as_micros() + ); print!("{}", solution); - file.write(solution.as_bytes()).expect("Cannot write to file"); + file.write(solution.as_bytes()) + .expect("Cannot write to file"); }); let banner = " ----------\n"; - let end_time = format!(" {:7}us\n", start.elapsed().as_micros()); + let end_time = format!( + " {:7}us\n", + start.elapsed().as_micros() + ); print!("{}", banner); file.write(banner.as_bytes()).expect("Cannot write to file"); println!("{}", end_time); - file.write(end_time.as_bytes()).expect("Cannot write to file"); + file.write(end_time.as_bytes()) + .expect("Cannot write to file"); file.write(b"```").expect("Cannot write to file"); -} \ No newline at end of file +} +