diff --git a/data/07.in b/data/07.in new file mode 100644 index 0000000..0e74403 --- /dev/null +++ b/data/07.in @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^...^................................................................... +............................................................................................................................................. +..................................................................^.^.....^.................................................................. +............................................................................................................................................. +.................................................................^.....^...^................................................................. +............................................................................................................................................. +................................................................^...^.^.....^................................................................ +............................................................................................................................................. +...............................................................^.^.^.^.^.^...^............................................................... +............................................................................................................................................. +..............................................................^.^...^.^.^...^.^.............................................................. +............................................................................................................................................. +.............................................................^.^.^.^...^.^.^.^.^............................................................. +............................................................................................................................................. +............................................................^...^.^.^.^.^.^.^...^............................................................ +............................................................................................................................................. +...........................................................^.^...^.....^...^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^.^.^.^.^.....^.....^...^.......................................................... +............................................................................................................................................. +.........................................................^.^.^.^.^.^.^.....^.^.^.^.^......................................................... +............................................................................................................................................. +........................................................^.^.^.^...^.^.^.^.^.......^.^........................................................ +............................................................................................................................................. +.......................................................^...^.^.^.^.^.^.^...^.^...^...^....................................................... +............................................................................................................................................. +......................................................^.^.....^.....^.^.^.^.....^.^.^.^...................................................... +............................................................................................................................................. +.....................................................^...^...^.^.^.^.^...^...^.^...^.^.^..................................................... +............................................................................................................................................. +....................................................^.....^.^...^...^...^.^.....^...^...^.................................................... +............................................................................................................................................. +...................................................^.^.^...^.....^.....^.^...^.^.^.^.^.^.^................................................... +............................................................................................................................................. +..................................................^...^.^...^.....^...^.^...^.....^...^.^.^.................................................. +............................................................................................................................................. +.................................................^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^................................................. +............................................................................................................................................. +................................................^.^...^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^................................................ +............................................................................................................................................. +...............................................^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.....^...^.^............................................... +............................................................................................................................................. +..............................................^.^.....^.^...^.^...^.^.^...^.^.^.^.^.^.....^.^.^.............................................. +............................................................................................................................................. +.............................................^.^.......^.........^...^.....^.^.^.^.^.^...^.^...^............................................. +............................................................................................................................................. +............................................^...^.^...^.^.^.^.^...........^...^.^.^...^.^.^.^...^............................................ +............................................................................................................................................. +...........................................^...^.^.^...^.^.^.^...^...^.^.^.....^...^.^.^.^.^...^.^........................................... +............................................................................................................................................. +..........................................^.^.^...^...^.^.........^...^.^.^.^.^.^.^.......^.^.^...^.......................................... +............................................................................................................................................. +.........................................^.^.^.^.^.^.^.........^.^...^.^.^.^.^.^...^...^...^.^.^...^......................................... +............................................................................................................................................. +........................................^...^.^...^.....^.^.^.^.^.^...^.^.^.^...^.^.^...^.^...^...^.^........................................ +............................................................................................................................................. +.......................................^...^...^...^.^.^.^.^.^...^.^.^.^.......^.^...^.^.^...^.......^....................................... +............................................................................................................................................. +......................................^.....^...^.^...^.^.^.^...^...^.^.^...^.^.....^.^.^.^...^...^.^.^...................................... +............................................................................................................................................. +.....................................^.^...^.........^.^...^...^.^.....^.^.^.^...^.^.......^.^.^...^.^.^..................................... +............................................................................................................................................. +....................................^.^.^.^.^.^.^...^...^.^...^.^.......^.^.^.^...^...^.^.^.^.^...^.^...^.................................... +............................................................................................................................................. +...................................^.....^.^.^.^.^.^...........^...^.^.^.^.^.^.^.^.^.^.^...^...^.^...^.^.^................................... +............................................................................................................................................. +..................................^...^...^.^...^.^.^.^...^.^.^...^...^...^.^.^.^.^.....^...^...^.^.^.....^.................................. +............................................................................................................................................. +.................................^...^.^.^.^.^.^.....^.^.....^.^.^...^...^.^.....^.......^.....^...^.^...^.^................................. +............................................................................................................................................. +................................^.^.^.^...^.^.^.^.^.^.^.......^.^.^.^.^...^...^.^.^.^.^...^.^.......^.....^.^................................ +............................................................................................................................................. +...............................^.^...^...^.....^.^...^.......^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.......^.^.^...^............................... +............................................................................................................................................. +..............................^...^.....^.^.^.^.....^.^.^.^.^.^.^.^.....^...^.^...^.^.^.^.^...^.^.....^.^.^.^.^.............................. +............................................................................................................................................. +.............................^.^...^...^.^.^.^.^.^.^.^.......^.....^.^.........^...^.^...^.^.^.....^.^.^.^.^.^.^............................. +............................................................................................................................................. +............................^.^.^.^...^...^.....^...^.^.....^.^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^.^.^.^.^.^.^.^............................ +............................................................................................................................................. +...........................^.^.^.^.^.^...^.^.^.^.^...^.^.......^...^.^.^.^.^.^.^.^...^.^.^.....^...^.^.....^.^.^.^........................... +............................................................................................................................................. +..........................^.^.^.^.^.^.^.^.^.......^.^.^...^...^.....^.^.^.^.^.....^.^.^...^...^...........^.^.^...^.......................... +............................................................................................................................................. +.........................^.^...^...^.......^...^...^.^...^.^.....^...^.^.^...^.^.^.^.^.^.^.^.......^.^...^...^.....^......................... +............................................................................................................................................. +........................^.^.^.^.^.^.^.^.....^.^...^.^.^.^...^.....^.^.^...^...^.^.^.^...^.....^.^.....^.^.....^.^.^.^........................ +............................................................................................................................................. +.......................^.^.^.^.^.^.^...^...^.^.^...^.^.^.....^.^.^.....^.^.^.^.^.^.....^.^...^...^.^.^.^.^.^.^.....^.^....................... +............................................................................................................................................. +......................^...^.^.^.^.....^.....^.^.^.......^...^.^.^.^...^.....^.^.^.^.^.^.^.^.^.^.^...^...^...^...^.^...^...................... +............................................................................................................................................. +.....................^.^...^.^.^.^.^.^...^.^.^...^.^.....^.^...^.^.^.^.^.^.^.....^.^.^.^.^.......^.......^.^.^.^.^.^.^.^..................... +............................................................................................................................................. +....................^.^.^.......^.......^.^.....^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.....^.....^.^.^.................... +............................................................................................................................................. +...................^.....^.^...^...^.^.^.^...^.^.^.......^.^.^.^.^.^.^.^.^.^.^.^.......^.^.^.^.......^.^.^...^...^.^.^...^................... +............................................................................................................................................. +..................^.^.^.....^.^.^.^.^.^...^.....^.^.^.^.^.^.^...^.^.^.....^...^.^.^.^.^.^...^.^.^...^.^.^.^...^.^.^...^.^.^.................. +............................................................................................................................................. +.................^.......^...^.^.......^.^.^.^.^...^...^.^...^.^...^.^.....^.....^.^.^.^...^...^...^.^.^...^.^.^.^.^.^.^.^.^................. +............................................................................................................................................. +................^.....^.^...^.^.^.^.^.....^.^.^...^...^.^...^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.......^...^.^...^.^.^.^................ +............................................................................................................................................. +...............^.^...^.^.^.....^.........^...^.....^.^.^.........^.^.^.^...^.^.^.^...^.^.^...^.^.....^.^.^.^...^...^.^.^.^.^.^............... +............................................................................................................................................. +..............^.^.^...^.^.^.^.^.....^.^.^.^.^...^.^.^.^.......^...^.......^.^.^.^.^.^...^.^.....^.^...^.......^.^.^.....^.....^.............. +............................................................................................................................................. +.............^.^.^.^.^...^...^...^.....^.^.^.^.^.^.^...^.....^.^...^.^...^.^.......^.^.^.^.^.^.^...^.......^...^.^...^.^.^.^.^.^............. +............................................................................................................................................. +............^.^...^...^.....^.^...^.^.^.^.....^...^.^...^.....^.^.^.^...^.^.^...........^...^.^.^.^...^.^.^.^.^.^.^.....^.^.^.^.^............ +............................................................................................................................................. +...........^...^...^.......^.^...^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^.^...^.....^.^.^.^.^.^...^.^.^.....^...^.......^...^...^.^.^.^........... +............................................................................................................................................. +..........^.^.^.^.^...^.^.^.....^...^.^...^.^.^...^.......^.^.^.^...^.^.^.^.....^.^.^...^.^.^...^...^...^.^...^.^.^...^.....^.^...^.......... +............................................................................................................................................. +.........^.^.^.....^...^.^.^.......^.^.^...^.^...^.^.^.^...^.......^.^.^.^...^...^.^.^.^.^.....^.^.^...^...^.....^.^.....^.^.^...^.^......... +............................................................................................................................................. +........^.^.^.^.^.^.^...^.^.....^.......^...^.^.^.^.^.....^.........^.^...^.^...^.^.^...^.^.....^.^.^...^.^.^.^.^...^.^.^...^...^.^.^........ +............................................................................................................................................. +.......^.^.^.^.^...^.^.......^.^.^.^.^.........^.^.....^.^.^.^.^...^.^.^...^.^.^.^.......^.^.......^...^.^.^.^.^.^.^.^.....^.....^.^.^....... +............................................................................................................................................. +......^...^.^.^.^.^.^.^.....^.^.^...^.^.^.....^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^...^.^.^.^.....^.^.^...^...^.^...... +............................................................................................................................................. +.....^...^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.....^...^...^.^.^...^.^.^.^...^...^.^.^.^.^.^...^.^.^.....^...^...^.^.^.^.^.....^.^.^.^..... +............................................................................................................................................. +....^.^...^.^...^.^.^.^.^...^...^...^...^.^...^...^.^.^.^.^.^...^.....^.....^.^.....^...^.^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.^.^...^.^.... +............................................................................................................................................. +...^.^.^.^.^...^.^.^.^.....^.^.^.^.^...^.^.^...^.^...^.^...^.....^...^.....^.^.^.^...^.^.^...^.^...^...^.^.^.....^.^.^.^...^.^.^.^...^...^... +............................................................................................................................................. +..^.^.^...^.^...^.^.^.^...^.^.^.^.^.....^.^...^.........^.^...^.^...^.^.^.^...^.^.^.^.^.^.^.^...^.......^.^.^.^.^.^.^...^.^.^.....^.^.^...^.. +............................................................................................................................................. +.^.^.^.^.....^.^.^.....^...^.^.^.^.^.^.^...^...^.^...^.^.....^...^.^.^.......^.^.^.......^...^.^.^.^.^.^.^.^.^...^.^.^.......^...^.^.....^.^. +............................................................................................................................................. diff --git a/day07.sql b/day07.sql new file mode 100644 index 0000000..41a1a4b --- /dev/null +++ b/day07.sql @@ -0,0 +1,71 @@ +with recursive + +grid (line, row) as ( + select + unnest(line), + generate_subscripts(line, 1) as row + from ( + select string_split(trim(content, e'\n'), e'\n') as line + from read_text('data/07.in') + ) +), + +dims as ( + select + max(row) as height, + max(length(line)) as width + from grid +), + +initial as ( + select col from range(1, (select width from dims)) r (col), grid + where row = 1 and line[col] <> '.' +), + +trace (depth, col, num) as ( + select + 1, + col, + cast(1 as int128) + from initial + + union + + select + depth, + col, + sum(num) + from + ( + select + depth + 1 as depth, + unnest( + case + when line[col] = '^' + then [col - 1, col + 1] + else [col] + end + ) as col, + num + from + trace, grid + where + depth + 1 = row + ) + group by depth, col +), + +part1 (solution) as ( + select count(*) from trace, grid + where line[col] = '^' and depth + 1 = row +), + +part2 (solution) as ( + select sum(num) from trace + where depth = (select height from dims) +) + +select + part1.solution as p1, + part2.solution as p2 +from part1, part2;