Advent of Code 2021 with PostgreSQL
github.com
github.com
- 1 statement per part - No schema needed
https://gitlab.com/feike/adventofcode/-/tree/master/2021
Some others doing sql based solutions:
https://github.com/xocolatl/advent-of-code https://github.com/zr40/adventofcode
When AOC 2021 is done I hope I will find the time to compile the different approaches for each day and compare them.
My current list of repos is this:
- https://gitlab.com/autra/adventofcode
- https://gitlab.com/feike/adventofcode
- https://github.com/dflss/advent-of-code-2021
- https://github.com/mitchellh/advent-2021-sql
- https://github.com/qwesda/AOC2021-postgresql
- https://github.com/WilliamLP/AdventOfCode
Baller move, Mitchell.
Picking something way out of your comfort zone will force you to learn a ton as you go along.
It has at least been nice checking out the Reddit every night and seeing everyone else's code and micro optimizations I missed or different paradigms.
The repository also contains couple of mix tasks to generate boilerplate codes for each solve. And update the readme automatically on each commit to list the problems that I've solved so far.
[0] Elixir: https://elixir-lang.org/
[1] Github: https://github.com/wasi0013/advent_of_code
Those are helpful to learn different approaches to solving these problems.
[0] Github: https://github.com/josevalim/aoc
[1] Twitch: https://www.twitch.tv/collections/k_DLnk2tvBa-fQ
SELECT
lineno::int AS line,
((lineno-3)/6)::smallint AS card,
((lineno-3)%6)::smallint AS y,
(col - 1)::smallint AS x,
value::smallint AS value
FROM
regexp_split_to_table($1, '\n') WITH ORDINALITY AS sub(line, lineno)
CROSS JOIN
regexp_split_to_table(ltrim(line, ' '), '(\s+|,)') WITH ORDINALITY AS sub2(value, col)
WHERE
line != ''
AND value != ''I can't see where it is creating a window of three results to compare against. I guess, you might just be able to change the offset to 3, as the offsets of 1 and 2 will be included in your current window so don't need to be compared.
https://github.com/jarshwah/advent-of-code/blob/main/sql/202...
Though now I know you can ignore the window and just compare against the 3rd offset, the first solution just needs a `LEAD(depth, 3)` to complete the second question.
Still - I learned about `RANGE BETWEEN` so I'm calling it a win.
BTW awesome products Hashicorp, way to go!