From 2b78ac2eff1971e1a98746be751d2eb466fa0978 Mon Sep 17 00:00:00 2001 From: z1glr Date: Tue, 9 Dec 2025 13:05:23 +0100 Subject: [PATCH] day 07 part 1 works, 2 too slow --- 07/input | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 07/main.go | 110 +++++++++++++++++++++++++++++++++++++++++ 07/test | 16 ++++++ 3 files changed, 268 insertions(+) create mode 100644 07/input create mode 100644 07/main.go create mode 100644 07/test diff --git a/07/input b/07/input new file mode 100644 index 0000000..e3934ae --- /dev/null +++ b/07/input @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^.....^.^.................................................................. +............................................................................................................................................. +.................................................................^...^.^...^................................................................. +............................................................................................................................................. +................................................................^.^.^.^.....^................................................................ +............................................................................................................................................. +...............................................................^...^.^.......^............................................................... +............................................................................................................................................. +..............................................................^.^.^.^.........^.............................................................. +............................................................................................................................................. +.............................................................^.^...^.^.^.^.^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.^.^...^.^.^.^.^............................................................ +............................................................................................................................................. +...........................................................^.^.^.......^.^.^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^.^.^.^.^...^...^.^.^.^.^.......................................................... +............................................................................................................................................. +.........................................................^...^.......^.^.^.^...^...^......................................................... +............................................................................................................................................. +........................................................^.^.....^...^.^...^...^.^...^........................................................ +............................................................................................................................................. +.......................................................^.^...^.^.^.^...^.^...^.^.....^....................................................... +............................................................................................................................................. +......................................................^.^...^.....^.^.^...^.^.^...^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^.^...^.^.^.^.^.^.^...^.^...^.^.^..................................................... +............................................................................................................................................. +....................................................^.^.........^...^.^.^.^...^.^.^.^.^.^.................................................... +............................................................................................................................................. +...................................................^.....^...^.^...^.^.^...^.^.......^.^.^................................................... +............................................................................................................................................. +..................................................^.^...^.^.^.^...^.^.^.....^.....^.^.^...^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.^.^.^.^...^.^.^.^...^...^.^.^...^.^................................................. +............................................................................................................................................. +................................................^.^.....^.....^.^.....^...^.^...^.^.......^.^................................................ +............................................................................................................................................. +...............................................^.^...^.^...^.^.....^.^.^.^.^.^...^.^...^.^.^.^............................................... +............................................................................................................................................. +..............................................^...^.^.^...^.....^...^.^.^.....^.^...^...^.^...^.............................................. +............................................................................................................................................. +.............................................^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^...^.^.^.^.^............................................. +............................................................................................................................................. +............................................^.^.^.^.^.^.....^...^.^.^.^.^.^...^...^.^.^...^.^.^.^............................................ +............................................................................................................................................. +...........................................^.^...^.^.^.^.^...^.^.^.^.....^.....^.....^.......^.^.^........................................... +............................................................................................................................................. +..........................................^.^...^.^.^.^...^.^.^.^.^.^...^.^.....^.^.^.......^.^.^.^.......................................... +............................................................................................................................................. +.........................................^.^.^.^.^.^.^...^.^...^.^.^...^...^.^...^...^.......^.^.^.^......................................... +............................................................................................................................................. +........................................^.^.....^.^...^.^.^...^.^.^...^.^...^.^.^...^.^.^.^.^.^.^...^........................................ +............................................................................................................................................. +.......................................^...^.....^...^.^.^.^...^...^...^.^...^.^...^.^.^...^.^.^.^.^.^....................................... +............................................................................................................................................. +......................................^.^.^...^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^.^.^...^.^.^.^.^.^.^.^...................................... +............................................................................................................................................. +.....................................^.^.....^.....^.....^.^.^.^...^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^..................................... +............................................................................................................................................. +....................................^.^...^.^.^.^...^.^.^.^.^.^.^.^...^.^.^...^.^.^.^...^.^...^...^.^.^.^.................................... +............................................................................................................................................. +...................................^.....^.....^.^.^.^.^.....^...^.^.^.^.^...^...^.....^.^.^...^.^.^.....^................................... +............................................................................................................................................. +..................................^...^...^...^.^.^.^...^.......^.^...^.^.......^.^.^.^...^.^.....^.^.^...^.................................. +............................................................................................................................................. +.................................^.^.^.^.^.^.^.^.^.^...^.^.^.^.....^.^.^.^.^.^.^.......^.^.^...^...^...^.^.^................................. +............................................................................................................................................. +................................^.^.^.^.^.^.^.^.^.^.^...^.^...^.....^.^.^...^.^...^...^.^...^.^...^.^.^.^.^.^................................ +............................................................................................................................................. +...............................^.^.....^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^...^.^............................... +............................................................................................................................................. +..............................^.^.^.^.^.^.^.^.^.........^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.......^.^.^.....^.^.............................. +............................................................................................................................................. +.............................^...^...^.^.^.^...^.^...^.^.^.^.^.^.^...^.^...^.^.^.^.^.....^...^.^...^.^.^.^.^.^.^............................. +............................................................................................................................................. +............................^.^.^.^.^...^.....^...^...^.^.....^.....^...^...^.^.^.....^.^.^.^.^...^.^.^.^.^.^.^.^............................ +............................................................................................................................................. +...........................^.^.^.^.^.....^.^.^...^.....^...^...^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.....^........................... +............................................................................................................................................. +..........................^.^.^.^.^.^.^.^.^.^...^.^.^.^...^.....^.^.....^.....^.^...^...^.^.^...^.^.^.^.^.^.^.^.^.^.......................... +............................................................................................................................................. +.........................^.^.^.^.^.^.^.....^...^.^.^.........^.^.......^.^...^.^.^...^.^.^.^.^.^.....^.^.^...^...^.^......................... +............................................................................................................................................. +........................^.^.^.^.....^.^...^.^.^...^.^...^...^.^.^.^.^.^.....^.^.^...^...^.^.^.^.^.^.^...^.^...^...^.^........................ +............................................................................................................................................. +.......................^.^.^...^.^.^.^.^.....^...^.^.^...^...^.^.^.^.^...^.^.^...^...^.^.....^.^.^.^.^.^.^.^...^.^.^.^....................... +............................................................................................................................................. +......................^...^...^.^.^.........^...^.^.^.^...^.^.^...^.^.^...^.^...^.^...^.....^.^.^.^.^.^.......^.^.^.^.^...................... +............................................................................................................................................. +.....................^...^.^.....^.^...^.......^.....^.^.^.^.^.....^.^.^.^.^.....^.^.^.^.^.^.^...^...^.^.^...^.........^..................... +............................................................................................................................................. +....................^...^.^.^.....^...^.^.^.^.....^.^.^.^.^.^.^.^...^.^.^.^...^.^.^...^.^.^.^.^...^.^.^.....^.^.^.^.^...^.................... +............................................................................................................................................. +...................^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...........^.^.^...^.^.^.^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^................... +............................................................................................................................................. +..................^...^.^.^.^.^.^.^.......^.^.^.^.......^.^.^.^.....^.^...^.^.^.^...^.^.....^.^...^...^.^.^...^...^.^.^.^.^.................. +............................................................................................................................................. +.................^.^.^.^.^...^.......^.^...^.^...^.^...^.....^.^.^.^.....^.^.^.^.^.^.^...^.^.....^.^.^.^.^.....^.^.^.^.^...^................. +............................................................................................................................................. +................^.^...^.^.^.^.^.^.^...^...^.^.^.^.^.^...^.^...^.^...^.....^.^...^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^................ +............................................................................................................................................. +...............^.^.^.^...^.^.^...^.^.^.^.^...^...^...^.^...^.^.......^.......^.^...^...^.^...^.^.^.^...^.^.^.^...^.......^.^.^............... +............................................................................................................................................. +..............^.^...^.^...^.^.^.^.^...^.^.^...^.^...^.^.^...^.^.........^.^.^...^.^.^.^.^.....^.^.^.^.^...^...^.^.^.^.^.....^.^.............. +............................................................................................................................................. +.............^.^.^.....^.^.^...^...^.^.....^.^.....^...^.^.....^.^.^.^.^.....^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^............. +............................................................................................................................................. +............^.....^.^...^...^.^.^.^.^.^.^.^...^.....^.^...^...^.^.^.^.^.^.^.^.....^.^.^.^...^.^...^.^...^.^.^.^.^...^.^.^.......^............ +............................................................................................................................................. +...........^.^.^.^...^.^.^.^.^.^.^.^.^.....^.^...^.^...........^.......^.^.^.^.....^.^...^.^.^.^.^.^.....^...^.....^...^.^.^.^.^.^........... +............................................................................................................................................. +..........^...^.^.^...^.^.^.^...^...^...^.^.^.^...^.^.....^...^.^.^.^.^.^.........^...^...^.^...^...^.^.^...^.^...^.....^...^.^.^.^.......... +............................................................................................................................................. +.........^.............^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.^.^.^.^.^.^.^.^...^...^...^...^.^.^......... +............................................................................................................................................. +........^.^...^...^.^.^.^...^.....^...^...^.^.^.^.....^.^.^.....^.^.^.^.^.^.^.^...^.^.^.....^...^.^.^...^.^...^.^.^...^.^.^...^...^.^........ +............................................................................................................................................. +.......^.^.^.^...^.^.^.^.^.^.^...^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...^...^.^.^.^...^.^.^.^.^...^.^.^...^.......^...^.^.^.....^.....^....... +............................................................................................................................................. +......^.^.....^.^...^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^...^.^.^.....^.^.....^.....^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^...... +............................................................................................................................................. +.....^...^.^...^.^.^.....^.^.^.........^.^.^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^...^...^.^.^.^.^...^.....^.^.^.....^.....^.....^.^...^.^..... +............................................................................................................................................. +....^.....^.^.^.......^.^.....^.^.^.^...^...^.^.^.^...^.^.^.^...^.^.^.......^.^.^.^.^.....^.^...^.^.^.^.^...^.^.^.^...^.^.^.^...^.....^.^.... +............................................................................................................................................. +...^.^...^.......^.^.^.^...^.^.....^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^...^.^...^.....^...^.^...^... +............................................................................................................................................. +..^.......^.^.^.^.....^.^.......^.^.^...^...^.........^.......^.^...^...^.^.......^...^.^.........^.^...^.^.^.^.^.^.^.^.^...^...^...^...^.^.. +............................................................................................................................................. +.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^...^.^...^.^.^.^.....^.....^.........^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.....^.^.^.^.^.^.^.....^.^. +............................................................................................................................................. diff --git a/07/main.go b/07/main.go new file mode 100644 index 0000000..dc8f06c --- /dev/null +++ b/07/main.go @@ -0,0 +1,110 @@ +package main + +import ( + "fmt" + + "git.z1glr.de/advent-of-code-2025/pkg/aoc" +) + +type Schematic struct { + rows [][]byte + splits int +} + +func (s *Schematic) CalculateRow(i int) { + if i == len(s.rows)-1 { + return + } + + for ii, char := range s.rows[i] { + switch char { + case byte('S'), byte('|'): + s.processPosition(i+1, ii) + } + } + + s.CalculateRow(i + 1) +} + +func (s *Schematic) processPosition(row, index int) { + if s.rows[row][index] == byte('.') { + s.rows[row][index] = byte('|') + } else if s.rows[row][index] == byte('^') { + s.splits++ + + s.rows[row][index-1] = byte('|') + s.rows[row][index+1] = byte('|') + } +} + +func (s *Schematic) Clone() *Schematic { + returnSchematic := Schematic{ + rows: make([][]byte, len(s.rows)), + splits: s.splits, + } + + for ii, rr := range s.rows { + returnSchematic.rows[ii] = make([]byte, len(rr)) + copy(returnSchematic.rows[ii], s.rows[ii]) + } + + return &returnSchematic +} + +func (s Schematic) CalculateQuantumRow(i int, pathCount *int) { + if i == len(s.rows)-1 { + return + } + + for ii, char := range s.rows[i] { + switch char { + case byte('S'), byte('|'): + if s.rows[i+1][ii] == byte('^') { + (*pathCount)++ + + parallelPath := s.Clone() + + s.rows[i+1][ii-1] = byte('|') + parallelPath.rows[i+1][ii+1] = byte('|') + + parallelPath.CalculateQuantumRow(i+1, pathCount) + } else { + s.rows[i+1][ii] = byte('|') + } + s.CalculateQuantumRow(i+1, pathCount) + return + } + } + s.CalculateQuantumRow(i+1, pathCount) +} + +func do(test bool) (int, int) { + rows := aoc.ReadFileRows(test) + + schematic := Schematic{ + rows: make([][]byte, len(rows)), + } + + for ii, rr := range rows { + schematic.rows[ii] = []byte(rr) + } + + quantumSchematic := schematic.Clone() + + schematic.CalculateRow(0) + + timelines := 1 + + quantumSchematic.CalculateQuantumRow(0, &timelines) + + fmt.Println(schematic.splits) + fmt.Println(timelines) + + return schematic.splits, timelines +} + +func main() { + if r1, r2 := do(true); r1 == 21 && r2 == 40 { + do(false) + } +} diff --git a/07/test b/07/test new file mode 100644 index 0000000..57a2466 --- /dev/null +++ b/07/test @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +...............