From 230c06ca3e1a828e1fa84ca2149520bd43689a19 Mon Sep 17 00:00:00 2001 From: Julius Klotz Date: Fri, 5 Dec 2025 23:29:13 +0100 Subject: [PATCH] implemented day 4 --- bin/main.ml | 2 + inputs/day04.txt | 139 +++++++++++++++++++++++++++++++++++++++++++++++ lib/day3.ml | 8 +-- lib/day4.ml | 99 +++++++++++++++++++++++++++++++++ 4 files changed, 241 insertions(+), 7 deletions(-) create mode 100644 inputs/day04.txt create mode 100644 lib/day4.ml diff --git a/bin/main.ml b/bin/main.ml index 9594a23..8dc46b2 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -4,3 +4,5 @@ let () = Printf.printf "Solution Day 2 part 1: %i\n" Aoc25.Day2.day2_part1 let () = Printf.printf "Solution Day 2 part 2: %i\n" Aoc25.Day2.day2_part2 let () = Printf.printf "Solution Day 3 part 1: %i\n" Aoc25.Day3.day3_part1 let () = Printf.printf "Solution Day 3 part 1: %i\n" Aoc25.Day3.day3_part2 +let () = Printf.printf "Solution Day 4 part 1: %i\n" Aoc25.Day4.day4_part1 +let () = Printf.printf "Solution Day 4 part 2: %i\n" Aoc25.Day4.day4_part2 diff --git a/inputs/day04.txt b/inputs/day04.txt new file mode 100644 index 0000000..afdfcad --- /dev/null +++ b/inputs/day04.txt @@ -0,0 +1,139 @@ +@@.@@@@..@@.@@@.@@@@@@@..@@.@.@@@@@@@.@@...@@@@...@@@@..@@@@..@...@@..@@@..@@@.@.@.@@@@@.@@@.@.@..@.@@.@@@..@...@@..@@.@@@@@@@.@@@@@@...@.@ +...@.@@.@@@@@@@.@@@..@@..@@@@.@@@.@..@@..@.@.@..@@@@@@.@@@...@@@@.@@@@@.@@@@@@.@..@..@.@.@@@@.@.@@.@@@@...@@.@.@@@.@@@@@.@...@.@@@@@@.@.@.. +@..@.@@@@.......@@@@@@@@.@@@.@.@@@@@@..@@@@..@...@.@@..@...@@.@@@@@@...@@@@@..@@@@...@.@@@@@@@@..@@@@.@..@@..@..@.@@@@.@@..@@.@@.@@@@@@.@@. +@@@@.@@@.@@@@.@@@@@@@.@@@@@..@@@@@@@.@@......@@@@.@.@@@.@@@....@@@@.@@@.@.@@.@..@..@@.@@.@.@@@@@@@@@@...@@..@@@@@@.......@@@..@@@@@.@@@@@.@ +@@.@@@..@@@@@.@@@@@@@@@@@@...@@@.@@.@@.@@@@@..@@@@@.@@.@@@@@@.@@@.@@@..@@...@..@@@@@..@@@@@@@@.@@@@@@.@.@.@..@@@@@@@@@@@.@@@@@.@.@@@@.@..@@ +@@@@@..@@..@@@@.@@@.@@@.@@@.@@.@@.@@.@@@..@.@@@@@.@@....@@@@@.@.@@@.@@@@@@@.@@..@@...@.@..@..@@@@@@@.@@@.@.@@..@.@.@@.@@.@.@@...@@@...@.@.. +@.@@@@@@...@..@@@.@.@@@@@@.@..@.@@@.@@@..@@@@@@@.@@@@@@.@@@@@@@@@@.....@@.@@.@@..@@...@.@@@@@.@@@.@@@.@..@@@.@.@@@@@@...@@.@.@.@@.@.@@.@@@. +.@@@.@@@.@@@@@@.@@@..@@@@@.@@@@.@..@@@@.@@..@@@@@@@@@@@@@@@..@@@@@@.@...@@@@@@@.@@@@@...@@@..@.@@.@.@@...@@@.@.@.@.@...@.@@@@@@@@@@@@@@.@@@ +@@@..@@@.@@.@@@.@.@@..@.@@@....@@.@@@...@....@@@.@@@.@@.@@@@..@@.@...@.@@@@@@@..@.@.@.@..@@@..@@.@@@.@@@.@@.@@@@.@@@@@@.@@@@.@.@@.@@@@@@@@. +@@@.@.@@@.@@@@..@.@.@..@@@@@.@@@@@@.@@@@@@@.@..@..@@..@@@@@@@@@..@.@@...@@@@.@@@@..@..@.@@@@.@.@..@@..@@@@.@@@@.@.@@@.@@.@@@@@@@.@@@@.@@... +@@@@@@@@@@@.@.@@.@...@@@.@@.@@..@@...@...@.@@@..@@...@@@@@@@.@@@.@@.@@@@.@.@.@@@@@.@.@@@@.@@@@@@@@@@@@@@@@.@@.@@@@@@@@...@@.@@@@.@.@@@@@.@@ +...@.@@.@@..@@@.@.@.@.@@@@@@.@@.@@@@.@@.@..@@@@@@.@@@@.@@@@.@.@.@@@.@@..@.@@@.@@.@@@@.@....@@@@@@@.@@@@@@.@...@.@@@.@@@.@@@@.@@@@.@@@@.@@@. +@.@@@..@....@.@@.@..@@@@.@@@@.@@@@@@.@@.@@.@@@...@@.@@..@.@..@@@.@.@@..@@@@@@@@@@@@.@@@....@@.@@@.....@@@@@@@..@@..@@.@..@.@@@.@@@@.@@@..@@ +@@@@.@@@@@@..@@@@@@@@@@@@.@@....@@@..@@@.@@@.@@@@.@.@@.@@@.@.@..@....@@@@@..@@@@@@@@..@@.@@@@@.@@.@.@@@@.@.@@@@@@@@@@@@@...@@@@@.@@@.@@.@@. +.@@@@@..@@@.@@@.@@..@....@@.....@@..@.@.@@..@...@@.@@.@.@@.@.@@@..@@.@.@@.@@@.@@.@...@@@.@@.@@@...@..@@.@@.@.@@@.@.@@@@@@@@..@@@@..@@@@@@.@ +.@@@@@@@@@..@.@....@.@@@@.....@.@.@..@@@.@@@.@.@@@@@.@@.@.@@.@@@@.@@@@@..@.@@@.@.@@@.@.@@.@@...@.@@@@@.@....@@@.@@....@.@@@@@...@@.@@@.@..@ +@.@@@.@.@@@@@@.....@.@@@@@@@@@..@@..@@.@..@.@@..@@@@@.@@..@.@@@@@@@@@@@@@.@..@@.@.@..@@@.@.@..@@@@@@...@..@@..@@@@.@.@@.@@@@@@...@@@.@@.@.@ +@@...@@@.@@@...@.@@.@.@.@@@.@..@...@@@@@@@.@@...@...@.@@@@..@@.@@@.@...@@.@.@@.@@.@.@.@...@.@@@@@@.@@@..@@@@@...@@@@.@@@...@@@@@..@.@@@@@@. +@..@...@@@.@@.@@.@@@@@@@..@@@.@@...@@.@@@@@..@.@@@@..@@@@@@.@@@....@@.@@@@@@@@@.@..@..@@@.@.@@....@..@@.@@.@@..@@@..@@@.@.@....@@@@@@.@@@@. +@@@@@@..@@@@@.@.@@@@@@@.@@@@..@..@@.@@@.@@@@@@..@.@@@@@.@.@.@.@@@..@.@@@@@...@.@@@@..@...@@@..@@@@@.@@..@@@@@@@@@@.@..@@@..@.@@@@@@@@@@.@@@ +@@@@@@@@.@.@..@@.@@...@.@@@@.@@.@@@@@@@...@@@@..@..@@@.@.@.@@@@@.@@@@@.@@...@.@@.@@@@@@@@@.@.@..@..@.@@.@@@@@@.@@@.@.....@@.@.@@..@@@..@@@@ +@@@@.@@@...@.@.....@@@@@..@.....@.@@...@..@@@@@....@@@@@.@.@.@...@@@..@@@....@@@.@..@...@..@..@.@.@@@@@.@.@@@.@..@.@.@@.@@@@@@.@@@.@.@@.@@@ +@@@.@@@@@@@.@@@.@.@@....@@@@@@..@@@@@@@@@..@@@@.@.@@@@@.@.@.@.@.@@@.@@@@...@@@.@....@.@..@@.@.@@.@@.@@.@@@@@..@@..@..@@@@.@@.@@.@@@.@@@@.@@ +.@.@@@@@.@@.@@@@@.@.@..@@@..@..@@@@@@.@@@@@..@@...@.@@@@@...@@@@.@@.@@@.@..@.@@@.@@@@...@@@@@.@@@..@..@.@...@@@@@.@@...@.@.@@@@.@@@.@@@@@.@ +..@@.@@.@@..@@@@.@@@@.@@@.@@@@@@@@@@..@@..@@@@@@.@.....@..@..@@@@@@@@..@@.....@@@....@@@@@.@..@@.@@@@@@@@@.@@@@@@.@.@@@..@.@@@@...@..@@...@ +..@@@@@.@@....@@@..@.@.@.@@@.@@.@@.....@@@@@.@@@@@@@@..@.@@@@@...@.@.@@@@@.@@@@.@.@@@.@..@@@@@@@.@.@@.@@@.@@@..@@.@.@....@@.@@.@..@@@@@.@@@ +@@@..@..@@@@..@@.@.@..@@.@@@.@@@.@.@@@...@@@@@.@@@@@@.@.@@@.@@@@.@@.@@@.@@.@@@@@@.@@.@@.@...@@.@..@@@.@.@@.@@@@@.@@@@@..@.@@@@@@.@@.@@..@@@ +@@@.@@.@@..@.@..@@@@@.@.@@...@.@.@@@.@@@.@@.@@@.@@@@@@.@@@..@.@@.@@@@@@.@..@@@..@.@.@@@@@@@@@@@@@.@@@.@.@@@@..@@.@.@.@@@@...@.@@.@.....@@.@ +@@@.@@.@.@@@@...@@@.@..@@@@..@@.@@@@@@@.@@@..@.@.@@..@@@@@@@.@.@@@@...@....@@..@@@.@@@@...@@.@@@@@@@.@@@@..@.........@@.@@.@.@.@@@.@.@@@@@@ +@.@@@@@@.@@.@.@@@@@.@@.@@@@@@@.@.@@@@@@@@.@@@@.@.@@@@.@.@@.@@@@@@.@..@..@@@@.@.@@@.@@@@.@@@@.@..@@@..@@@@.@@@@@.@.@.@@@@@.@@@@@.@..@..@.@.@ +@.@.....@@@.@.@.@@.@@..@@@@@@@@@@...@.@@.@...@..@@@@@.@.@.@@@@..@...@@.@@@@.@@@@.@.@.@.@..@.@@@@@@.@...@@@@@@@@..@@@@@.@.@.@...@...@@@@@@.@ +.@@@..@...@@.@@@@..@@@@@@.....@..@@@@.@@@@@.@@@.@@.....@@@@@@@@@@.@@@@@@@@@..@.@@@@.@..@@@@.@@@@..@@@....@.@@.@@@@..@..@..@@@@@.@@.@@@.@@@@ +.....@@@.@@@@@@..@@@...@.@..@@.@@.@.@.@@.@@@@.@@@@@@@.@@@@..@@.@..@@.....@.@@@@.@@@@...@@.@.@.@.@.@@...@@@@@@@@@.@...@..@@..@.@@@@@@@@@@@@. +.@@@@.@@@.@.@@@@@.@@.@....@@..@.@.@.@@.@..@@@@@@.@...@@..@..@...@@.@.@@.@.@@...@@..@@.@@.@...@...@@....@@.@@@@.@.@@.@.@.@@@.@@...@@@@@@.@.@ +@@.@..@.@@@...@@@.@..@@.@@@..@.@.@....@.@@@.@@@@@@.@@@@@.@.@@@@@.@.@@..@.@@.@@.@@@.@@.@@@@@@@@@..@@@@.@@.@@..@.@@.@.@.....@@@@@@.@@.@@@@@@@ +@@@..@@@@.@@@.@@@@@@@@.@@@..@.@@.@@.@@@.@.@.@@@@..@@@..@@@.@@@..@@@@@@.@@@...@@@@....@@.@@@@@@..@.@.@@.@.@@.@.@.@@@.@.@@@@@..@.@@@@.@@@.@@. +.@@@@.@@.@@@@@@@@@.@@@@.@.@@@@..@@@@.@@@@@@@@@@.@@@.@.@.@@@@@...@@@....@......@@@@@@...@@.@.@@@.@@..@@.@.@@@.@@@.@@@.@.@@..@@@.@@@.@.@@.@@@ +@...@@..@@@@@@@...@....@.@@@@..@.@..@@.@@@.@@.@@@.@@@@@@@.@@.@.@.@@@@@...@.@@@.@@@@..@@@@@..@@@@..@...@.@@@@@@@@.@..@@.@.@@@.@@@@@.@@..@@@. +@@@@@@.@.@@..@.@..@..@...@..@@..@@.@@.@..@@@@.@@@.@@.@@.@@@@@@.@..@@.@..@@@.@@@@@@@..@@@.@@@@@....@@.@..@..@...@@@..@.@@.@.@@@.@@@@...@@@@@ +...@...@@..@@.@..@@@.@.@....@@@@@@@@@@.@@..@@@@@@@@@@.@@@.@@@.@@.@@..@@@...@.@@@@@@@@@@....@.@...@@.@@@.@@...@@.@@@@@@@@@@@.@.@@@..@@.@@..@ +@@.@@@@.@@@@@.@@@..@@@@@@@@@.@@@..@.@@.@.@@..@@...@@.@@@...@..@....@@@..@@@@@@@@.@@@@@@@.@@.@@@@..@.@@@@@@@@@@@@.@..@.@..@....@@..@@..@.@@. +@@.@@@@@@@.@.@.@@.@@.@.@@@@@...@@@@...@@@@.@@.@.@.@@@.@@@@@..@@..@@@@@....@.@@@@@@@..@@@...@.@.@@..@@@.@@.@@.@@@@@@@..@..@..@@.@@...@@@@.@@ +@...@@@@@..@.@.@@@@@@@@@@@@@@...@@.@.@@..@@.@.@...@@.@@@.@.@.@.@@@.@@@.@.@@@@@.@..@@.@@.@@@..@@@@..@@@@.@@.@@......@@@.@@@.@@@@@@.@@.@@.@.. +@@@@@@@@.@.@@@...@@@@@.@@.....@.@@@@@.@@@@@@.@.@@.@@@@@.@..@@.@@@.@@.@@.@@.@.@.@..@@.@@@@@@@@..@..@.@@.@.@.@@@@.@.@@@@.@@@@@@...@@..@@.@@.@ +..@@@@.@@@@@@@@@.@.@@.@@.@...@@.@@.@.@@@..@.@@.@.@@..@.@@@.@@@@..@@..@@@@@@@.@@..@..@@.@..@@@..@..@@@@.@@@@@@..@.@@@.@.@@@@@.@@@@@@@...@@@@ +..@@.@.@.@@@.@.@@@@.@@@.@@@@.@.....@@@@@@.@.@@@.@@.@@@.@.....@@@@..@.@...@@@@@@@@.@@.@@..@.@@.@....@@@@@@@..@@@...@@@..@.@...@@@@.@@@.@@.@@ +@@@@.@.@@@@...@..@@@@@@@@@@@@@...@@@.@@..@@@@@@@@@@..@@.@...@@.@@@@@@.@@.@@@.@.@.@.@@@@@.@.@.@@@...@@@.@@.@@@@@@@@@@@@@@..@@@@@@@@@..@@..@@ +@@@@@@.@@.@@..@@...@..@@@..@@@@..@@..@@.@....@....@@@@@@@@@.@.@@...@.@@@@@.@@.@...@@@.@@@..@.@.@@@.@.@@@@.@@@@@@.@..@@@@@@@@@...@@.@@.@@@@. +.@@@.@@@@..@@@..@@@.@@.@...@@@@@.@@.....@@.@@@@@@@.@..@@.@@..@..@@@@@....@@@@@@@@@@@@@@....@.@@@..@..@.@@@@@@.@..@@.@@@@@.@@.@.@...@@@@@@@@ +@.@@@.@@...@@.@..@@@@.@@..@@@@@@.@@@.@.@@@@@.@@@@@@.@..@@..@..@@@@.@@@.@@@@@@@.@@.@@@@@@.@..@.@......@@@@.@@@.@.@@@@@@@@.@.@@@@@.@@.@.@@@@. +@@..@.@.@@@..@@@.@@@.@.@@@..@..@@..@.@.@.@.@@..@.@.@@@@@@.@.@@@@.@@.@@.@@@..@.@@@@..@@.@@@.@@@.@@@@@.@@@@@.@@@@@.@@@@.@@@@@@..@..@.@.@@@@.@ +..@@@@@.@@@@@@.@@..@.@.@.@.@@@@@@@@@@@@@..@.@....@@@..@@@@@@@.@@..@@@.@@@..@@@..@@@@@@@@@..@@.@@@@@@.@..@@..@..@@@@@@@...@@@@..@@@@.@..@@@. +@@@@..@.@...@.@.@@@@.@@@.@@@@@@@@.@@@..@.@@@@..@@@.@@@@@.@@..@@.@..@@@@@@.@@@@..@.@.@@.@@@@@@.@@@@@@.@@@@@@.@..@.@....@@@@..@@@@..@.@@.@@@@ +@@@@@@@.@@@@@@.@@@...@..@@.@@@..@.@@@@@...@@.@@@@.@@@....@@..@@@@@@..@.@.@@@@@.@.@@.@@@@@@@@@@.@@@@@.@.@@@..@@@@@@@.@@@.@@.@@@@.@..@.@..@@. +.@@@.@@@@@...@@.@.@.@@@@@@@@@@@.@@@.@@@@@..@...@@@@.@@@..@@@@@.@@@.@.@@@.@@@@...@@.@@@@@.@.@.@@@@@.@@.@@..@@@.@.@.@...@@@.@@@@@@@.@@....@.@ +.@.@@.@@@...@@@.@@@@@@@.@@@.@..@@@@@@@@@...@..@@.@@...@@@@@.@@.@@.@@..@@@.@@@@..@@@@@@@@@@.@.@@@@@@.@.@@@@@@@@@@.@@@@@.@.@@@.@.@@@..@.@@@.@ +.@@.@@.@.@@@@@@@@@@@..@@..@.@@@.@@.@@@@@.@@..@@@@@@@@@@@@.@.@..@@@@..@.@@@@@@@@.@..@@@@.@@..@.@.@.@@@@.@@@...@@@..@@@@..@@@@@@@....@@@@@..@ +@@.@@..@@@@.@@@@..@@@.@.@@@@@@@@@@.....@@..@@@.@@@..@@@.@@@....@..@....@@@@@...@@@@.@@.....@@@..@@.@@.....@@@.@..@..@@@@@@.@@@..@..@.@@@@.@ +.@@@....@@.@@@@@...@@..@@@...@..@.@@@@@.@@.@...@@@.@@@..@@@@@@@.@@....@@@@@@.@@@.@@@.@@@.@@@@.@.@..@@@@@@@@@.@@@@.....@..@@@..@@@@@@@@@@.@. +@.@@.@@.@@.@@@.@.@@..@@.@@@@@.@@@@@@...@.@.@.@.@@.@..@@@@@..@@.@@@@@...@@.@@.@@@..@@@@@@@@.@@...@@@@@@..@...@@.@@@@@@@@@..@@@.@@@@.@@@@@@@@ +@@@@@.@..@.@@@..@@@@@@@@@@..@@.@@@@@@....@@@@@@@@@.@.@...@@@@@..@@@@@@..@...@@...@@...@..@@.@@@.@.@@@@@@@@@@@@@@@..@@@@...@.@@@@.@@@.@@..@@ +..@.@@@.@@@.@@.@@.@....@@@@@.@..@.@.@@.@@@.@@.@.@@@@@@@@@@@@.@@@.@.@.@@@.@@@.@@@@@@@@.@.@@@@@@@@.@@@@@@@@@@..@@@@@@..@@@.@.@.@@..@@@@@@@.@. +@@.@.@@@@@@.@@@.@..@@@@..@...@@@@.@.@@@.@@.@@@@@@@@.@@@@@@.@@@@..@@@@@.@..@@@.@.@.@@.@.@.@..@..@@.@@.@@@.@@..@.@@..@@.@@@@@@@.@@.@..@.@@@@@ +@@@@@@@.@....@@..@..@@@.@@@@.@@.@.@@@.@..@@@@@@@@.@.@.@.@@.@..@@.@@@.@@@@@.@..@@.@.@@@.@@.@@@..@@@.@@@@.@..@@@@@@@...@@@.@.@@@@@@.@@.@@.@.. +.@.@.@@@.@@@...@@.@@@@@.@.@.@@@@@@@@@.@.@.@@.@.@@@...@..@@@@@@@@.@@@@@@.@@@.@.@@@@@@@@..@@@@..@@.....@@@.@@@.@@@@@@.@@@..@...@@.@@@@@@@@@@@ +@@@.@..@.@@@@.@.@@@.@@.@@...@@.@@@@@@...@...@.@..@@@.@@@@@@....@@@@@@.@@....@.@@.@@@@@..@@@@@@@.@@@@.@@.@@.@@@@@.@@.@@...@@@@@...@@@@@@@@.@ +@.@@.@@@.@.@@@@@@.@@@.@@@@.@.@.@.@.@@.@@.@..@@@@@.@@@....@@.@@..@@.@..@....@.@@.@.@.@@.@.@@@@@@@.@@...@@.@@@.@@@.@@@@@@@.@@.@@@@@@@@@@@@@@@ +@@@.@@@@.....@@.@@@@@.@@..@@..@.....@@@@.@....@...@.@...@@.@.@@.@.......@@..@..@@@@@..@..@@..@@@@@@@....@@@..@...@@@@.@@@@@@@@..@@.@.@@@@.@ +@@.@@@@@@.@@@@@@@....@.@@@@.@@@@.@@..@@@.@@.@@@@.@@@@@..@@.@@.@..@@@@.@@.@.@@.@.@@@.@....@@.@@..@@.@.@@.@.@@@.@.@....@@.@@@.@@@..@@@@.@@.@@ +@@@@.@@.@.@@.@.@@.@.@..@@@.@@.@@@@.@@@@@@.@@@@@.@@@@..@@@.@.@.@@@..@@@.@@@.@.@@@@@@.@@@..@@.@@@.@@.@..@@@@..@.@@...@@..@@@@.@@@@@.@@.@.@@.@ +@@..@..@.@.@@@@@@@...@@.@@@@.@@..@@@@..@@@@@@..@@.@.@@@@.@..@@@...@@.@...@@@@@.@.@.....@@@.@@.@...@@@@..@@@.@@.@..@@@@@.@..@@@.@.@.@..@@.@. +@@.@@@@@.@.@@@.@@@@@@@@.@@.@@.@@..@@@.@@@@@..@@@@.@@@@@@@.@.@@@..@@@.@.@@@@@@@@@@..@@@..@..@.@@..@@@@.@.@@@@..@@.@@..@@@@@@.@.@.@@@@@@@.@.. +.@@@..@@....@@@@@.@.@.@@@.@@@.@..@.@@@@.@.@@.@@@@@.........@.@@@...@@@.@@...@.@...@@@.....@.@..@.@@.@@@.@.@@.....@.@@@@@.@.@.@@....@.@.@@.. +@...@.@@@.@.@.@.@@@@@@@@...@@@...@.@@@@.@@@..@.@@@@@@.@@@.@@....@@@@@@@...@.@.@@.@.@@@.@@.@..@@@..@.@@@@@@@..@..@...@@.@.@@@.@.@@@..@.@@@.@ +.@@@@@...@@.@....@.@@.@@.@.@@@..@@.@@@@..@.@....@@@.@@..@@@@@@.@@@@@@....@.@.@.@.@@@.@@@.@@.@@.@@@@.@@@.@@@@@@@@.@.@.@.@@@@@.@@@@@.@@@..@@@ +.@@.@.@@..@@@@@@@.@@.@..@@@@.@@@@.@@@..@@.@@@..@@.@@@.@@@@.@@@..@@@...@@@.@.@..@@@...@@.....@@@.@@.@@@.@.@..@.@@....@@.@..@.@@@@.@.@@..@@.@ +@@@@.@@..@.@@@@@@@@@.@@@.@@@@@.@@.@@@@@@@@@@@.@.@@@@.@.@@@.@@@@@@@@@.@@.@@.@@.@.@@..@.@@.@@@@@.@.@@...@@@..@@@@@.@@...@@@@..@@.@.@@..@@@@.. +.@.@@..@@@@@.@@@.@@.@@@@@.@@@@.@@...@...@.@.@@@@@@@@@.@@.@@@@@@@.@@@@@@@...@@@@@@@@@@@@..@@@.@@.@@@@@@.@@.@@...@.@@@.@@@@.@@.@@@@.@@.@@.@@@ +@...@@@@@..@.@..@.@@...@@.@..@@@@@@@..@..@@@.@@@@@..@@@@@@@.@@.@.@@@@@@@.@..@.@.@@@@@@..@@.@@@@@@..@@@.@....@@@@@@@@.@@@@@.@@@@@@.@@@@@@@@@ +@@@@..@...@@@@@@@.@@@@@@@@.@@@.@@@@@@@@@@@.@.@..@@@@@@@@.@@@...@@@.@.....@@@@@@@@@..@@.@@@@.@..@.@@@@@@.@@.@@@.@@@@@@@..@@@.....@@@@@@@@@@@ +..@.@@.@.@@.@@@.@@@@.....@..@.@.@.@.@@.@@@@.@@.@@.@@@@@...@@.@@.@.@@.@@.@@.@...@@.@...@@@..@@..@@@@.@@.@@@@@.@@@@.@@@.@..@@@.@@@.@.@@...@@@ +@@@..@..@@.@@@@@..@@.@@@@@@@@@..@@@@@@...@@.@@@@@@@@@.@@..@....@@.@.@@@...@@@.@.@@@@@@@.@.@@@@@.....@@.@..@@.@@@@@@@@@@@..@@.@@.@@@@.@@@.@@ +..@@..@@@.@@..@.@.@..@@@@.@.@@@@.@@@@@@@@@@.@.@@@@.@.@.@......@@....@@@.@.@.@.@@.@@@.@@@..@@@@@.@..@@@.@@@.@@.@@@.@@...@..@@@@@@@@.@@...@.. +@.@@@.@.@.@.@@@@@@@@@@.@@..@.@@@..@@@@@@@@.@@@.@@@..@@@.@@@@@@@@@@.@..@@@@@.@@.@@@@..@.@.@@.@@@@@@..@@.@@.@.@.....@@@@@@@.@@..@.@@.@..@@@@@ +.@@.@@@@..@@@@...@@@.@@@@.@@@@@@@.@@.@@@....@@@@@@.@@@.@@@@@@@.@...@.@@@@.@.@@@@@@@@..@.@.@@@.@...@@@....@@.@@@@@.@@..@@@@.@@.@.@..@..@@.@@ +@@.@.@@@...@@@@@@@@@@.@...@@@@@@.@@@.@@@@@.@@.@@@@....@@.@@@@@@@..@.@@.@@.@@.@@@.@@@@..@@@@@@@..@@@.@@@@.@@@@@.@.@@@....@...@@.@@@@@@@..... +....@@@@.@@@.@.@.@@@@@@@.@@@@..@@@.@@.@@.@.@.@@.@@@.@.@@.@..@.@.@@@.@@.@.@@.@@....@@...@@.@..@@@@@@@.@.@.@@.@.....@.@@.@.@..@@..@@@.@@@@.@@ +.@.@.@@.@@@.@@@@.@@@@.@@@@@.@@@...@@..@.@.@@@@...@.@@@@@.@.@.@@@@.@@..@@..@@@.@@@@@@@@@@@.@@...@@@@.....@@@.@@@..@@@@.@@@@@.@@@@.@.@@..@@@@ +@@.@@@@.@@@@....@....@.@@.@@@@@.@@@@@@@@.@@.@@..@@@@@@@@..@@.@@.@.@@@..@.@@@.@@.@@@..@@@.@@@@@..@@@@@@@@@@@..@.@.@@@@@..@@.@.@@@.@@@@....@. +@@..@.@@.@@@..@.@@@..@.@@@.@.@.@@.@@.@@@@...@@@@@@@@.@.@@.@@...@.@@@@@@@@@@@@@.@.@@.@..@@.@.@@.@@@.@@.@@.@..@@@..@@.@.@@..@.@@..@@..@@@.@@. +.@@.@@.@@..@@@@..@..@@@@.@..@@..@@@@@....@.@@@..@@@@@@@@..@..@..@..@@@@.@@@@.@@@@@@.@@..@@.@@..@@.@@@@@@..@@@@@..@.@@@.....@..@.@.....@@@@. +@@@@.@.@...@@.@.....@@@@..@..@.@@@@@@.@@@.@.@.@@.@.@@@@@.@..@@.@@@@@@...@@@@@@@@@@.@@@@@@@..@@.@@@...@.@..@@..@@@@@..@@@...@@.@@@.@..@..@@@ +...@.@.@@..@.....@@@@@@@@@.@@@@...@@@@@.@@.@.@@@..@@@.@.@@@@@@.@........@@@..@@@@@@@@@@...@@.@.@.@@@@@@..@@@.@...@@.@@@.@.@...@.@@@@@@..@.@ +..@@@@@@@@@@.@.@.@@...@.@@@..@@@@.@.@@@..@@@@@@@@@@...@@.@@.@@.@@@@@.@@.@@.@@@@@..@@.@@.@.@...@@@@@@@@@.@@@@@@@@@@@@@.@@@.@@@.@@.@@.@@@.... +@..@.@.@@@@.@@@@@@@@@@...@@@.@..@..@.@..@@@@@@..@@...@.@.@@.@@@@@.@...@@@@@....@.@..@@.@.@@.@@@@@.@.@..@@@.@@@@@.@@@@......@@.@@@@@...@@@.@ +@@@.@@@@@.@@@@@@@@.@@@...@...@@....@@..@..@@@@@@@.@@..@@@.@.@@@.@@.@@@@.@.@@@@.@@.@.@.@...@.@@...@...@...@@@@@@@.....@@.....@@@@@@@.@@@..@. +@.@@@@@@@@@....@@@..@.@@@@.@.@@.@@@.@@@.@@@@@.@@@@@.@.@.@@..@@@...@@@@@@@@@.@...@.@@.@....@@.@@@@@@..@@...@@@@@@.@@..@@@@@@@..@@@@@@@@.@@@@ +@@..@.@.@.@@@..@...@..@@.@.@@.@.@.@.@@.@@@.@.@..@@.@@.@@.@@.@@@.@..@.@@@.@@@@..@@@@.@..@.@@.@@@.@@@@@@@@@@@@@@@@@...@.@.@@...@@@@@@@@@@.@.. +.@.@.@.@@.@.@@@.@@@.....@.@@@@@@.@@@.@@@@@.@..@@.@@@.@@..@..@@@.@@@.@..@@..@@@.@..@..@@.@.@@@..@@@@..@@.@@.@..@.@.@@.@@.@.@@@@.@@..@@@.@..@ +.@.@@@.@@@@.@@@..@..@@@.@@@..@.@.@@.@@@..@@@@....@@@@@@.@..@@@.@.@...@@.@@..@@@@@@@..@....@@@@@@@@@..@@@@@@.@@..@.@...@@@@@.@@@@.@.@@@..@@@ +.@@@@@@@.@@@..@@@..@..@@@.@@@@@...@@@@.@@@@.@@.@@@@..@@@....@.@@.@@@@..@@@..@..@@@.@..@@@.@@@@..@@@...@.@@@@...@@.@@.@@@@@@@@@..@@@@.@@.@@. +@@@@@@@@@@@@.@@.@@.@@..@@@@@@@@@.@.@@@@@@@@..@@@.@.@@@@@@...@@@@@.@..@@@@@.@@.@@.@@...@@.@...@@.@..@.@..@@.@@.@.@@@@@@@@@.@..@...@..@@..@@. +@.@@@.@@@@.@@@..@@.@..@@.@.@@@.@@.@@@@@@....@@@@@@..@@@.@@..@@@.@@@.@@@.@@@.@.@@@@@@@.@@.@@@@@.@@@.@.@@@@@.@@@@@..@@.@.@@@..@@@@.@@@@@@@@@@ +@.@@@..@@@@@@@@.@.@@@@@..@@@@...@.@.@...@.@@@@@.@@@.@....@..@@@..@@@.@.@..@@.@@.@.@...@@@@..@@.@@@@@..@.@@@@@..@..@..@@@@...@@.@.@@@@@@@@.@ +@....@@@@@.@@@.@@@..@.@@...@@@@@.@@@.@@.@@.@@@.@@.@@@@@@@...@@@@.@.@@@.@...@@@@@@@..@.@@.@@@@@.@@@...@.@..@@..@@@.@..@@.@@@@@@.@@..@@@@@@@@ +@@@.@@@@@@@@@@..@@@..@@.@@@@@@.@@@@@@@@@@@.@..@@.@@@.@@@@@@@@@.@@.@@.@@.@@@@@.@@...@@.@@@@@@@@.....@..@.@..@@.@@@@@@.@.@@.@@@@@@@...@.@@@.@ +.@@@.@@@@@@@@@@@@@@@@@@..@@@@@@@.@@@@@@@@.@@.@@@@@.@@.@@@@@@@@.@...@@.@@@@..@@..@@@.@@@@..@.@@..@@@@.@.@@@.@@.@.@@..@@.@@@@@@..@@@.@@@@@@@@ +.@@.@...@.@@@@@..@@@.@.@@@@.@.@.@.@@@...@@@.@.@..@.@@@@@.@.@@.@@.@.@.@@@.@@.@..@@@@.@.@@@@.@.@.@@@@@@@@@@.@@@@..@@...@@@@.@@@.@@.@@.@@@@@@@ +@@.@@.@.@..@@@..@@@@...@@@@..@...@@@@..@.@@@.@..@@.@@@@@@.@.@.@@@@.@@@.@@..@......@@.@.@@@@@.@@@@.@@@.@@.@@@@@.@@@@@..@@@@@.@@@@@@@@@@.@@@@ +@@@@..@@@@@...@@@.@.@@@@.@.@@@@.@@@.@@@@.@.@.@@@.@@@@@...@@...@@.@@@@@@@@@.@@..@@@@@@@@@@.@..@@@@@@.@@@@.@@@@...@@@@@.@@@.@@..@@@@@.@@@@@.. +@..@@@...@.@.@@@.@@.@....@@@@@.@..@@.@..@@@@.@..@@.@..@@...@.@.@.@.@@@.@@..@..@@@....@...@.@@@@@@.@@.@@@...@..@@@@@.....@.@..@.@..@@@@...@@ +.@@@@..@@@@..@..@@.@@@@.@@.@@@@.@@..@.@@@.@@@.@@..@@@@@@.@@.@@@@.@.@@@...@@..@..@@@@@@@@@@@@@.@@.@..@@.@@@.@@@@.@@@@.@@@.@@@.@@@@@@@@.@@@@@ +@@@@.@@@@@..@.@@@@...@@@.@@@@..@@@.@@@.@.@@@@@....@.@..@@@@@@@@@@@@@.@@@@@...@@.@.@.@..@.@@@@@.@@@@.@.@@.@@.........@@@.@@.@.@@@@@@@@.@@@@@ +@@..@@@.@.@..@@...@.@.@@@...@@@.@..@....@@@@.@@.@@@@@@....@@..@...@..@@@@..@@@.@.@@@@.@@@....@@.@@@.@@@..@@@.@@@@.@@.@@@@@@@@@..@@.@@@@@... +@.@@@.@@@.@.@@@@@..@@@@@.@@@.@@@.@@.@.@.....@@...@@@.@..@..@@@....@@@@@@@....@@.@@@@.@..@@@....@@@@.@.@@.@@@@@@@.@@@@@@.@@.@@.@..@@@@.@@@@@ +...@@@..@...@@@.@@@@@@@@@..@.@@...@@@@.@@@@@@.@.@@.@@@@@@.@@@@@@@@@@.@.@..@.@@....@@...@....@.@.@.@@@.@@......@@..@@.@@@@@@.@@@..@@@..@@@.@ +@@@@.@..@@@@@@@@@@@@.@.@.@..@@@@@@..@.@@@..@@..@@@@@@@.@@..@.@.@..@@@.@..@..@.@@.@@.@@.@@@@@.@.@@@@@@@@@@.@.@@..@@.@...@@..@...@@@@@@@@@@@@ +@@..@@.@@.@.@@@@.@@@@@@.@@.@@@@@@.@..@.@.@@@@@@.@.@@@@@@..@...@@@@@@..@@..@@@@@@@@.@@.@@.@.@@@.@@@@@..@@.@@@.@.@@@@.@@.@..@...@..@@...@..@. +@.@.@@@@@@..@.@@@@@@@.@@@.@@.@..@@.@..@@@@..@..@@@@.@@@...@..@@@@@@@...@..@@@@@...@@....@@.@@.@.@@@.@..@@.@@@@..@@@@@@.@@@.@.@@@.@@@@@@@@@@ +@@.@.....@.@.@@@@.@@.@@@@@.@...@@.@....@@@..@..@@@@@@.@@.@...@@.@@.@@@@@@@@.@@@@.@@@.@@@.@.@@.@.@@@@@@@.@..@@@@.@@@.@..@..@@@@.@@@@@..@..@@ +.@@.....@@@.@@@.@@@.@@.@...@@..@@@.@..@@.@.@.@@@@...@@.@.@.@@.@@...@@@@.@@@@@@@.@....@@@@..@@@...@@@@..@@...@@@@@..@@@@@@@.@.@@..@.@@..@@.@ +@@.@@@@@@.@@.@...@@@@@.@@@@@@....@@@.@@..@@@...@@@@@.@@..@@@@@@@@@.@@.@@@@@@@.@@@...@@@@.@@...@@...@.@@@.@@@@.@@@@@@.@.@@@..@@@@@.@@.@@@@@@ +@.@.@.@.@@@@..@@.@@@@..@.@@@@@@.@@..@.@@.@..@@@@@@@@@@.@@...@@@@.@@@@@@@.@@@..@@@@@.@@@@.@@@@@.@....@..@@@.@..@.@@.@@@@@.@@.@@@@@@.@@@.@.@@ +@@@@....@@.@@@@@.@.@@@@@@.@@@@@.@@.@.@@@@.@.@....@.@@@@@@@@@@@..@@..@@.@@@....@.@.@@.@@.@..@@@.@@@@@@@@.@.@@.@...@.@...@@@..@.@@@...@@.@@.. +@@.@.@...@..@..@@@..@@@@@@@@@@@@@.@@@.@@@@..@@.....@..@@.@@.@@@.@@@@@@@@.@@@....@@.@.@@@@.@.@@..@@@@@@@@@@@.@@.@@.@@@@@@.@@@@@@@@@@.@@...@@ +@@@@@@@.@..@..@@..@@@@@@@@@.@@@@@.@@@@.@@@@@...@@.@..@@@.@@@.@@@.@..@@.@@@..@@@@@@@@@@@@.@..@@.@@@.@@@@..@@.@...@..@@.@.@@.@@@....@...@.@@@ +@..@@@..@...@..@.@@.@.@@.@.@@.@@.@@@..@@@@@@@@..@@@@@.@.@@@@...@@.@@@@@@@@@@@.@@.@@@@.@.@.@@.@@@..@@@@.@@@.@@@@.@@..@@..@.@.@@@@@@..@.@@@@@ +@@@.@..@@@.@@@@@@.@@@..@.@@@@@@@@.@@.@@@@..@@..@...@.@@@@@.@@@.@@@..@@@.@@@@.@@@.@@@@@@@@@.@....@@.@.@@@@@.@.@@@@@.@@@@@@@..@@@@@.@@.@@@@@@ +.@@@..@.@@.@@..@.....@..@@.@@@@@..@@..@@@..@@@.@.@@@@@.@@@.@.@@@@@.@@@@@......@@.@.@.@.@.@@@.@@@@@..@.@@.@@@@.@@.....@..@...@@@...@@.@@.@.. +@.@@@@.@@@@@.@@.@@@@.@@@@.@@@@@...@@@.@@@@@.@@...@@@@@...@@@@.@.@@..@@@@...@@.....@@.@..@@.@..@@.@@..@.@@..@@@@@.@@@@.@....@.@@@@@@.@..@@@@ +@.@@....@@@@@@.@@@.@.@.@.@@@.@.@@@@@@@.@@@@.@.@@@..@@...@@@@@@@@@@@..@.@.@@@@@@.@@..@@@@.@@@@.@.@@@@@.@..@@@.@.@@.@@@@@....@@@@..@@..@.@@.@ +@@@@.@@@@@@.@@.@@@@@@.@@@@@@@@.@@@@@@.@.@.@@@.@@@@.@@@.@@@.@@@@.@..@@@.@..@@.@@...@.@@.@.@.@@..@@..@.@@@@@@..@@..@@...@..@.@@@@...@@@@@@..@ +@@.@@..@@@@@..@@@..@@@@@..@....@.@@@@...@@.@@.@.@..@..@@.@@@.@@@.@@@@...@@...@@.@.@.@@.@..@@.@@.@@@.@.@@@.@@@@.@@@@@@@@..@.@@.@@@@@..@@.@@@ +@@@@@@@@@@@@@@@@@@.@..@@@@@@@.@.@@..@@.@@.@@@@.@@@.@..@.@@@.@@@@@@@@..@.@@.@.@@@.@@..@@@..@@@.@@@@@@@@@@.@...@@.@.@.@@@@@.@@....@@@@@@.@.@@ +@@@.@@@@@@.@@.@.@@@@@@.@@@.@...@@@@@@@@..@..@@@..@@@...@@.@@.@.@.@@@@@@@@@@@@.@@.@@@@@@@@@@@@@@@@@@@@@@@@.@@@@..@.@@@@@@@.@.@@..@..@.@.@@.@ +.@..@@@.@..@@@@@...@@...@.@@@@@@@@@@@@.@..@@@.@@.@@@@@@@@@@..@.@@.......@@@.@@@@..@@@@@.@.@@@.@.....@@@...@.@..@.@......@.@@.@@@@@@@.@.@@.@ +.@@@...@@@@@.@@.@@@@@.@@@.@@@..@@.@@.@@@@@...@@@..@@@@@@...@.@..@..@@@.@@@@@@@.@.@.@.@@@@@..@@.@@..@@@.@@.@@.@@.@@@.@@@.@@@.@@@@@.@@@.@.@.@ +@@.@..@@.@.@@@@@@@..@.@@@@..@@@.@.@@@@@@@@..@@..@.@@@.@@@@...@@.@....@@@@@@@.@..@@@@@@.@@@@@.@@.@@@@@@@@@@.@.@@@@.@@@@@@..@@@.@@.@.@@.@@@.. +@.@.@@.@@@@@@@@@.@@@@.@..@@@.@..@@@@.@@.@@@@@..@@@@..@...@@@@@@@@......@.@@@@@@@@...@.@@@@.@..@@@.@@@@@@.@@@..@@@@@@@@@@@@.@@.@@@@.@@.@@@@. diff --git a/lib/day3.ml b/lib/day3.ml index a48bf1b..c58309d 100644 --- a/lib/day3.ml +++ b/lib/day3.ml @@ -67,12 +67,6 @@ let day3_part2 : int = solve_part2 input module Tests = struct - let test_input = "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124" - - let test_lines = String.split_on_char ',' test_input - - - let test_input = "987654321111111 811111111111119 234234234234278 @@ -92,4 +86,4 @@ module Tests = struct Printf.printf "All day 3 tests passed!\n" end -let () = Tests.run_tests() \ No newline at end of file +let () = Tests.run_tests() diff --git a/lib/day4.ml b/lib/day4.ml new file mode 100644 index 0000000..3fe20ed --- /dev/null +++ b/lib/day4.ml @@ -0,0 +1,99 @@ +let string_to_char_list s = + s |> String.to_seq |> List.of_seq +let lines = Reuse.split "inputs/day04.txt" '\n' +let input = List.map string_to_char_list lines + +let (>>=) = Option.bind ;; +let get_grid_pos (x: int) (y: int) (grid: char list list) : char option = + List.nth_opt grid x >>= fun sublist -> List.nth_opt sublist y + +let get_neighbors (x: int) (y: int) (grid: char list list) : char option list = + let right_top = if y = 0 then None else get_grid_pos (x + 1) (y - 1) grid in + let left = if x = 0 then None else get_grid_pos (x - 1) y grid in + let left_bot = if x = 0 then None else get_grid_pos (x - 1) (y + 1) grid in + let top = if y = 0 then None else get_grid_pos x (y - 1) grid in + let left_top = if y = 0 || x = 0 then None else get_grid_pos (x - 1) (y - 1) grid in + [get_grid_pos (x + 1) y grid; get_grid_pos (x + 1) (y + 1) grid; right_top; left; left_bot; left_top; + get_grid_pos x (y + 1) grid; top] + +let sum_papers (neighbors: char option list) : int = + List.length (List.filter (fun x -> x = Some '@') neighbors) + +let update_grid_position (grid: char list list) (x, y: int * int) : char list list = + let update_row (row: char list) (y: int) : char list = + List.mapi (fun col_idx c -> if col_idx = y then '.' else c) row + in + List.mapi (fun row_idx row -> + if row_idx = x then update_row row y else row + ) grid + +let apply_to_all_positions (grid: char list list) (positions: (int * int) list) : char list list = + List.fold_left (fun current_grid (x,y) -> update_grid_position current_grid (x, y)) grid positions + +let rec update_grid (grid: char list list) (acc : int) : int = + let result = ref acc in + let rows = List.length grid in + let cols = List.length (List.hd grid) in + let positions = ref [] in + for x = 0 to rows - 1 do + for y = 0 to cols - 1 do + let ats = sum_papers (get_neighbors x y grid) in + if get_grid_pos x y grid = Some '@' && ats < 4 then positions := [(x, y)] @ !positions; + result := !result + List.length !positions; + done; + done; + let new_grid = apply_to_all_positions grid !positions in + if new_grid = grid then acc else update_grid new_grid (acc + List.length !positions) + +let solve_part1 (inputs: char list list) : int = + let result = ref 0 in + let rows = List.length inputs in + let cols = List.length (List.hd inputs) in + for x = 0 to rows - 1 do + for y = 0 to cols - 1 do + let ats = sum_papers (get_neighbors x y inputs) in + if get_grid_pos x y inputs = Some '@' && ats < 4 then result := !result + 1 + done; + done; + !result + + +let solve_part2 (inputs: char list list) : int = + update_grid inputs 0 + +let day4_part1 : int = + solve_part1 input + +let day4_part2 : int = + solve_part2 input + +module Tests = struct + let test_input = "..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@." + + + + let run_tests () = + let test_lines = String.split_on_char '\n' test_input in + let test_input = List.map string_to_char_list test_lines in + + let part1_result = solve_part1 test_input in + let part2_result = solve_part2 test_input in + if part1_result <> 13 then + failwith ("Day 4 Part 1 test failed: expected 13, got " ^ string_of_int part1_result); + + if part2_result <> 43 then + failwith ("Day 4 Part 2 test failed: expected 43, got " ^ string_of_int part2_result); + + Printf.printf "All day 4 tests passed!\n" +end + +let () = Tests.run_tests()