diff --git a/.src/2025_desc.txt b/.src/2025_desc.txt index 430a2ab..9ef6f06 100644 --- a/.src/2025_desc.txt +++ b/.src/2025_desc.txt @@ -90,3 +90,18 @@ Read the input one way to add and multiply various numbers. #### Part 2 Read the input in a different way to add and multiply various numbers. +-- Day 7 +Splitting tachyon manifolds + +### Description + +#### Part 1 + +The input is a map with the positions of the splitters and the starting tachyon. +We should determine how many times the tachyon splits, while travelling in a +*classical* tachyon manifold. + +#### Part 2 + +For part 2, we should determine how many times the tachyon splits, while travelling in a +*quantum* tachyon manifold. diff --git a/Advents.lean b/Advents.lean index a2d2ed6..fc114ac 100644 --- a/Advents.lean +++ b/Advents.lean @@ -5,3 +5,4 @@ import Advents.AoC2025.day03 import Advents.AoC2025.day04 import Advents.AoC2025.day05 import Advents.AoC2025.day06 +import Advents.AoC2025.day07 diff --git a/Advents/AoC2025/2025_descriptions.md b/Advents/AoC2025/2025_descriptions.md index a2e7a65..46545a6 100644 --- a/Advents/AoC2025/2025_descriptions.md +++ b/Advents/AoC2025/2025_descriptions.md @@ -6,3 +6,4 @@ | [4](2025_descriptions_with_tests.md#day-4) | The input is a grid with the positions of rolls of paper. | | [5](2025_descriptions_with_tests.md#day-5) | Finding fresh ingredients for the cafeteria | | [6](2025_descriptions_with_tests.md#day-6) | Helping cephalopods with their maths homework | +| [7](2025_descriptions_with_tests.md#day-7) | Splitting tachyon manifolds | diff --git a/Advents/AoC2025/2025_descriptions_with_tests.md b/Advents/AoC2025/2025_descriptions_with_tests.md index 5266627..3ee81ba 100644 --- a/Advents/AoC2025/2025_descriptions_with_tests.md +++ b/Advents/AoC2025/2025_descriptions_with_tests.md @@ -196,3 +196,45 @@ Read the input in a different way to add and multiply various numbers. [Solution in Lean](day06.lean) --- + +# [Day 7](https://adventofcode.com/2025/day/7) + +Splitting tachyon manifolds + +#### Test + +
+.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... ++ +### Description + +#### Part 1 + +The input is a map with the positions of the splitters and the starting tachyon. +We should determine how many times the tachyon splits, while travelling in a +*classical* tachyon manifold. + +#### Part 2 + +For part 2, we should determine how many times the tachyon splits, while travelling in a +*quantum* tachyon manifold. + +[Solution in Lean](day07.lean) + +--- diff --git a/Advents/AoC2025/day07.input b/Advents/AoC2025/day07.input new file mode 100644 index 0000000..f671e9c --- /dev/null +++ b/Advents/AoC2025/day07.input @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^.^.^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^...^.^.^................................................................. +............................................................................................................................................. +................................................................^...^...^.^.^................................................................ +............................................................................................................................................. +...............................................................^.^...^.^.^...^............................................................... +............................................................................................................................................. +..............................................................^.^.^.^.^.....^.^.............................................................. +............................................................................................................................................. +.............................................................^.....^.^.^.^...^.^............................................................. +............................................................................................................................................. +............................................................^.^.^...^.^.^.^.^.^.^............................................................ +............................................................................................................................................. +...........................................................^...^.^.^.^...^...^...^........................................................... +............................................................................................................................................. +..........................................................^.^.^.^.^.^.....^.^.^...^.......................................................... +............................................................................................................................................. +.........................................................^...^.^.......^...^.......^......................................................... +............................................................................................................................................. +........................................................^.^...^.^.^.^.^.....^...^.^.^........................................................ +............................................................................................................................................. +.......................................................^...^...^...^.^...^.^.^.^...^.^....................................................... +............................................................................................................................................. +......................................................^.^.^.^.^...^.^.^...^.^.^.^.^...^...................................................... +............................................................................................................................................. +.....................................................^.^.^.^.....^...^.........^.^...^.^..................................................... +............................................................................................................................................. +....................................................^.^.^.^.^.^.^.^.^...^.^.^.....^...^.^.................................................... +............................................................................................................................................. +...................................................^...^.^...^.^...^.^.^.^.^...^.^.^.^.^.^................................................... +............................................................................................................................................. +..................................................^.....^.^.^...^.^.....^.^...^.^.^.^.^.^.^.................................................. +............................................................................................................................................. +.................................................^.^.^...^.....^...^...^.^.^.^.^.^.^.^.^...^................................................. +............................................................................................................................................. +................................................^.^...^...^.^...^.^.^...^.^.....^...^.....^.^................................................ +............................................................................................................................................. +...............................................^.^.^...^.^.....^...^...^...^.^...^.^.^.......^............................................... +............................................................................................................................................. +..............................................^...^.^...^.......^.^.^.^.^.^.^.^.^...^...^.....^.............................................. +............................................................................................................................................. +.............................................^...^.^.....^.......^.^.^.^.^.^...^.^.^.^.....^...^............................................. +............................................................................................................................................. +............................................^.^.^.........^.^.....^.^.^.^.^...^.^.^.^.^...^.....^............................................ +............................................................................................................................................. +...........................................^.^.^.^...^.....^.^.^.^.^...^...^.^.....^...^...^.^.^.^........................................... +............................................................................................................................................. +..........................................^.....^.^.^.^.^.^...^.....^.^.....^...^...^.^.^.^.^...^.^.......................................... +............................................................................................................................................. +.........................................^.^...^.^.....^.^...^.^.^.^.^.^.^.^.^.^...^.....^.....^.^.^......................................... +............................................................................................................................................. +........................................^.....^.^.^.^.^.^.^...^...^.^.^.^.......^.^.^.^.^.^.^.^.^.^.^........................................ +............................................................................................................................................. +.......................................^.^.^.^.^.^.^.^...^.^...^.^.^.^...^...^.....^.^.^...^.^...^.^.^....................................... +............................................................................................................................................. +......................................^.......^.^.........^...^.............^.^.^.^...^.^.^.^.^.^.^.^.^...................................... +............................................................................................................................................. +.....................................^.^.^...^.^.^.^.....^.^.^...^.^.^.^.....^.^.^.^...^.......^.^...^.^..................................... +............................................................................................................................................. +....................................^...^.^...^.^.^...^.....^...^.......^.^.......^...^...^.^.^.^...^...^.................................... +............................................................................................................................................. +...................................^.^.^.^.^.......^.^...^.^...^.^...^.^...^...^.^.^...^.^.^.^.^.^.^.^.^.^................................... +............................................................................................................................................. +..................................^.........^.^.^.^.^...^.^.^...^.^.^...^.^.^.^...^...^.^.^.....^...^.^.^.^.................................. +............................................................................................................................................. +.................................^.^.^...^...^.^.....^.^.^.^...^.^.^.^.^.^.^...^...^.^.^...^.^.^.^...^.^.^.^................................. +............................................................................................................................................. +................................^.^.....^...^.....^...^.^...^.^.^.^...^...^.^.^.^.^.^...^.^.^.^.^.^.^...^.^.^................................ +............................................................................................................................................. +...............................^...^.^...^.^.^...^...^.^.^.^.^.^...^.^.^.^...^.^.^.^.^...^...^...^.^.^.....^.^............................... +............................................................................................................................................. +..............................^.^.....^.^.^.^.....^.^.^.....^.^.^.^.^.^.......^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.............................. +............................................................................................................................................. +.............................^.^.....^...^.^.^.......^.^...^.^.^...^...^.^...^...^.^...^.^.^.^.^.^.^.^...^.^...^............................. +............................................................................................................................................. +............................^.....^.^...^.^.^.......^.^.^.^.......^.^.^.^.^.^.^...^.^.^.^...^...^.......^.^.^.^.^............................ +............................................................................................................................................. +...........................^.^.^...^...^.^.^.^...^.^.^.^.^.....^...^...^.....^...^.^.^.^.^.........^.^.....^.^.^.^........................... +............................................................................................................................................. +..........................^.^...^.^...^.^.^.^.......^.^.^.^.^...^.^.....^.^.^.....^.....^...^.......^.^.^.^.^.....^.......................... +............................................................................................................................................. +.........................^.^.^.^.....^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^.^...^.^...^.^...^...^...^...^.^.^.^...^.^......................... +............................................................................................................................................. +........................^.^.^...^.^.^.^...^.....^...^.^.^.^.^.^...^.....^.^.^.^.^.^...^...^.^...........^...^...^...^........................ +............................................................................................................................................. +.......................^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.......^.^.^.^.^.^...^...^...^.^.^.^.^.......^.^.^.^.^.^.^....................... +............................................................................................................................................. +......................^.......^.^.^.^...^.^...^.^...^.^...^.^.^.^.^...^.^.^...^...^.^...^...^.^.^.^.^.^.^.^.^.....^.^.^...................... +............................................................................................................................................. +.....................^...^.....^.^.....^.^.^.^...^.^.^.....^.....^.^.^...^...^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^..................... +............................................................................................................................................. +....................^...^...^.^.^.^...^.^...^.^.^.^...^...^.^.^.^...^.^.^.^.^...^.^.......^.^.^.^...^...^.....^.^.....^.^.................... +............................................................................................................................................. +...................^...^.^.^.^...^...^.^.....^...^.^.^.^.^.^.^.^.^.^.....^.^...^.....^...^.^...^.^...^.^.^.^.^...^.^...^.^................... +............................................................................................................................................. +..................^.^.....^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^.^.^.^...^.^...^.^.^.^.^.................. +............................................................................................................................................. +.................^.^...^.^.^.^.^.^.^.^.^...^.^.....^.....^.^.^.^...^.^.^.^...^...^...^.^.^.^.^.^.^.......^.....^.^.....^...^................. +............................................................................................................................................. +................^.^.^.........^...^.^...^.^.^.^.^.^...^...^...^.^.^...^.^.......^.^.^...^...^.^.^.^.^.^...^...^.....^.^.....^................ +............................................................................................................................................. +...............^.^.......^.^.^.^...^.^.^...^.^...^.^.^.^...^.....^.^.....^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.....^.^............... +............................................................................................................................................. +..............^.^.^.^...^.....^.^.^.^.^.^...^...^.^.^.^...^.^.....^.^...^.....^.^...^...^...^.^.^...^.^.....^...^.^.^.^.^.^.^.^.............. +............................................................................................................................................. +.............^.^.^.^.^.^.^.^.^.....^...^...^...^.......^.^.^...^...^...^.^...^...^.....^.^.......^.^.....^...^...^.....^.^.^.^.^............. +............................................................................................................................................. +............^.^.......^.....^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^.^.^.^...^.......^.^.^...^...^...^...........^.^.^.^...^...^.^.^............ +............................................................................................................................................. +...........^...^.^.....^.^.^.^.^.^...^.....^...^...^.^.^.^.^.^...^.^.^.^.^.^.^...^.....^.^.^.....^...^.^.^.^.....^.^.^.^.......^.^........... +............................................................................................................................................. +..........^.^...^...^.^.^.^.^.^.....^.........^...^.^.^.^.^.^...^.^.^.........^.^.^.^.^...^...^.^.^.^.^...^.^.^.^...^.^.^.^.^...^.^.......... +............................................................................................................................................. +.........^.^.^...^.......^.^.^.^.^.....^...^.^...^...^.^...^...^...^.^.^.^.^.^.^.^.^.^.^.....^...^.^.^.....^...^.^.^.^.....^...^.^.^......... +............................................................................................................................................. +........^.^...^.^.^.^...^...^.....^...^.^.^.....^.^...^.^.^.^.^...^.....^...^.^...^.^.....^.....^.^.^.^...^.^.....^.^.^.....^.^.^.^.^........ +............................................................................................................................................. +.......^.^.^.^.....^.........^...^.........^.^.....^.^.^.^.^.^.....^.^.^...^.^...^.^.^.^.^.^.....^.^.^.^.^.^...^.......^.^...^.^.^.^.^....... +............................................................................................................................................. +......^.^.^.....^.^.^.^.^.^...^.^.....^.^.^.^.^...^...^.^.........^.^...^.^.^.^.^.^.^.^.......^.^.^.^.....^...^...^...^...^.^.....^...^...... +............................................................................................................................................. +.....^.^.....^.^.^.^.^.^.^.^.....^.^...^.^.^...^.....^...^.^.^.^.^.^...^.............^.^.^...^.^.....^.^.....^.^.....^.^.^.^.^.^.....^.^..... +............................................................................................................................................. +....^.^.^.^.^...^.^...^.......^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^...^...^.....^.^.^...^.^...^.^.^...^.^...^.^.^.... +............................................................................................................................................. +...^.^.^.^.^.^.....^...^...^.^...^...^.^...^.^...^.^.^.^.......^...^.^.^...^...^.^.^...^.^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^... +............................................................................................................................................. +..^.^.^...^.^.........^.^...^.^.^.^.^.......^.^.....^...^.....^...^...^...^.....^.^.^.....^...^.....^.......^.^.^...^.^.....^.^.....^.^.^.^.. +............................................................................................................................................. +.^.^.^.^.^...^...^...^.^...^.^...^.^.^.^.....^.^.^.^.....^.^...^.^.^.^.^.^.^...........^.^.^.^.......^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^...^. +............................................................................................................................................. diff --git a/Advents/AoC2025/day07.lean b/Advents/AoC2025/day07.lean new file mode 100644 index 0000000..57ed612 --- /dev/null +++ b/Advents/AoC2025/day07.lean @@ -0,0 +1,91 @@ +import Advents.Utils +open Std + +/-! +Splitting tachyon manifolds +-/ + +namespace AoC2025_Day07 + +open System in +/-- `input` is the location of the file with the data for the problem. -/ +def input : FilePath := ("Advents"/"AoC2025"/"day07" : FilePath).withExtension "input" + +/-! +# Question 1 + +The input is a map with the positions of the splitters and the starting tachyon. +We should determine how many times the tachyon splits, while travelling in a +*classical* tachyon manifold. +-/ + +/-- `test` is the test string for the problem. -/ +def test := ".......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +..............." + +/-- `atest` is the test string for the problem, split into rows. -/ +def atest := (test.splitOn "\n").toArray + +/-- `part1 dat` takes as input the input of the problem and returns the solution to part 1. -/ +def part1 (dat : Array String) : Nat := Id.run do + let spos := dat[0]!.length - (dat[0]!.dropWhile (· != 'S')).length + let mut (tacs, splits) : HashSet Nat × Nat:= ({spos}, 0) + for d in dat do + let inds := sparseGrid (d.toList.toArray.map ("".push)) (· == '^') + if inds.isEmpty then continue + (tacs, splits) := (Array.range dat[0]!.length).foldl (init := (∅, splits)) + fun (tot, ss) n => + if tacs.contains n then + if inds.contains (n, 0) then + (tot.insertMany [n - 1, n + 1], ss + 1) + else (tot.insert n, ss) + else (tot, ss) + splits + +#assert part1 atest == 21 + +solve 1 1553 + +/-! +# Question 2 + +For part 2, we should determine how many times the tachyon splits, while travelling in a +*quantum* tachyon manifold. +-/ + +/-- `part2 dat` takes as input the input of the problem and returns the solution to part 2. -/ +def part2 (dat : Array String) : Nat := Id.run do + let spos := dat[0]!.length - (dat[0]!.dropWhile (· != 'S')).length + let p0 := List.replicate dat[0]!.length 0 + let mut pathsTo := p0.modify spos (· + 1) + for d in dat do + let (inds, _) := d.foldl (init := ((∅ : HashSet Nat), 0)) fun (tot, ct) c => + (if c == '^' then tot.insert ct else tot, ct + 1) + if inds.isEmpty then continue + pathsTo := (Array.range dat[0]!.length).foldl (init := p0) fun ss n => + if pathsTo[n]! != 0 then + if inds.contains n then + (ss.modify (n - 1) (· + pathsTo[n]!)).modify (n + 1) (· + pathsTo[n]!) + else ss.modify n (· + pathsTo[n]!) + else ss + pathsTo.sum + +#assert part2 atest == 40 + +solve 2 15811946526915 + +end AoC2025_Day07