File tree 2 files changed +2274
-0
lines changed
2 files changed +2274
-0
lines changed Original file line number Diff line number Diff line change
1
+ create temp table raw_input (calories int);
2
+
3
+ \copy raw_input from './day01.txt' with delimiter ',' csv
4
+
5
+ create temp table elves as
6
+ with with_row_number as (
7
+ select row_number() over () as row_number,
8
+ calories
9
+ from raw_input
10
+ ),
11
+ with_elf_id as (
12
+ select sum(case when calories is not null then 0 else 1 end) over (order by row_number) as elf_id,
13
+ calories
14
+ from with_row_number
15
+ )
16
+ select elf_id,
17
+ calories
18
+ from with_elf_id
19
+ where calories is not null;
20
+
21
+
22
+ select format('Problem 1: %s', sum(calories))
23
+ from elves
24
+ group by elf_id
25
+ order by sum(calories) desc
26
+ limit 1;
27
+
28
+
29
+ with top3_carriers as (
30
+ select elf_id, sum(calories) as total_calories
31
+ from elves
32
+ group by elf_id
33
+ order by sum(calories) desc
34
+ limit 3
35
+ )
36
+ select format('Problem 2: %s', sum(total_calories))
37
+ from top3_carriers;
You can’t perform that action at this time.
0 commit comments