From d9d2aa4e5ec14a60fedba2bdf9ed4a3005a329e4 Mon Sep 17 00:00:00 2001 From: Devon Sawatsky Date: Thu, 4 Dec 2025 05:27:16 +0000 Subject: [PATCH] day4 part1 --- Cargo.lock | 18 ++++++ Cargo.toml | 1 + input/day4.test.txt | 10 ++++ input/day4.txt | 137 ++++++++++++++++++++++++++++++++++++++++++++ src/day4.rs | 106 ++++++++++++++++++++++++++++++++++ src/lib.rs | 16 ++++++ 6 files changed, 288 insertions(+) create mode 100644 input/day4.test.txt create mode 100644 input/day4.txt create mode 100644 src/day4.rs diff --git a/Cargo.lock b/Cargo.lock index 25df959..7567d52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,3 +5,21 @@ version = 4 [[package]] name = "aoc2025" version = "0.1.0" +dependencies = [ + "itertools", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] diff --git a/Cargo.toml b/Cargo.toml index cfe6cd5..97dbdc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +itertools = "0.14.0" diff --git a/input/day4.test.txt b/input/day4.test.txt new file mode 100644 index 0000000..9ad769d --- /dev/null +++ b/input/day4.test.txt @@ -0,0 +1,10 @@ +..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@. \ No newline at end of file diff --git a/input/day4.txt b/input/day4.txt new file mode 100644 index 0000000..d60afe6 --- /dev/null +++ b/input/day4.txt @@ -0,0 +1,137 @@ +@@@.@..@@.@@..@.@@@...@...@@@.@@..@..@@@@@@.@@.@@@.@@@@@@@@@@@@@......@@@@@@@@......@@.@@@@@@@.@.@@.@@@@@.@...@......@@@@@@@@@@@@.@@@@@@@ +@@@.@@@@@@@@.@@@@.@@@@.@.@.@.@@@..@..@@@@...@@@@@@@@.@@@.@@@@@@.@..@@@@@.@@.@.@.@@@@.@@@......@@@@@.@..@@@...@@@@@@@@@@.@.@@@@@@@@.@@@@.. +..@@@@.@.@.@@@.@@@@@..@@@@.@@@@..@@@.@.@@@...@@@@@..@@@@.@@@@@..@@@@@...@@..@.@@@@.@@.@@.@@.@@.@..@.@@@@@....@@@...@@.@.@@@@@.@.....@@.@@ +.@@@..@@.@.@@.@@@@@@..@@@.@@..@@@@...@@@.@@@.@@.@@@@@@.@@@@..@@@@@.@@@@@@@..@@....@@.@....@@@@@.@@.@@@..@@@@.@.......@@@@...@@@@.@..@..@@ +@@@..@..@@@@.@.@@@@@@..@@@@..@.@.@@@.@..@@@@@.@...@..@..@...@....@@..@@@...@@@@@.@.@........@..@@.@.@@...@@@@@.@@@@..@.@@@@...@..@@.@@..@ +@.@@.@.@..@@@@.@.@@@...@@@..@.@.@@..@.@@@......@..@...@.@@.@@@.@@@.@@@@..@@.@.@@@@.@..@..@.@@..@@@@.@@@@@@@@@@@@..@@@@..@@.@.@@..@@..@..@ +.@...@@......@..@@@@@...@@@@@.@@@.@@@@@.@@..@@@@@@@.@@@@@@@@@.@.@..@@@@...@@.@...@@@@@.@@@@@...@.@.@.@@.@@.@.@@.@@@@.@@@@@@@@@.@.@.@...@. +.@@@...@@@.@....@@@@@@@.@@@.@@@@.@@...@@.@@@@@@...@@@@@..@.@...@.@@..@@..@@@@@@.@@@@@@@@@@..@.@@..@..@.@@..@@.@@@@@@@@...@....@.@@@@@@@@@ +.@..@@@@@@@@.@@@.@@@@@@@.@@@@@.@.@.@@@@..@..@@@..@@@.@@@@.@@.@@@@@..@@@.....@@@.@.@@@@.@@.@.@@@@.@@...@.@@@.@@@@@@@@@..@.@..@@@@@@@.@@@@@ +.@.@@.@.@@@@@@@@@@@..@@@@@@....@@@.@.@.@@@.@@@@@@@@.@@@@@@@..@@..@@@..@@@...@.@@@@..@@@@..@@@@@@@@@@@@.@@.@@@@@@@@@@..@.@.@.@@.@@.@....@. +@@.@@@@@..@.@.@@@@@@..@@@.@@.@.@@..@@@@.@@..@@@@@@@@.@@@@@@@.@@@@@@@.@@@@...@@@@.@@@@@@@.@@..@@.@.@@@@@.@@@@@@@.@@@@@@@@.@.@.@.@@@@@@@@.@ +..@@.@..@@.@..@.@.@.@@...@@@...@.........@@.@.@@@.@.@@.@.@@.@@@@@@@@.@.@.@@.@@.@@@@@@@@.@@..@@@@@.@@.@@@@@@.@.@.@@@.@.@.@.@@@.@@.@@...@@@ +.@@.@@@..@..@@@....@@@.@@@@@@@@..@@@@..@@.@@@@@..@@.@..@@@@@@@.@@@@@.@@@@.@@@@@@@@@@@.@..@@@..@@.@.@@....@@..@@.@@...@..@@@@@@@..@.@@@@@@ +.@@.@@@@@@.@@@@.@.@.@..@@@@.@..@@..@.@@@@@.@.@@@@@@@@@.@@@..@.@.@.@.@@@@@@@@@@@@...@@.@@@@@@@..@.@.@@@..@...@...@@@@.@@.@@@.@.@.@@@...@.. +@@.@..@@..@@..@.@@@.@@@@.@@@@@@@..@.@@.@@@.@.@.@@@@@@.@@@.@.@@@@@@.@@.@@@.@@@@@@@@@@@@@@@.@.@@@@@@..@@@@..@@.@@.@@@@@.@.@@@@@.@@@@.@@@@@. +@@@@@.@.@@@.@@..@@.@.@@@@@.@@@..@@@@@@..@...@....@.@@..@@@@.@@@@.@..@@.@@.@@@@.@..@@.@@@@..@@@@.@.@@..@@@@.@.@.@.@@@.@@@@@@.@@@@.@...@@@@ +@@.@@@..@..@.@.@@@@@@@@@@@....@@@@@@@.@.@@@....@@.@@@@@@@@@@..@@.@@.@.@.@..@@.@.@.@...@@.@.@@@@.@@@@@@@@@@@...@.@..@.@..@@@.@@@.@..@@@@.. +.@..@@@..@@.@@.@..@@@@@@..@@@@.@@@@@@@@@@@@.@.@.@@@@@@.@@.@@@@.@@@.@..@@@@@.@@@@@.@.@.@@@@@@.@.@@.@.@.@@@@.@..@@@.@@.@@@.@@.@@@@..@...@@@ +@@....@@.@.@@....@.@@.@@@@@@@@@@@@@..@.@..@@@@.@@.@.@@.@.@@..@..@@@@@@@@@@@@@@@@@@..@.@@@@@@.@..@@@@@.@.....@@@..@...@@@@..@@@@.@@.@@.@@@ +.@...@@@.@@.@.@@.@@@@.@@@@....@@@@@.@@@@@@@@.@@.@@..@@@@.@@.@@@@@.@.@.@@.@.@@@@.@.@@.@@@@..@@@@@@.@@@@.@@.@@..@@@@....@@@@@@.@@.@@@@@@@.@ +.@@.@@@@@@@.@@@.@@.@..@@@.@@@@@@@.@@@@..@@@@@@...@@@..@..@@@@@@@.@@@@...@@@@@..@@@@@@..@@.@@.@@.@@@@@@@@@.@@@@@.@@...@@@@@@@.@@..@.@.@@@. +@@@@@.@@.@@@.@@@@@@@@@@@@.@.@.@@@@.@@.@...@@@@@@...@@..@@@@.@@@@@@@.@.@@.@@@.@...@.@.@@.@@.@@..@@@@...@@.@@@@.@@@@@@@.@@@..@.@...@@@@@... +..@@@@@@.@.....@.@..@@.@@@.@@@@.@@@@..@..@.@@....@@@@@.@..@@..@@..@.@@.@@@..@...@@..@@.@@@@@.....@@@@@@@@@@@@..@@@@@@@..@@@.@@.@@.....@@. +@@@@@.@@.@@.@@.@@@@@@.@@.....@.@..@..@@@@@@.@@@.@@@@@@..@@..@@@.@@@@@.@@@...@..@@@...@@@@.@..@@@@@...@@..@.@@@..@.@@..@@@@.@.@.@@@...@.@@ +@@@@@@@@@@@..@@@@.@@@..@@.@.@@@@@@@.@@..@..@@@....@@@@@..@.@..@@@@@@...@@..@@@@@@@@@@@.@..@..@@@....@.@@@..@@@@..@@....@.@.@@@..@.@.....@ +@.@@.@....@..@@@@@@@@@@@.@........@.@@@@@@@@..@..@.@@.@.@@.@@@..@..@..@...@@@@@@@@.@..@@@...@@@@@@@@.....@@@..@@@.@@@.@@.@@..@.@@.@@@@@@. +.@@@..@@@@..@@.@.@@@..@.@@.@@@@@@@@@@.@@...@@@@@@@@@...@@..@@.@@..@@@@@.@@@@..@.@..@.@@@.@@.@@@.@@@@.@@@@@@.@@.@@@.@@..@.@@@.@.@@@@@.@@@. +@@@.@@.@@.@..@..@....@.@@@@@@@..@@.@@@..@@@@@..@@@@@...@...@@@@.@@@.@..@@@..@..@@@@@.@@.@@@@@@.@@@@@.@@@@..@..@@@.@@@@.@@...@..@.@..@@@.@ +@..@.@.@@@.@@@@.@.@@@.@.@@@@..@@@@.@@...@@@....@@..@@.@@@@@@@@.@.@@@@@..@@@@@@@@...@.@.@@@.@@.@...@@@@@.@@....@@.@@@@@@....@.@.@@@@.@.@@. +@@@@@@..@@..@.@.@...@@@..@....@..@@..@@@@@@@@..@.@...@@@@@@@.@.@@.@@@.@...@@.@@@@@..@@@@@@..@@@@@.@@@.@@@@@@.@@...@@@@@.@.@.@@@@..@.@@..@ +@...@@@@@@@@@@@@.@@@@@@@..@..@.@@@@@..@@@..@@...@..@@.@.@.@@@.......@@@@@....@...@@@@@@@@@@@.@.@.@.@@@@@@.@@@.@@....@@@.@....@@@@@@@@.@@. +@@.@@@.@@.@.@@@@.@.@.@@@.@.@@@@..@.@@@@@@@@@.@.@@@@.@@@..@...@@@.@.@.@.@@@@@@.@@@@@.@@@..@@@@.@.@@@@@@.@@@@@.@@..@@@@@@@@@@.@..@@@@@@@@@@ +@@.@..@@@@@.@@@@.@@@@@@@@@@@@...@@@@@.@..@..@.@@@@@@@@..@.@@@@@..@.@@@@.@..@@..@@@@@@@@@@..@@@.@.@@@@@@.@@@@.@@@@@@@@@@@@@.@@@@..@@@@@@@@ +.@.@@@@..@.@.@...@@@@.@..@@@@@@@@@...@@@..@.@@@..@@@@@@@@@...@@@@@@.@@@.@@.@@@@@..@@..@@....@@@@@@@@.@@@@.@@..@@@@@@.@.@@@@@.@@@@@.@@@@@. +.@@@@@@@@@..@..@@@@.@.@.@@@@.@@@...@@.....@.@.@@@@@@@@@@@@@@@@.@.@..@@.@.@@@..@@..@@@@@@@.@@.@@@.@@@@@..@@.@@@@@@@@@@@@..@@@@.@.@.@.@@@@@ +@@.....@.@@@@@@.@@.@@@@@@@@@@@@.@@@@@@.@@@@@@@@...@@..@@.@@.@@@@@@@.@@@.@.@@@...@@@@@@@@.@@@@@@.@@@@.@@@@@@@@.@@..@..@..@@@....@.@@@@.@@. +@....@..@.@..@.@@@@@@.@.@.@@@@..@.@@@...@@@.@..@.@@@@...@@@@@@@.@.@.@.@@@@@@@@@@@..@.@@..@@.@@@@@@@@...@@@.@@..@.....@@@@@@@@@@..@@.@@.@@ +..@@@...@.@@.@@@.@@@...@..@@@@@.@..@@.@.@@@.@@@.@@..@@@@@@@@@@@@@.@@@@@..@.@.@@@@@@..@@@@..@@@...@.@@@@....@...@@..@@@..@@@@@..@..@.@@... +.@@@@@@@@.@.@@.@@.@@@@@.@@.@........@@..@@@.@.@@..@@..@@@@.@@@@@.@@.@@@@@@@.@@@.@@@..@@....@@...@@@.@.@.@@@@@@@@.@@@...@@@@@@@@@@.@..@@.. +@.@@.@.@@@@.@.@.@@@@@..@.@.@...@@@.@.@.@.@@@@@@@.@.@@.@@@.@@@@@.@@@@@@.@.@@..@@@..@.@@.@@..@.@@@@@@@@@@.@....@@@.@@@@@@@@@@@@@@@...@@@@.. +@@.@@@..@.@@...@@.@@@@.@@@@@.@.@@.@@@@@@@@@...@@@@@.@@@@@@..@.@@..@@@.@.@@@..@@.....@.@@.@.@.@..@..@@@.@.@@.@@@@@@@.@.@@....@@.@@@@...@@@ +@.@@.@@@@@..@@@@.@..@..@@.@.@.@...@@.........@@.@.@@@@.@@..@@.@@.@@@.@.@.@@.@@.@@..@.@@.@.@@@@@@@@@@@..@.@@@.@@.@@@@@@@.@.@@...@..@@@...@ +@.@@@...@@.@@.@@@@.@@..@@@.@@.@@......@@.@@@..@@.@@..@@@@@.@.@.@@....@..@@@..@@.@@.@@@@@@@.@@@@@@@@...@@@@@@@@@@@@@@@...@...@..@@.@.@@@@@ +@@@@.@@.@@@@@@@@@.@.@@....@...@@.@..@.@.....@@@.@@....@@..@@..@.@.@@@@....@.@@@@@@.@@..@@.@@@.@@@.@@@@@@@@@@@..@.@@..@.@.@@@@@@.@@@@@@.@@ +...@@..@..@@@..@.@@@@@@@.@.@@@.@.@@@.@.@@@.@@.@@@@@..@@.@...@@@..@.@@@@@@@.@.@@@.@@@@@.@@@@@@@@.@@.@.@@@@@.@..@.@@@@@@@@@@.@@...@.@...@@. +.@@@@@@@@@@..@@@@.@@.@.@@@.@@.@@..@@@.@@@@@.@.@@@..@@@@@@@.@@@@@..@@@@@.@@.@@@..@@@@@.@@@.@..@..@...@.@.@.@@.@@.@@@@@@@.@@@@@.@@.@@@@..@@ +@..@.@.@@..@.@@@@@.@.@@.@..@@@.@@@@..@..@@@@@..@@..@@@@..@.@@.@@.@@@@@@@@@@@@@@......@...@.@@@@.@..@.@.@@...@@@@@@@.@.@@.@@.@@@....@.@@@@ +@@@@@@@@@@.@@@..@@.@@@.@@.@..@@.@@.@@@@@@...@..@.@....@.@@.@@@@@@.@@.@@@.@@.@@@@@......@@.@@..@@@.@.....@@@@@@@@.@@..@@.@.@.@@..@@.@....@ +@@.@@@..@@@.@@@@@@@@@@...@@.@.@.@@.@@.@.@....@@@.@@..@....@.@@.@..@@@.@@@.@..@.@..@..@@@@@@@@@.@.@.@.@...@@@@.@.@@@.@...@@@@@@..@@...@@@@ +@@@@.@@.@@@.@@@@@@@@@@@...@@.@@..@.@@@...@@.@.@.@@@@@@.@@@@..@@@@..@@..@.@.@@@@@.@.@@@@.@@@.@@@.@.@@@..@@.@@..@.@@@@@@@.@@@..@@@@.@.@@@@@ +@...@@.@@@@@@.@.@@@@@@@@@@@@@@@@@@..@@..@@...@@.@.@@@@.@@.@@@@@@@.@.@.@@.@@.@..@.@@@@..@@@...@@.@.@@..@@@....@@.@..@...@.@@@.@@@@@@@...@@ +@@..@..@.@.@@@@.@@@..@.@@@@@@@@.@@@.@@@.@@@.@@..@@.@@@@.@..@.@..@...@@.@@@@...@@@@@..@@@..@...@.@@.@@@.@.@@@.@.@....@..@.@@@@@@@@.@@.@@@@ +@@@@@@..@@@....@@.@.@...@@@@@.@..@@@@@@..@...@@.@@@@@@.@.@@.@@@@.@.@.@@@@@@.@.@@@@@@@@.@...@@@@@@.@.....@@...@@...@@@@@@@.@@@@@@@@.@.@@.. +@@@@@@@@...@@@@..@..@..@@@..@@.@@@@@@.@@@..@@@@.@@.@..@..@.@@.....@.@@..@@@....@@@@@@.@@@@@@@@@@@@..@.@@@@@@@@....@.@@@.@@@@@@@@@@@..@.@. +@@@@@.@..@.@@.@@@@..@.....@.@@@.@.@.@@@.@@@@@..@@.@@@@@@..@@.@.@@@...@@.@.@@..@.@.@@..@.@.@@@@@.@@..@..@@@...@@@.@@@@@@@@@...@@@.@@..@@@@ +..@@...@@@@@@@@@@.@.@.@..@@.@@@@@@@@....@@@.@..@@@@.@@@@@.@.@@@.@@.@@.@@@@@@@@@..@@.@@@@@@.@@@@@@@..@@@...@@.@@@@@@@@.@.@@@@@@.@@@@...... +@@...@...@@@.@..@@@.@@@@@@@@@@@@@..@.@@.@@@@@@@@@@.@@.@@.@@.@@@@.@.@@..@@@@.@@.@@.@...@.@......@@.@..@.@@@@@@.@@@@@@....@.@....@..@@@@..@ +@.@@@@@@@@@.@.@@@@@@@@@@@@..@.@@@@.@@.@@.@.@@@...@@@.@@@.@@@@..@@@@@@@@..@@.@@..@.@@.@@@.@.@@@@.@@@.@@@@@@.@@.@@.@@@...@@@@@@.@@@@.@@@.@. +@@@.@@@@@..@@@@@@.@.@@@@.@@...@@@@@.@@@@.@.@.@.@@.@..@@..@@@@@@...@@@@.@..@@@..@@.@@@.@@@@@@@@.@@@@@@.@@.@.@@@@@@@@@@@.@.@@..@@@@.@.@.@.. +...@@@..@..@@..@@@@@@@..@@.@@@...@@.@@@@@@.@@@@@..@@@.@@@@@@@@@.@@@@@@.@.@.@@@@@..@@@@@@.@@.@@@@.@.@@@@@@@@..@@@@@@.@.@.@@.@...@@@@@...@. +.@@@....@.@.@.@@@@.@@@@@@@.@@@@.@.@@@@@@.@@@@.@@@@..@@..@..@@.@...@@@@@.@@@@@@@@.@@@@@@.@@@@@.@@@@@@@..@.@@@@@..@.@@@@.@@@@..@@@@@.@.@.@. +..@..@.@..@@@@@.@..@.@.@@@@@.@@@@..@.@@@@@...@.@@.@@@@.@@@@.@.@@..@..@....@@.@.@@..@.@@@@.@.@@.@....@.@@.@@..@..@@..@@@@@@@.@@.@.@@@@.... +@..@.@...@@.@@@@.@@..@@.@@..@@.@@@@@@@.@@@@@@@.@...@..@@@@..@@@@.@...@..@@@@.@.@@@@.@.@...@.@.....@.@@.@@@@.@@.@@@@@@@@@@.@..@@@.@.@@@@.. +@@@@.@@@@..@.@...@@@@.@.@@.@.@..@.@@@@@.@@.@@@.@@.@@....@.@@@@...@@@..@@@..@@@@@@@@@@@@.@@@..@@@@.@@@@@@@@.@.@@@.@..@@.@.@@@.@@@@..@@.@@@ +...@.@.@.@@@@@@@@.@@@@@@.@@.@@.@.@...@...@@@@@..@.@@@...@@@.@@@@@.@@@@@@@@@@@.@..@@@..@@.@@@@@@@@...@@@.@@..@@@@.@@@@.@@..@@@@@.@@@@@@..@ +@@..@@@@.@..@.@.@@@....@@.@@@@..@...@...@.@@..@@....@@.@@@@.@@@..@...@@@.@@@.@@.@..@@@..@..@@@@@@..@@.@@@@@@@@@@@.@@.@@@@@...@@@@.@@.@@@. +@@@@..@.@.@@..@@@@.@@@@.@@@@@@.@..@@@.@@.....@.@@.@@.@.@@@@@.@@@@..@.@@..@...@.@@@@@@..@.@@..@..@@@@@.@@@@.@...@@..@..@@.@@@@.@.@@@@@.@.. +@.@..@@@..@@.@@@@@.@@@...@@@@@@.@@@@.@.@@@@@@@@@@@.@@@@.@@@@@@.@@@@@....@@..@@@@@@@...@.@..@@@.@.@..@@@..@@....@..@@@@@.@@@@@@.@@@@.@@@@. +@@@....@@@.@@@.@.@@...@@@..@@.@.@@.@@@.@@@@@@@@@.@@..@@..@@@@..@@@.@.@@..@..@@.@.@@@..@@@@@@@.@@.@.@@@@@.@@@@.@@@.@@@.@.@@.@@@.@@@.@@@..@ +@.@@.@@@@@@@.@@..@@@@@@..@@@@@@@@.@@@@.@@@..@@.@@@@@@@@@@@.@@...@@@@.@..@@@.@@@@@@@@@@@@.@@@@@@@@.@.@@@@@@.@@.@@@@@@@@.@....@.@@@@.@@.@.. +@.@@..@@@@@@@.@@@@@@.@..@@.@..@.@@@.@.@@@..@@@@@@@@@@@@@..@@@@.@@.@@@@.@@@@.@..@.@@.@.@@.@@@..@.@@@@@.@@.@@.@@.@@@.@@.@@@@@..@@..@.@.@@@. +.@.@..@.@@@@@@@@@@@@@@..@@@@..@@@.@@@@@.@@@.@@@@@@.@..@@@.@.@@@@@@.@.@@.@.@..@.@@@@@@..@..@.@@@@@@@@@.@@.@@....@.@@.@@@.@@@.@@.@@@@.@@@@@ +...@@@.@@@.@.@.@@.@@@@@@@.@..@.@@@@.@.@..@@@@.@@..@@.@@@@@@@@.@@@.@@@@@...@.@@.@..@.@@@@@@@@.@.@@.@.@.@@@.@@@@@@.@...@..@.@@.@..@@@@@.@@@ +@...@.@..@...@@@.@@...@.@.@.@@@.@.@@@@.@@.@@@@..@@.@@@@..@....@..@@...@.@@@@@@@@.@.@@@@@...@@@...@@@@@.@.@@..@@..@@@.@.@@@@@@@@.@@@@.@@@. +.@@@..@@.@@@@.@.@..@@@@.@.@..@@.@.@@.@@.@@@@@@.@..@@..@@.@@@@..@@@@@@@@..@@@..@@@@..@@@@@@@@@@.@.@@@..@@@@...@@@@@.@@@.@@@@@@@@....@@.@@. +@@@.@@..@@@.@.@.@.@@..@@@..@.@@@.@@...@@.@@.@@@@.@@@@@@.....@@@@@@.@@.@...@@@.@@@.@.@@@@.@@.@..@@.@@.@@@..@..@@.@@@..@.@@@@.@.@@@@..@.@@@ +@@@.@@@@@@@.@@@@@.@.@@@@@@.@@....@@@.@.@@@@..@@.@@@@.@@...@.@@.@@@.@.@...@@@.@@.@@.@.@@.@....@@.@@@..@@@@..@@@@@.@@.@@@@@@@@@@@..@@@@@@@@ +@..@.@@@@.@@@.@..@..@@@.@@@@@@@.@.@...@..@.@@@..@.@@@.@@@@@.@@@@@@@.@@@.@@....@@@.@@..@.@@@.@.@@.@.@.@@@.@.@.@@..@@@@.@@.@@.@@@@@@@..@.@. +@.@@@.@@.@@@@..@.@@@....@@@.@@@@.....@@@.@@...@....@.@.@@...@@@...@.@@@..@@@@.@.@@@@@@@@.@@@@.@.@..@@.@@@.@..@@.@@.@@.@@@@...@.@@@@...@@@ +.@@@@@@@@@@@@@.@@@@.@@@@..@..@..@@@.@.@@.@@@..@@@..@@.@@.@@@@@@.@....@.@@@@@@@@@@.@@...@..@@..@@.@.@@@.@@@@@.@@..@@@..@@.@@@.@.@@@...@..@ +@@@@@@.@...@@@...@.@..@@@@.@..@....@@@.@.@...@@.@@@..@.@@...@.@@@@..@@.@@@.@@@.@@@@@@@@@@@@@..@.@@.@@@..@@@@@..@@.@@.@@@@@@@@..@.@@@@.@@@ +@@@@.@@...@@@@@..@.@@@@..@@.@.@@@@@@..@@@.@.@.@@@@..@@@@@...@@@.@@@..@.@.@@.@.@@.@@...@.@...@..@@@@@@@@@..@@@....@@.@.@@@@.@.@.@@..@@@@@. +.@@@.@@@.@@.@@@.@@..@@@.@.@..@.@.@.@@@@@@@.@.@@..@.@..@...@.@@@.@.@@@@..@@@..@@@.@@@@@@@...@@...@.@@..@@@@@@@@@.@@@@@@@@@@@.@@@@@.@.@.@@@ +@.@@@@.@..@@@@.@@@@@.@@@@@@.@@@@.@.@@.@.@.@@@@@@@...@..@@@@@@@@@@.@.@@@..@.....@@@@...@....@@@@@@.@@@@@@@.@.@@.@.@....@@@@...@@@@..@.@@@. +@@@@@.@.@@@..@@.@.@@..@@@.@@@@@.@...@..@@@.@@@@.@@..@@.@..@...@.@@@.@.@@@.@@.@.@..@.@..@.@@@..@.@.@@@@.@..@@@.@@@@.@.@..@@@.@@@.@@@@@.@@@ +@..@@@@.@.@.@@@@@@@@...@@@@@@..@@@..@@.@@..@@@@@..@@@@@...@.@.@@@@..@@@@@..@.@.@@@@.@.@@@.@@@..@..@@@.@@@..@.@.@@@@@@@@@@.@@.@...@@@@@@@@ +@.@@.@@.@..@.@@@.@@.@.@@.@.@..@@@@.@@.@@@@.@@@@@@@.@@@..@.@@@@@..@.@@@@@@...@@@.....@.@.@@@@@@@.@@.@.@.@@@...@@@@@@@..@@@@.@@@.@@@@.@@@@. +@@@@.@..@.@@@.....@@@.@.@@.@@@@@.@@@.@@@@...@@.@.@.@@@@..@.@...@@@@@@@@@..@@.@@@@.@@.@@@@.@@..@@@..@.@@@@...@@@@.@..@@@@@@.@@.@..@@@.@.@. +@@@.@@@@@.@@.@@.@@@@@@@@.@@..@.@@...@@.@@..@.@@@@@@.@..@.@@@..@@@.@@.@@.@....@@......@@.@@@..@@@..@@.@@@...@@@@@@@.@....@@@@.@@@@..@.@@.. +@@@@@@.@....@@.@@.@@@...@@.@.@@@.@.@@@@@.@@@.@..@@@@@@.@..@@@.@@@.@..@@.@@@@@@..@.@@@.@@@.@.@@@..@.@@...@@@.@@.@@@@@@@@.@@@@.@..@@@.@..@@ +@@.@.@.@@@@@@@.@@.@@@..@@.....@.@@.@@@.@@@.@@@@@@@@@@.@.@.@@@.@@.@.@..@@@@@@@@.@..@..@@@@@@@@@.@@@@@@..@.@..@..@@...@@@@.@.@@@..@@@@.@.@@ +.@@@@@.@.@@@@@@@@@@@@@.@@..@@@@@@..@@.@@@@@@@@.@@...@@@@@@.@.@.@@@..@@...@@.@.@@@@@@@@@.@@...@@@@@.@@@@@..@@@@@@.@@@...@@@.@@@@@@@@@@.... +@@@@@@.@.@.@.@@.@@.@@@..@..@@.@@..@@@@.@@.@.@.@@.@@@@@@@@..@@@.@.@.@.@@@@.@......@.@.@@@@@@@..@@@@@@.@..@@.@.@.@@..@..@@@.@@@@@@.@@@@.@@@ +....@@@@@@@@@@@@@@@.@@..@@.@@@@@..@...@.@@...@@..@@@@@@@@@@@@@.@.@.@@@.@.@@.@.@@@.@@@@@@@.@@@@.@@@@@.@@@@@@@..@@@@@...@...@@.@@@@@@..@@@. +@@@.@@@.@.@@@@@.@@@@@.@@@..@@..@@@@@..@@@@.@@...@@.@..@..@@@@....@.@.@@.@@@@.@....@@@.@@..@@..@@@@.@@@@@..@@@...@@@.@@@@@@@@@@@@.@..@@@.@ +..@.@.@@@@..@@@@..@@@@.@@@.@..@@.@@@@@@.@@.@.@.@..@@@@@.@@@@..@.@..@.@@@@@.@.....@@@...@.@@@@..@..@..@.@@.@.@@@.....@@.@@.@@...@@...@@@@. +@.@@@..@@....@..@@.@@.@.@@.@.@.@@@.@@@@@....@...@@@.@@@.@.@@.@.@@@@@@.@@@.@@.@@@@@@..@@@@.@..@.@@@.@.@@@...@.@.@..@@@@.@@@@@@.@.@@...@@@@ +@@.@....@@@@@..@@@..@.@@.@@@..@@@@@@@@@@@@@@@....@@.@@@@.@@@@.@.@.@@.@.@.@@@@@@@@.@@.@@@@@@@..@.@@@@@@@.@...@@@@@@@....@@@..@....@.@@@.@@ +@.@.@@@@@@@@@.@@@@@@.@...@@@.@@@..@@@@.@.@@.@@@.@.@@.@@@@@.@@@.@@@@.@@..@@.@.@@.@@.@@@.@.@@@@..@@@.@@@.@..@@@@@.@@..@@..@@...@@@@@@@@@@.@ +.@@@@@@@@@.@..@@.@@@@..@..@@@@@.@@...@.@@.@.@@@@@@@@@.@@@@....@@.@@@@@...@...@.@@@@@.@@@@@@.@..@@..@.@@@@@.@@@@.@@@@.@@.@@@.@@.@...@@.@@. +..@@@@@@@.@@@@@@@@@@@@@@..@@@.@@@@@@..@@@.@@.@@@@@@@@@@@.@.@@..@@@@@.@@@.@.@@@@..@...@@.@@@@.@@@@.@@@@@..@.@@@@.@@.@.@.@.@@@.@@.@@@..@@@. +@@@@.@@@@.@@.@@@@@@@.@.@@@@@@.@.@.@.@@..@@....@.@@@@@.@..@.@@...@.@@@@@@@.@.@@@.@.@@.@@...@@@.@..@@@@@@...@@..@@@.....@.@.@@@@@@...@@@@@@ +@..@..@@.@@@..@@.@@.@.@@@...@@.@@@.@@.@@@.@...@@@@.@.@@.@@@.@..@@@@.@@@..@@..@@@@.@.@..@..@@.@.@@@.@...@@@.@@@@@@@.@@@.@.@..@..@.@@@@@.@. +@@@@..@@.@@@@.@@@@...@.@@@@@@@.@.@@.@@@..@@.@@@@@@@@@@@.@@@..@.@@@.@@@@..@@@@.@@@@.@..@.@@@..@..@@.@@@@@@.@..@@@@@@@...@.@@.@...@.@.@@..@ +@@.@@..@..@@@@@@@@@@@@@@..@@@@@@@.@@@@@...@@@..@@.@@..@.@@@@@@@@..@@.@.@@.@@@@@...@@@@..@@@@@@@@@@@@.@@@..@..@@@@.@@@@@@.@@@@@@@.@...@@@@ +@@@@@.@@.@@...@.@.@@@@@@@.@@@....@@@@@@@..@@..@..@@@@@..@@@.@@@@@@@@@.@@.@.@@@.@@...@@@.@@@.@@.@@@.@..@@@@@@.@@@@@@@@@@@...@.@@@@@@.@@@@. +.@@@@@@.@@@@..@..@@..@@@.@@@@...@@@@.@..@@.@@@@.@.@.....@..@.@@...@@@@.@.@..@@@@@@@..@@@@@@@@@@@@@.@..@@@@.@.@..@@@.@@@@@@..@.@@..@.@@.@. +@@@.@@@@@...@@@.@@@@@.@@@@@@...@@.@@.@@.@@@@@@@@.@@@@@@.@@@@..@.@@.@@@@@@.@.@@.@@@.@@@@.@@@@@@@@.@@@@@@@@.@@.@@@.@.@@@@@@@.@.......@.@..@ +@@@@@@.@..@...@..@..@@@..@@@@.@@..@@.@@@..@@.@@@@.@@@@@...@.@@@.@@@@..@...@@@...@.@@@.@@@@@@.....@@@@..@.@@@.@@@@@@@.@@@.@.@.@.@@....@..@ +@@@..@@@.@..@@@@....@.@@@.@@@@.@@@@@@@.@@@.@@@.@@.@@@.@@@@.@@@@.@@@@.@@..@@@@@@@...@@@.@@@@@@@.@@.@.@@@@@@@@@@@@@@@@@@@.@.@@@@.@@@.@.@@@. +@..@@@@@@@@@@@@@.@.@.@@@@..@.@@@@@@.@@@@..@..@@@@.@@..@@.@@@@@@.@@@@.@.@@@@@.@@@@@@.@@.@@...@@@@..@@@@@@@@@.@@@.@@@@@@@@@@.@.@@@@@@@@.@@@ +@@....@..@..@...@@@@.@...@@@.@@.@@@...@..@.@@..@@@.@@@@@@...@.@@@.@@@@@.@@@@...@@@@.@@@@.@.@@.@@@@@@@.@.@..@@@@@@@@@@..@.@@@@.@..@@@@@@.@ +.@.@@@@@@@@..@@.@@@.@.@.....@@@@.@@@@@@..@...@@@@.@.@@....@.@@@@@.@.@@@.@..@.@@@@@@@@@.@@@@@@@@@@@@.@.@@.@...@@@@.@.@..@.@@@@.@..@@.@@@@. +@@@@@.@.@@@@@@...@@@@@@@@@@@...@...@.@...@..@@.@.@@@.@.@..@@@@@@@@.@.@@@@@.@@@@@@@@@.@....@@@@@@.@@@@@@@.@@@@.@@@@@@@@@...@..@@...@@.@@@@ +@..@.@.@.@@@..@@@..@@@@@@.@@@@@@@@@.@.@.@.@@@......@..@@@@.@@@.@@.@@.@....@.@@@...@.@@@.@@@.@..@...@@@@@@@@@@@@@.@.@@@.@@@@@@@@@.@@@@@@@@ +..@@.@@@@@@@@@..@@...@..@@@@.@@.@@@@@@.@@.@.@..@@@@@@@@...@@@@@.@@.@@@@@.@.@@@.@@@@.@.@.@..@@@@@@.@@@@@@.@.@@@@....@@..@..@@..@@..@@@.@@@ +@@@.@@@@@@@.@@@@@.@@.@.@@.@@@@..@@.@@@@@@...@@@@@@..@.@@@.@@.@@@@@@@@@@@@@....@@@@..@@@.@@@@@@@@@.@.@@@@@.@@@@@@@@.@@@@.@..@@.@.@.@.@@@@. +@.@@@@@@@@@.@@.@@.@@@@@..@.@@@.@..@....@@@@.@.@@@@.@@.@.@@@..@@..@@.@@@@@@@@@@@@..@.@@@@.@....@@.@@@@@@.@@@@@@.@.@@@@@.@.@@.@@@@.@@..@.@. +@.....@.@@@.@.@...@.@.@@@@@@@@@@@@..@.@@@@@@@@@@@@.@@@..@@@..@@@.@@@@@.@@@@@@@@@@@@@..@@@@.@..@@@@..@@..@@@@@@@@@@..@@@@@..@@@@.@@@@@.@@. +.@@@@..@.@@@@@...@@.@@@.@@@@@@@@@@...@..@@.@.@..@@@@@@@...@@@@@@@.@.@....@.@.@@@.@@.@@@@.@@.@.@@@@@@.@...@@@@.@@@@.@.@@@.@@.@@.@@@@@.@@@@ +.@@@.@@@@@@@@@.@@@@..@@@.@..@@.@@@.@@@@@..@@@..@..@.@.@@@....@@@..@.@.@@.@@.@..@@.@@@@.@@@@@@.@...@.@@@@@.@.@..@@@..@.@...@.@@....@@@@@@@ +@@.@.@@@@@.@.@..@..@@@@.@@.@@..@@@.@@.@@.@@@.@.@@@...@..@.@@..@@@....@..@@@.@@@@@@@@@@@@@@...@.@@..@@@.@@...@@.@@@..@@@@@@@......@.@@@@@@ +@.@@@..@@.@.@@@.@.@..@.@...@@.@@..@@@@@..@@....@@@@@@.@.@.@@@.@@@@@@@@@@@@@@.@@.@@@@@@.@.@@@...@@@@.@@..@...@.@@.@@@@@.@@@.@@@@@@@.@@..@@ +.@.@@.@@@.@.@@@@@@..@.@.@@.@@@.@@@@@...@@@@@@@@.@@@....@...@@.@@@@.@...@@@.@.@@@@.@@@@.@@@@@@.....@...@.@@@@@..@..@.@.@...@..@@..@.@@@@@. +@@@@.@@.@@@@@@@@@..@...@@@@@@@@..@@@.@@@@@@@..@@@.@@@@@@@@@..@@@@@.@@@@..@@@@@@@@.@@@@@@@@@@@@@@@@@@@@@@.@@..@@@@@@@@@@@@.@@@@@.@@@@@.@.@ +@@.@@@@@.@@@@..@.@@..@.@@@@.@..@@@@.@@@@@.@@@.@...@@.@@@@@..@@@.....@.@@@@.@.@@@@@@.@@..@..@@@@.@@@.@@..@.@@.@@...@.@@@@.@@@@@...@@.@@@.@ +@@@@@@.@.@.@@@.@@.@@..@@.@@.@@@..@.@.@..@@.@@@@@@@.@.@@..@@@@@@@@@.@.@@..@@@@@@@@.@.@.@@@@@@@@@.@@...@@@.@@@@....@@.@@.@@..@@@.@.@.@@@.@. +@@@@@...@@..@.@@.@.@.@@...@@..@@@@@@@@@.@@@.@@@.@@...@@@@.@@@.@@@@.@@..@@@@...@.@@@@.@.@@......@@@@@@@..@@@.@@@..@..@@@@@.@@@.@@.@@....@@ +@..@@.@@@@@@@@....@.@.@@@@@@....@@@@.@.@@@.@.@@@@@@@.@@@@@@@..@@.@@@.@..@@@@@@.@.@..@@@.@@.@.@@@@@@@....@@.@.@@.@.@.@@@.@@@...@@@@@.@@@.. +.@@@@..@@@@.@.@@.@@@@....@@@..@.@.@.@.@@@@@@@@.@.@.@@@.@@.@@..@@.@@@@.@..@@.@@..@@@.@.@.@..@@...@.@@@@@.@..@@@@@.@...@.@@@@@@@@@@.@.@@..@ +.@...@.@@@...@@@.@@@.@.@@@@@@.@.@@@@@...@@@@@@@@@@@..@@.@@@@@@...@@.@.@@@.@.@@@.@@@..@@@@.@@.@.@@@@.@@@.@@@@@@@@@@@@.@@@@@@@@@@@.@@@@@.@@ +@.@@@.@@@@@@.@@.@..@.@@.@@.@@..@.@@...@@@@@@@@.@@@..@.@.@.@@@.@@.@@@.@.@@.@@@@@....@@@.@@.@@.@@..@@@..@@@@@@.@@@@@@@@@@@@.@@.@@@@@@@@@.@. +@@.@@@@@@.@.@@...@@.@@@@..@.@.@@.@@@.@...@@@@..@@.@@.@@.@.@@@@..@.@@@@.@@@..@@.@.@.@@@@@@@@@......@@.@@@@@@...@.@..@.@@@@@..@..@.@@.@@..@ +@@@@@@..@@.@@@@..@@@.@@@@@..@@@.@@@@@@@.@@@@..@@@@.@@@.@.@@@@@@..@@@....@@@...@@@@@.@.@@@@.@.@.@@@@...@@..@@..@@@@@@..@@.@@.@@.@@.@@@.@.. +@@@...@.@@@@@.@@..@.@.@@@@@@@@.@@.@.@.@@..@@..@@@@@@@@@@.@@@@..@@.@@@@@@@@@.@.@@....@@@@.@@@@@.@@@..@@@@@@@@..@@@@@@@@@.@@..@.@@@@..@...@ +@@@@@@@@.@@@@@@@@@@@@@@....@..@@.@.@@@.@@@@@@@@@@.@@.@@@@@@@@.@....@..@@.@@@.@...@@@@.@@@@@@.@@@@..@@@@.@@..@.@@.@@@@.@.@@@..@@@@@@@@@@.@ +...@@..@.@@@@@@.@@@..@.@@.@@..@@..@.@@@.@.@.@@@@@@.@@@@@@.@@@.@@@@.@@@@..@.@@@.@...@@.@....@@@.@@@@@@.@@..@@.@@@.@.@@.@.@.@@@@.@.@@.@@..@ diff --git a/src/day4.rs b/src/day4.rs new file mode 100644 index 0000000..63e5853 --- /dev/null +++ b/src/day4.rs @@ -0,0 +1,106 @@ +use itertools::Itertools; + +pub fn day4_part1(input: &str) -> String { + let roll_locations = parse(input); + all_coords(roll_locations[0].len(), roll_locations.len()) + .filter(|coords| roll_locations[coords.row][coords.col]) + .filter(|&coords| { + adjacent_including_diagonals(roll_locations.as_slice(), coords) + .iter() + .flatten() + .filter(|&&neighbour| neighbour) + .count() + < 4 + }) + .count() + .to_string() +} +pub fn day4_part2(input: &str) -> String { + todo!() +} + +fn parse(input: &str) -> Vec> { + input + .lines() + .map(|line| line.chars().map(|c| c == '@').collect()) + .collect() +} + +fn unparse(grid: &[Vec]) -> String { + grid.iter() + .map(|row| { + row.iter() + .map(|&is_roll| if is_roll { '@' } else { '.' }) + .collect::() + }) + .join("\n") +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +struct Point { + row: usize, + col: usize, +} + +fn all_coords(width: usize, height: usize) -> impl Iterator { + (0..height) + .cartesian_product(0..width) + .map(|(row, col)| Point { row, col }) +} + +/// North, East, South, West, Northeast, Southeast, Southwest, Northwest +fn adjacent_including_diagonals( + grid: &[Vec], + coords: Point, +) -> [Option; 8] { + [ + adjacent_cardinal(grid, coords), + adjacent_ordinal(grid, coords), + ] + .concat() + .try_into() + .unwrap() +} + +///Never Eat Shredded Wheat +fn adjacent_cardinal(grid: &[Vec], coords: Point) -> [Option; 4] { + let mut retval = [const { None }; 4]; + let (row, col) = (coords.row, coords.col); + + if row > 0 { + retval[0] = Some(grid[row - 1][col]) //N + } + if col < grid[0].len() - 1 { + retval[1] = Some(grid[row][col + 1]) //E + } + if row < grid.len() - 1 { + retval[2] = Some(grid[row + 1][col]) //S + } + if col > 0 { + retval[3] = Some(grid[row][col - 1]) //N + } + + retval +} + +/// Never Eat Shredded Wheat, rotated 45 degrees clockwise +/// AKA northeast, southeast, southwest, northwest +fn adjacent_ordinal(grid: &[Vec], coords: Point) -> [Option; 4] { + let mut retval = [const { None }; 4]; + let (row, col) = (coords.row, coords.col); + + if row > 0 && col < grid[0].len() - 1 { + retval[0] = Some(grid[row - 1][col + 1]) //NE + } + if row < grid.len() - 1 && col < grid[0].len() - 1 { + retval[1] = Some(grid[row + 1][col + 1]) //SE + } + if row < grid.len() - 1 && col > 0 { + retval[2] = Some(grid[row + 1][col - 1]) //SW + } + if row > 0 && col > 0 { + retval[3] = Some(grid[row - 1][col - 1]) //NW + } + + retval +} diff --git a/src/lib.rs b/src/lib.rs index e82c6b7..2e7edda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,11 +116,27 @@ pub mod day2 { } pub mod day3; +pub mod day4; #[cfg(test)] mod tests { use super::*; + #[test] + fn day4_part1_test() { + let test_result = day4::day4_part1(include_str!("../input/day4.test.txt")); + assert_eq!(test_result, "13"); + let result = day4::day4_part1(include_str!("../input/day4.txt")); + assert_eq!(result, "1372"); + } + // #[test] + // fn day4_part2_test() { + // let test_result = day4::day4_part2(include_str!("../input/day4.test.txt")); + // assert_eq!(test_result, "3121910778619"); + // // let result = day4::day4_part2(include_str!("../input/day4.txt")); + // // assert_eq!(result, "175304218462560"); + // } + #[test] fn day3_part1_test() { let test_result = day3::day3_part1(include_str!("../input/day3.test.txt")); -- 2.51.2