Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hgwood/advent-of-code-sql
My solutions to Advent Of Code, written in SQL. See https://adventofcode.com/.
https://github.com/hgwood/advent-of-code-sql
advent-of-code advent-of-code-2022-sql advent-of-code-2023-sql postgresql sql
Last synced: 25 days ago
JSON representation
My solutions to Advent Of Code, written in SQL. See https://adventofcode.com/.
- Host: GitHub
- URL: https://github.com/hgwood/advent-of-code-sql
- Owner: hgwood
- Created: 2022-12-15T17:07:01.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-18T00:07:52.000Z (11 months ago)
- Last Synced: 2023-12-19T02:50:45.216Z (11 months ago)
- Topics: advent-of-code, advent-of-code-2022-sql, advent-of-code-2023-sql, postgresql, sql
- Language: Shell
- Homepage:
- Size: 155 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Advent of Code SQL
My solutions to Advent of Code, written in SQL.
## How to run
Run the database then run the solver for the day and part you want on the input you want.
```
docker compose up -d
sh run.sh 2022/day_1/part_1.psql 2022/day_1/example.txt
```## How it works
The code is meant to be run on Postgres 16+. Solutions are written using only
SQL (no PLpg/SQL). `run.sh` runs `run.psql` using `psql` (the Postgres client
CLI). `run.psql` creates a schema named `tmp` then sets the search path to it so
that all objects created after that are placed in this schema. Then it runs
`import.psql` which import the input file into the `input` table. Then it runs
the solver (a `.psql` file). Finally, it drops the `tmp` schema, which drops all
objects created by the solver.## Philosophy
I mostly use SQL as a purely functional language here. Once the input is loaded
into the `input` table, I try to only use `select` to compute stuff from it,
along with `create table as` to store results for further computations. I try
not to use stateful tables (2022 day 5 is the only exception).