diff --git a/2025/07/input_final.txt b/2025/07/input_final.txt new file mode 100644 index 0000000..3b3e409 --- /dev/null +++ b/2025/07/input_final.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^.^.^................................................................... +............................................................................................................................................. +..................................................................^...^.^.^.................................................................. +............................................................................................................................................. +.................................................................^...^.^.^.^................................................................. +............................................................................................................................................. +................................................................^.^.........^................................................................ +............................................................................................................................................. +...............................................................^.^.^.^.......^............................................................... +............................................................................................................................................. +..............................................................^.^...^.....^...^.............................................................. +............................................................................................................................................. +.............................................................^.....^.^.^.^.^...^............................................................. +............................................................................................................................................. +............................................................^.^...^...^.^.^.^.^.^............................................................ +............................................................................................................................................. +...........................................................^.^...^.^.^...^.^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^.^.^.^.^.......^.^.^.^.^.......................................................... +............................................................................................................................................. +.........................................................^...^.^.^...^.^.....^.....^......................................................... +............................................................................................................................................. +........................................................^.^.^.^...^.^.^...^...^.^...^........................................................ +............................................................................................................................................. +.......................................................^...^.^.^.....^...^.^.^.^...^.^....................................................... +............................................................................................................................................. +......................................................^.....^.^.^.^.^...^.^...^.^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^.^...^.^.^.^.^...^.^.^...^...^.^.^..................................................... +............................................................................................................................................. +....................................................^.....^.^.^.^.^.^.^.^.^...^.^...^.^.^.................................................... +............................................................................................................................................. +...................................................^.......^.^...^...^.^...^.^.^...^.^.^.^................................................... +............................................................................................................................................. +..................................................^.^.^.^.^.^.^...^...^.......^.....^.^.^.^.................................................. +............................................................................................................................................. +.................................................^...^.^...........^.^.....^.^.^.........^.^................................................. +............................................................................................................................................. +................................................^.^.....^.^...^.^.^.......^.^.^...^.^.^.^.^.^................................................ +............................................................................................................................................. +...............................................^.^.^.^.^.^.....^.^.^.......^.^...^.^.^...^.^.^............................................... +............................................................................................................................................. +..............................................^.^.^.....^...^...^.^.^.....^...........^.^.^.^.^.............................................. +............................................................................................................................................. +.............................................^.^.....^.^.......^...^.^.^.^.^.^.^.....^.......^.^............................................. +............................................................................................................................................. +............................................^...^.^.^.^.^.^.^.^...^.^...^.^.......^.^.....^.^.^.^............................................ +............................................................................................................................................. +...........................................^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^.....^.^.^.......^.^........................................... +............................................................................................................................................. +..........................................^.^...^.^...^.^.^...^.^...^.^.^.^.^...^.^...^.^.^.....^.^.......................................... +............................................................................................................................................. +.........................................^...^...^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^...^.^...^...^.^......................................... +............................................................................................................................................. +........................................^.^.....^.^.^.^...^.^...^.^.^.^.^.^.^...^...^...^.....^.^.^.^........................................ +............................................................................................................................................. +.......................................^.^...^.....^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^....................................... +............................................................................................................................................. +......................................^.^...^.^.....^.^...^.^.^.^...^.^.^.^.....^.^...^.^.^...^.......^...................................... +............................................................................................................................................. +.....................................^.^.^...^.^.^.......^...^.^.^.^.^...^.^.^...^.^.....^.^.........^.^..................................... +............................................................................................................................................. +....................................^...^.....^.^...^.^.......^.^.....^.....^.^...^...^.^.^...^.^.....^.^.................................... +............................................................................................................................................. +...................................^.....^.^.^.^.^.^.^...^.^...^.^...^...^...^.^.^...^.^.^.^...^.^.^.^.^.^................................... +............................................................................................................................................. +..................................^.^.^...^.^...^.^.^.......^.^...^.^.^...^.^.^.^.^.....^.^.^.^...^.^.^.^.^.................................. +............................................................................................................................................. +.................................^.^.^.....^.....^...^...^.^.^.^.^.^.^.^...^.^.^.^...^...^.^...^.^...^.....^................................. +............................................................................................................................................. +................................^.........^...^...^.^.^.^...^.^...^.^.......^.^.^.^.^.^.^.^.^.^.............^................................ +............................................................................................................................................. +...............................^...^.^...^.^.^...^.^.^.....^...^...^...^...^.^.^.^.....^...^.^.^.^.^.^...^.^.^............................... +............................................................................................................................................. +..............................^.^.^.^.^.^.....^.^.^...^...^.^.^...........^.^...^.^.^.^.^...^.^.^.^.....^.^...^.............................. +............................................................................................................................................. +.............................^...^.^.^...^.^...^...^.^.....^.^.^...^.^.^...^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.^............................. +............................................................................................................................................. +............................^...^...^...^.^.^...^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.^.^...^.^...^.^.....^.^.^.^............................ +............................................................................................................................................. +...........................^.^...^.^...^...^.^.^.^...^.^.^.^.^...^.^...^.^.^...^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^........................... +............................................................................................................................................. +..........................^.....^.^.^...^...^.^.^...^.^.^.^.^.^.^.^.^...^.^.....^.^.......^.....^.^.^.^.^.^.^.^.^.^.......................... +............................................................................................................................................. +.........................^.^.^.^.^.^.^.^...^.^.....^.^.^...^.^.^.^.....^.^.^...^.^...^.^.^.^.^...^.^...^.^.^.^...^.^......................... +............................................................................................................................................. +........................^.^.^.^.^.^.^.^.....^.^.^.^...^.^.....^.^.^.^.^.^.^.^.^.^.^.....^.....^.^.....^...^.^.......^........................ +............................................................................................................................................. +.......................^.....^.^.^.^...^.^...^.^.^.^.^.^...^.^.^.^...^...^.^.^.^...^.^.^.......^.^...^.^.^.^.^.^...^.^....................... +............................................................................................................................................. +......................^...^...^...^.^...^.^.^.....^.^.^...^.........^.^...^.^.^...^.^...........^.^.^.^.....^.^.....^.^...................... +............................................................................................................................................. +.....................^...^.^...^.^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.....^.^...^.^.^.^.^.^.^.......^.^.^.^.^...^...^.^..................... +............................................................................................................................................. +....................^.^.....^.^.^.^.^.^.^.....^.^...^...^.^.^.^.^.^.....^...^.^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^...^.^.................... +............................................................................................................................................. +...................^.^.^.^.^...^.^.^.^...^...^.^.^.....^.....^...^...^.^...^.^.^.^.^...^.....^...^.^...^.^.............^.^................... +............................................................................................................................................. +..................^.^.^.^.^.^.^.....^.^...^...^.^.......^.^.^.^.^.^...^.^.^...^.^.^.......^.^.^.^.^.^...^.^.^...^.^...^.^.^.................. +............................................................................................................................................. +.................^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^...............^.^...^...^.^.^.....^.^...^.^.^.^.^...^.....^...^...^.^.^................. +............................................................................................................................................. +................^.^.^.^...^.^.....^.^.^.^.^.^...^.^.^.^...^...^.....^.^...^.^.^.^...^.^.^...^.^.^.....^.......^.^.^.....^.^.^................ +............................................................................................................................................. +...............^.^.^.^.^...^.^.^...^.^...^.^.....^...^.^.^...^.....^.^.^.....^.^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.......^.^............... +............................................................................................................................................. +..............^.^.^.^...^.^.^.^.^.........^.^.......^.^.....^.......^.^.^.^.^.^...^.......^.^.^.^.......^.....^.^...^.....^.^.^.............. +............................................................................................................................................. +.............^.^...^.^.......^.....^.^.^...^.......^.....^.....^...^.^.^.^.^.^.....^.^.....^.^.^.^.^.^...........^.^.^.^...^...^............. +............................................................................................................................................. +............^.^...^...^.^.^.^.^...^...^.......^.....^.^.....^.^...^...^.^.^...^.^...^.....^.....^...^.^.^.^.^.^...^...^.^...^.^.^............ +............................................................................................................................................. +...........^.....^.^.^.^...^.^.^.^.....^...........^.^.^...^.^.^.^.^.^.....^.^...^.^...^...^...^...^.^.^...^.^.^.^.^.^.^...^.^...^........... +............................................................................................................................................. +..........^.^.^.^...^.^.......^.^.^.^...^.^.^.^...^.^.....^.^.^.^...^...^...^.^...^.^...^.^...^.^.^.^.......^.^.^.^.^...^...^.^.^.^.......... +............................................................................................................................................. +.........^.^.^.^...^.^...^.......^.^...^.^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.......^...^.....^.^.^...^...^.........^...^.^...^.^......... +............................................................................................................................................. +........^.^.^...^...^...^.^.^.^.^.^.^.^.....^.^.^.......^.^.^.^.^.^.^.^.^.^.^...^...^...^.^.^.^...^.^.^.^...^...^.^.^...........^.^.^........ +............................................................................................................................................. +.......^.^.^.^.^...^.^.^.^...^.^.....^.^.^.^.....^.^.....^.^.......^.^.^.^.^.^.......^.^.......^.^.^.^.....^...........^.^.^...^.^...^....... +............................................................................................................................................. +......^.^.^.^.^.^...^.^...^.^.^.^.....^.....^.^...^...^.^.^.....^...^.^.....^.^.^.^...^.^.^.^.....^...^.^.....^...^.......^.....^.....^...... +............................................................................................................................................. +.....^.^.^...^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.......^.^.^...^.........^.....^...^.^.^.^.........^.^.......^.^...^...^.^.^.....^.^...^.^..... +............................................................................................................................................. +....^...^.^.^.^.^.^.^.^.^.^...^.^...^.^...^.^.^.^.^.....^.^.......^.^...^.^...^.^.^.^.....^.^.^.....^.^...^.....^.^.^.^.^.........^.....^.... +............................................................................................................................................. +...^.^.^.^...^...^.........^.^.^.^.^.^.^.^.^.^...^...........^.^...^...^.......^...^.^.^.^.^...^.^.^.^.......^.^...^.^...^.^.^.....^...^.^... +............................................................................................................................................. +..^.......^.......^.^.^...^.^.^.^.^.^.......^...^.^...^.^...^.^.^...^.^.....^...^.^.^.^.^...^...^...^.^.^.^.........^.^...^.^.^.^.^.^...^.^.. +............................................................................................................................................. +.^.^.^.^.^.^.^.^.........^.........^...^.^.^.^...^...^.....^.......^...^.........^.^.^.^.^.^.^.^.^.^...^.^.^.^.......^.^.^...^.^.^.^.^.^...^. +............................................................................................................................................. \ No newline at end of file diff --git a/2025/07/input_training.txt b/2025/07/input_training.txt new file mode 100644 index 0000000..8868910 --- /dev/null +++ b/2025/07/input_training.txt @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... \ No newline at end of file diff --git a/2025/07/load.sql b/2025/07/load.sql new file mode 100644 index 0000000..63bde4e --- /dev/null +++ b/2025/07/load.sql @@ -0,0 +1,36 @@ +DROP TABLE IF EXISTS raw; +CREATE TABLE raw(line TEXT); + +.import input_final.txt raw + +DROP TABLE IF EXISTS nodes; +CREATE TABLE nodes ( + row INTEGER, + col INTEGER, + entry TEXT +); + +INSERT INTO nodes (row, col, entry) +WITH RECURSIVE + grid AS ( + -- Start with each line, use rowid-1 as 0-based row index, + -- and column index 1 (SQLite strings are 1-based) + SELECT rowid - 1 AS row, + line, + 1 AS col + FROM raw + + UNION ALL + + -- Advance column index until we reach the end of the line + SELECT row, + line, + col + 1 + FROM grid + WHERE col < length(line) + ) +SELECT + row, -- 0-based row index + col - 1 AS col, -- convert to 0-based column index + substr(line, col, 1) AS entry +FROM grid; \ No newline at end of file diff --git a/2025/07/solve-1.sql b/2025/07/solve-1.sql new file mode 100644 index 0000000..11a1991 --- /dev/null +++ b/2025/07/solve-1.sql @@ -0,0 +1,72 @@ +WITH RECURSIVE +manifold AS ( + SELECT + row as rowm, + col as colm, + '|' as entry + FROM nodes where entry = 'S' + + UNION ALL + + -- Case 1: below is not '^' -> go straight down + SELECT + n.row AS rowm, + n.col AS colm, + '|' AS entry + FROM manifold m + JOIN nodes n + ON n.row = m.rowm + 1 + AND n.col = m.colm + WHERE n.entry = '.' and m.entry = '|' + + UNION ALL + + -- mark the places we split + SELECT + b.row AS rowm, + b.col AS colm, + '*' AS entry + FROM manifold m + JOIN nodes b + ON b.row = m.rowm + 1 + AND b.col = m.colm + AND b.entry = '^' + + UNION ALL + + -- Case 2a: below is '^' -> go down-left + SELECT + nl.row AS rowm, + nl.col AS colm, + '|' AS entry + FROM manifold m + JOIN nodes b + ON b.row = m.rowm + 1 + AND b.col = m.colm + AND b.entry = '^' + JOIN nodes nl + ON nl.row = b.row -- same row as the '^' below + AND nl.col = b.col - 1 -- left + + UNION ALL + + -- Case 2b: below is '^' -> go down-right + SELECT + nr.row AS rowm, + nr.col AS colm, + '|' AS entry + FROM manifold m + JOIN nodes b + ON b.row = m.rowm + 1 + AND b.col = m.colm + AND b.entry = '^' + JOIN nodes nr + ON nr.row = b.row -- same row as the '^' below + AND nr.col = b.col + 1 -- right + +) + +select count(*) from ( + select rowm, colm, count(*) from manifold where entry = '*' + group by 1, 2 + ) \ No newline at end of file