Skip to content

Commit 9ebc928

Browse files
committed
Initial commit
0 parents  commit 9ebc928

File tree

9 files changed

+1563
-0
lines changed

9 files changed

+1563
-0
lines changed

.github/workflows/run.yml.disabled

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Run
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
run:
8+
runs-on: ${{ matrix.os }}
9+
name: Day ${{ matrix.day }} (${{ matrix.os }})
10+
11+
strategy:
12+
matrix:
13+
os: ['ubuntu-latest', 'macos-latest']
14+
day: ['01']
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: cachix/install-nix-action@v22
19+
with:
20+
nix_path: nixpkgs=channel:nixos-unstable
21+
- name: Build
22+
# We have to disable sandboxing to allow derivations to access the network
23+
# during builds. This is required e.g. to build day 9's PAKCS with Haskell
24+
# Stack, which downloads its own GHC, packages etc.
25+
run: nix build -v --option sandbox false || (nix log; exit 1)
26+
working-directory: 'day${{ matrix.day }}'
27+
- name: Run with input
28+
run: nix run . resources/input.txt
29+
working-directory: 'day${{ matrix.day }}'

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*~
2+
.vscode
3+
.DS_Store
4+
*.swp
5+
.curry
6+
.metals
7+
.fake
8+
9+
# Ignore build outputs from performing a nix-build or `nix build` command
10+
result
11+
result-*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 fwcd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- Automatically generated from README.md.gyb, do not edit directly! -->
2+
3+
# Advent of Code 2024
4+
5+
[![Run](https://github.com/fwcd/advent-of-code-2024/actions/workflows/run.yml/badge.svg)](https://github.com/fwcd/advent-of-code-2024/actions/workflows/run.yml)
6+
7+
My solutions to the [Advent of Code 2024](https://adventofcode.com/2024), written in 25 different programming languages.
8+
9+
10+
## Development
11+
12+
The programs are packaged with [Nix](https://nixos.org/), a functional package manager for Linux and macOS that focuses on reproducible builds. This makes it easy to build the programs, both locally and CI, without relying on system packages.
13+
14+
To build one of the days, `cd` into the corresponding directory and build and/or run the Nix flake. For example, to run day 1, use the following commands:
15+
16+
```sh
17+
cd day01
18+
nix run . resources/input.txt
19+
```
20+
21+
Every day is packaged up to take exactly one command-line argument, the input file, and usually includes the demo input from the exercise too.
22+
23+
> [!TIP]
24+
> The build environment can be added to the current `PATH` using `nix develop`. This is useful to manually run the compiler.
25+
26+
## Previous Years
27+
28+
My solutions to the previous challenges can be found here:
29+
30+
- [Advent of Code 2023](https://github.com/fwcd/advent-of-code-2023)
31+
- [Advent of Code 2022](https://github.com/fwcd/advent-of-code-2022)
32+
- [Advent of Code 2021](https://github.com/fwcd/advent-of-code-2021)
33+
- [Advent of Code 2020](https://github.com/fwcd/advent-of-code-2020)
34+
- [Advent of Code 2019](https://github.com/fwcd/advent-of-code-2019)
35+
- [Advent of Code 2015](https://github.com/fwcd/advent-of-code-2015)

README.md.gyb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
%{
2+
import json
3+
4+
with open('paths.json', 'r') as f:
5+
days = json.load(f)
6+
7+
def format_solution(solution):
8+
lang = solution['lang']
9+
path = solution['path']
10+
s = f"[{lang['name']}]({path})"
11+
12+
additional_paths = solution.get('additionalPaths', '')
13+
if additional_paths:
14+
s += f" ({', '.join(f'[{name}]({path})' for name, path in additional_paths.items())})"
15+
16+
additional_notes = solution.get('additionalNotes', '')
17+
if additional_notes:
18+
s += f' {additional_notes}'
19+
return s
20+
21+
def day_links(ds):
22+
return f"day {', '.join(f'[{d}](day{d:02})' for d in ds)}"
23+
}%
24+
<!-- Automatically generated from README.md.gyb, do not edit directly! -->
25+
26+
# Advent of Code 2024
27+
28+
[![Run](https://github.com/fwcd/advent-of-code-2024/actions/workflows/run.yml/badge.svg)](https://github.com/fwcd/advent-of-code-2024/actions/workflows/run.yml)
29+
30+
My solutions to the [Advent of Code 2024](https://adventofcode.com/2024), written in 25 different programming languages.
31+
32+
% for i, day in enumerate(days):
33+
% if day:
34+
- [${'x' if day.get('completed', False) else ' '}] [**Day ${f'{i + 1:02}'}**](day${f'{i + 1:02}'}): ${', '.join(format_solution(part) for part in day.get('parts', [day]))}
35+
% end
36+
% end
37+
38+
## Development
39+
40+
The programs are packaged with [Nix](https://nixos.org/), a functional package manager for Linux and macOS that focuses on reproducible builds. This makes it easy to build the programs, both locally and CI, without relying on system packages.
41+
42+
To build one of the days, `cd` into the corresponding directory and build and/or run the Nix flake. For example, to run day 4, use the following commands:
43+
44+
```sh
45+
cd day04
46+
nix run . resources/input.txt
47+
```
48+
49+
Every day is packaged up to take exactly one command-line argument, the input file, and usually includes the demo input from the exercise too.
50+
51+
> [!TIP]
52+
> The build environment can be added to the current `PATH` using `nix develop`. This is useful to manually run the compiler.
53+
54+
## Lessons Learned
55+
56+
- Visualize the input with GraphViz (${day_links([8, 20, 23, 25])})
57+
- Some puzzles are actually reverse-engineering exercises and rely on undocumented input constraints to be solved efficiently or even feasibly at all (${day_links([8, 20, 23])})
58+
- Take the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) to solve cycle alignment problems (${day_links([8, 20])})
59+
- If there are offsets, use the [CRT](https://en.wikipedia.org/wiki/Chinese_remainder_theorem) ([like in previous years](https://github.com/fwcd/advent-of-code-2020/blob/18c3ba9820cb52627366a632ccaab233a6d9f563/day13/src/day13.c#L39-L59))
60+
- Binary counters can elegantly be modeled as chains of flip flop (${day_links([20])})
61+
- Cross products can be surprisingly useful to turn the most nonlinear-looking problems into linear equations (${day_links([24])})
62+
63+
## Previous Years
64+
65+
My solutions to the previous challenges can be found here:
66+
67+
- [Advent of Code 2023](https://github.com/fwcd/advent-of-code-2023)
68+
- [Advent of Code 2022](https://github.com/fwcd/advent-of-code-2022)
69+
- [Advent of Code 2021](https://github.com/fwcd/advent-of-code-2021)
70+
- [Advent of Code 2020](https://github.com/fwcd/advent-of-code-2020)
71+
- [Advent of Code 2019](https://github.com/fwcd/advent-of-code-2019)
72+
- [Advent of Code 2015](https://github.com/fwcd/advent-of-code-2015)

paths.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

paths.schema.json

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "Advent of Code solution paths manifest",
4+
"description": "A manifest describing where the main sources for each day are located.",
5+
"definitions": {
6+
"lang": {
7+
"type": "object",
8+
"properties": {
9+
"codemirror": {
10+
"type": "string",
11+
"description": "The CodeMirror language mode of the implementation language",
12+
"examples": [
13+
"apl", "asn.1", "asterisk", "brainfuck", "clike", "clojure", "css",
14+
"cmake", "cobol", "coffeescript", "commonlisp", "crystal", "cypher",
15+
"python", "d", "dart", "django", "dockerfile", "diff", "dtd",
16+
"dylan", "ebnf", "ecl", "eiffel", "elixir", "elm", "erlang",
17+
"factor", "fcl", "forth", "fortran", "mllike", "gas", "gherkin",
18+
"go", "groovy", "haml", "handlebars", "haskell", "haxe",
19+
"htmlembedded", "htmlmixed", "idl", "javascript", "jinja2", "julia",
20+
"livescript", "lua", "markdown", "mathematica", "mbox", "mirc",
21+
"modelica", "mscgen", "mumps", "nginx", "nsis", "ntriples",
22+
"octave", "oz", "pascal", "pegjs", "perl", "asciiarmor", "php",
23+
"pig", "powershell", "properties", "protobuf", "pug", "puppet", "q",
24+
"r", "rpm", "rst", "ruby", "rust", "sas", "sass", "spreadsheet",
25+
"scheme", "shell", "sieve", "slim", "smalltalk", "smarty", "solr",
26+
"soy", "stylus", "sql", "sparql", "swift", "stex", "tcl", "textile",
27+
"tiddlywiki", "tiki", "toml", "tornado", "troff", "ttcn",
28+
"ttcn-cfg", "turtle", "twig", "vb", "vbscript", "velocity",
29+
"verilog", "vhdl", "vue", "webidl", "wast", "xml", "xquery",
30+
"yacas", "yaml", "yaml-frontmatter", "z80"
31+
]
32+
},
33+
"name": {
34+
"type": "string",
35+
"description": "The human-readable name of the language."
36+
}
37+
},
38+
"required": ["name"]
39+
},
40+
"solution": {
41+
"type": ["object", "null"],
42+
"description": "A solution.",
43+
"properties": {
44+
"lang": {
45+
"$ref": "#/definitions/lang"
46+
},
47+
"path": {
48+
"type": "string",
49+
"description": "The path to the main source file"
50+
},
51+
"encoding": {
52+
"type": "string",
53+
"default": "utf-8",
54+
"description": "Optionally a custom text encoding that the file uses (e.g. because the compiler/interpreter/IDE only supports the given encoding). See https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding#value for values.",
55+
"examples": [
56+
"utf-8", "ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4",
57+
"iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8",
58+
"iso-8859-8i", "iso-8859-10", "iso-8859-13", "iso-8859-14",
59+
"iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh",
60+
"windows-874", "windows-1250", "windows-1251", "windows-1252",
61+
"windows-1253", "windows-1254", "windows-1255", "windows-1256",
62+
"windows-1257", "windows-1258", "x-mac-cyrillic", "utf16-be",
63+
"utf16-le", "replacement"
64+
]
65+
},
66+
"binary": {
67+
"type": "boolean",
68+
"description": "Whether the file is in a binary (i.e. non-text) format.",
69+
"default": false
70+
},
71+
"additionalNotes": {
72+
"type": "string",
73+
"description": "Additional notes to be added to the README."
74+
}
75+
},
76+
"required": ["path"]
77+
},
78+
"day": {
79+
"description": "The solutions for a day.",
80+
"allOf": [
81+
{
82+
"type": "object",
83+
"properties": {
84+
"completed": {
85+
"type": "boolean",
86+
"description": "Whether the day has been completed (fully).",
87+
"default": false
88+
}
89+
}
90+
},
91+
{
92+
"anyOf": [
93+
{
94+
"$ref": "#/definitions/solution"
95+
},
96+
{
97+
"type": "object",
98+
"properties": {
99+
"parts": {
100+
"type": "array",
101+
"items": {
102+
"$ref": "#/definitions/solution"
103+
}
104+
}
105+
},
106+
"required": ["parts"]
107+
}
108+
]
109+
}
110+
]
111+
}
112+
},
113+
"type": "array",
114+
"items": {
115+
"$ref": "#/definitions/day"
116+
}
117+
}

scripts/generate-readme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e
4+
cd "$(dirname $0)/.."
5+
6+
scripts/gyb -o README.md --line-directive "" README.md.gyb

0 commit comments

Comments
 (0)