Initial commit: Days 1 - 5

This commit is contained in:
ctsk
2025-12-06 17:20:26 +01:00
commit 92828e6272
11 changed files with 6332 additions and 0 deletions

35
day01.sql Normal file
View File

@@ -0,0 +1,35 @@
with
instructions as (
select
case when line[1] = 'L' then -1 else 1 end as dir,
cast(line[2:] as int) as amount,
row_number() over () as id
from read_csv('data/01.in', header = false) file (line)
),
positions as (
select 50 + sum(dir * amount) over (order by id) as abs_pos
from instructions
),
clicks as (
select
dir as click,
row_number() over (order by id) as click_id
from instructions, generate_series(1, amount)
),
all_positions as (
select 50 + sum(click) over (order by click_id) as abs_pos
from clicks
)
select
(
select count(*) from positions
where abs_pos % 100 = 0
) as p1,
(
select count(*) from all_positions
where abs_pos % 100 = 0
) as p2;