setup skeleton for 2024
This commit is contained in:
commit
6f5d482865
9 changed files with 316 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
input.txt
|
22
LICENSE
Normal file
22
LICENSE
Normal file
|
@ -0,0 +1,22 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023 Daylin Morgan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
31
README.md
Normal file
31
README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Advent of Code 2024
|
||||
|
||||
<div align="center">
|
||||
<img
|
||||
src="./assets/tree.svg"
|
||||
alt="christmas tree"
|
||||
width="600"
|
||||
>
|
||||
</div>
|
||||
|
||||
To generate a new day and fetch the input's for a puzzle use the below command.
|
||||
Note: the day and year are inferred from today's date if not specified.
|
||||
Set advent of code session cookie to `AOC_COOKIE` environment variable.
|
||||
|
||||
```sh
|
||||
nim r ./src/aoc.nim # -d:1 -y:2024
|
||||
```
|
||||
|
||||
To quickly view solutions from your terminal use my soft-serve instance!
|
||||
|
||||
For an individual solution:
|
||||
|
||||
```sh
|
||||
ssh -p 23231 git.dayl.in repo blob advent-of-code-2024 solutions/day01/solution.nim
|
||||
```
|
||||
|
||||
To interactively explore repo:
|
||||
|
||||
```sh
|
||||
ssh -p 23231 git.dayl.in -t advent-of-code-2024
|
||||
```
|
65
assets/tree.svg
Normal file
65
assets/tree.svg
Normal file
|
@ -0,0 +1,65 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 800 600" width="800" height="600">
|
||||
<foreignObject width="100%" height="100%">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||
<style>
|
||||
.calendar .calendar-verycomplete {
|
||||
color: #a6e3a1;
|
||||
}
|
||||
.calendar .calendar-day25.calendar-verycomplete{ color: #f9e2af; }
|
||||
.calendar .calendar-day25.calendar-verycomplete{ text-shadow: 0 0 5px #f9e2af; }
|
||||
.calendar .calendar-trunk { color: #cccccc; }
|
||||
.calendar .calendar-verycomplete .calendar-ornament0 { text-shadow: 0 0 5px ##89b4fa; animation: anim-ornament 3s infinite;}
|
||||
.calendar .calendar-verycomplete .calendar-ornament1 { text-shadow: 0 0 5px #fab387; animation: anim-ornament 3s infinite 1.2s;}
|
||||
.calendar .calendar-verycomplete .calendar-ornament2 { text-shadow: 0 0 5px #f38ba8; animation: anim-ornament 3s infinite 2.4s;}
|
||||
.calendar .calendar-verycomplete .calendar-ornament3 { color: #f9e2af; text-shadow: 0 0 5px #f9e2af}
|
||||
@keyframes anim-ornament {
|
||||
0% { color: ##89b4fa; }
|
||||
32% { color: ##89b4fa; }
|
||||
|
||||
33% { color: #fab387; }
|
||||
65% {color: #fab387; }
|
||||
|
||||
66% { color: #f38ba8;}
|
||||
100% { color: #f38ba8;}
|
||||
}
|
||||
.calendar .calendar-lightbeam { visibility: hidden; color: #666666; }
|
||||
.calendar .calendar-verycomplete .calendar-lightbeam { visibility: visible; }
|
||||
.calendar .calendar-verycomplete .calendar-lightbeam { color: #f9e2af; text-shadow: 0 0 5px #f9e2af; }
|
||||
</style>
|
||||
<!-- tree from https://adventofcode.com/2015 -->
|
||||
<div style="background-color: #0f0f23; padding: 2em">
|
||||
<pre class="calendar calendar-perfect"><span class="calendar-day25 calendar-verycomplete"> <span class="calendar-lightbeam">|</span>
|
||||
<span class="calendar-lightbeam">\</span><span class="calendar-lightbeam">|</span><span class="calendar-lightbeam">/</span>
|
||||
<span class="calendar-lightbeam">-</span><span class="calendar-lightbeam">-</span>*<span class="calendar-lightbeam">-</span><span class="calendar-lightbeam">-</span></span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament1">o</span>< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament1">o</span><< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament3">*</span>>><span class="calendar-ornament1">o</span>< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament3">*</span>><span class="calendar-ornament0">O</span><<<< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament0">O</span>><span class="calendar-ornament2">@</span>>>><span class="calendar-ornament0">O</span><< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament3">*</span><<<span class="calendar-ornament3">*</span>>><span class="calendar-ornament1">o</span>>><span class="calendar-ornament2">@</span><< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament2">@</span><<span class="calendar-ornament1">o</span>><span class="calendar-ornament2">@</span>>><span class="calendar-ornament0">O</span><<<<span class="calendar-ornament3">*</span><< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament1">o</span><<span class="calendar-ornament0">O</span>><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament3">*</span><<< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament3">*</span>>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament3">*</span>>>><span class="calendar-ornament0">O</span><<span class="calendar-ornament2">@</span>>><span class="calendar-ornament3">*</span>< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament1">o</span><<<span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span>><span class="calendar-ornament1">o</span><<span class="calendar-ornament1">o</span><<<<span class="calendar-ornament2">@</span>><span class="calendar-ornament2">@</span><<< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament3">*</span>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament3">*</span>>>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament3">*</span>>>><span class="calendar-ornament1">o</span><<<< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament1">o</span>>><span class="calendar-ornament3">*</span><<<span class="calendar-ornament0">O</span><<<span class="calendar-ornament3">*</span><<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament3">*</span><<span class="calendar-ornament0">O</span><<<<span class="calendar-ornament0">O</span>< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament0">O</span><<<span class="calendar-ornament2">@</span>>>><span class="calendar-ornament0">O</span><<<span class="calendar-ornament2">@</span><<<span class="calendar-ornament0">O</span><<span class="calendar-ornament0">O</span><<<span class="calendar-ornament0">O</span>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament0">O</span><< </span>
|
||||
<span class=" calendar-verycomplete"> ><span class="calendar-ornament2">@</span>>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament2">@</span><<span class="calendar-ornament1">o</span>><span class="calendar-ornament1">o</span>><span class="calendar-ornament0">O</span><<<span class="calendar-ornament3">*</span>><span class="calendar-ornament3">*</span><<<span class="calendar-ornament1">o</span><<<span class="calendar-ornament3">*</span><<<span class="calendar-ornament0">O</span>< </span>
|
||||
<span class=" calendar-verycomplete"> ><span class="calendar-ornament1">o</span><<<<span class="calendar-ornament1">o</span><<<<span class="calendar-ornament2">@</span>><span class="calendar-ornament0">O</span><<span class="calendar-ornament3">*</span>>><span class="calendar-ornament2">@</span>>><span class="calendar-ornament3">*</span><<span class="calendar-ornament0">O</span><<<span class="calendar-ornament0">O</span>><span class="calendar-ornament0">O</span><<span class="calendar-ornament3">*</span><< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span><<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament1">o</span>>><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament2">@</span>><span class="calendar-ornament1">o</span><<<<span class="calendar-ornament0">O</span><<<span class="calendar-ornament0">O</span><<span class="calendar-ornament1">o</span><<<span class="calendar-ornament3">*</span>< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament0">O</span><<span class="calendar-ornament1">o</span>>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament0">O</span><<<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament0">O</span>>><span class="calendar-ornament0">O</span><<<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament1">o</span>< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament1">o</span><<span class="calendar-ornament1">o</span><<span class="calendar-ornament0">O</span>>>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament1">o</span><<<<span class="calendar-ornament3">*</span><<<span class="calendar-ornament2">@</span>>>><span class="calendar-ornament0">O</span>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament2">@</span><<span class="calendar-ornament1">o</span>>><span class="calendar-ornament3">*</span>< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament2">@</span><<<span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span>>>><span class="calendar-ornament2">@</span>>>><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament0">O</span><<span class="calendar-ornament1">o</span><<span class="calendar-ornament2">@</span>><span class="calendar-ornament2">@</span><<span class="calendar-ornament3">*</span><<<span class="calendar-ornament3">*</span>><span class="calendar-ornament2">@</span><<<span class="calendar-ornament3">*</span><<span class="calendar-ornament1">o</span>< </span>
|
||||
<span class="calendar-verycomplete"> >><span class="calendar-ornament2">@</span>>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament0">O</span><<span class="calendar-ornament3">*</span><<<<span class="calendar-ornament3">*</span><<<<span class="calendar-ornament3">*</span>><span class="calendar-ornament1">o</span><<<span class="calendar-ornament2">@</span>><span class="calendar-ornament0">O</span><<span class="calendar-ornament1">o</span>>><span class="calendar-ornament2">@</span>><span class="calendar-ornament1">o</span>< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament2">@</span><<span class="calendar-ornament0">O</span>>>><span class="calendar-ornament2">@</span><<<span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span><<<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament2">@</span><<<span class="calendar-ornament3">*</span><<<span class="calendar-ornament3">*</span><<<<span class="calendar-ornament1">o</span><<span class="calendar-ornament0">O</span>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament0">O</span>>>><span class="calendar-ornament3">*</span>< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament2">@</span>>><span class="calendar-ornament1">o</span>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament0">O</span><<<span class="calendar-ornament0">O</span><<<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament1">o</span>><span class="calendar-ornament1">o</span>>>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament2">@</span><<<<span class="calendar-ornament1">o</span><<span class="calendar-ornament0">O</span><<<span class="calendar-ornament0">O</span><< </span>
|
||||
<span class="calendar-verycomplete"> ><span class="calendar-ornament1">o</span><<<<span class="calendar-ornament2">@</span><<<span class="calendar-ornament3">*</span><<<<span class="calendar-ornament0">O</span>>>><span class="calendar-ornament2">@</span>><span class="calendar-ornament1">o</span>><span class="calendar-ornament0">O</span>>><span class="calendar-ornament0">O</span><<span class="calendar-ornament3">*</span><<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament1">o</span>><span class="calendar-ornament3">*</span><<span class="calendar-ornament2">@</span><<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament0">O</span>><span class="calendar-ornament1">o</span><< </span>
|
||||
<span class="calendar-verycomplete">><span class="calendar-ornament0">O</span>>>><span class="calendar-ornament2">@</span><<<<span class="calendar-ornament0">O</span><<span class="calendar-ornament3">*</span><<span class="calendar-ornament3">*</span>>>><span class="calendar-ornament2">@</span>>>><span class="calendar-ornament3">*</span><<span class="calendar-ornament3">*</span><<span class="calendar-ornament0">O</span><<<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament1">o</span>>>><span class="calendar-ornament2">@</span>>><span class="calendar-ornament0">O</span><<span class="calendar-ornament2">@</span><<<<span class="calendar-ornament3">*</span><<< </span>
|
||||
<span class="calendar-trunk"> | |
|
||||
| |
|
||||
_ _ __ ___|___|___ __ _ _</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</foreignObject>
|
||||
</svg>
|
After Width: | Height: | Size: 14 KiB |
9
config.nims
Normal file
9
config.nims
Normal file
|
@ -0,0 +1,9 @@
|
|||
import std/[algorithm, os, sequtils]
|
||||
|
||||
--noNimblePath
|
||||
--path:"./src"
|
||||
|
||||
task solve, "run all solutions":
|
||||
for dir in walkDirRec("solutions", yieldFilter = {pcDir}).toSeq().sortedByIt(it):
|
||||
echo "--",dir,"--"
|
||||
selfExec "r --hint:all:off " & dir & "/solution.nim"
|
27
flake.lock
Normal file
27
flake.lock
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1732837521,
|
||||
"narHash": "sha256-jNRNr49UiuIwaarqijgdTR2qLPifxsVhlJrKzQ8XUIE=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "970e93b9f82e2a0f3675757eb0bfc73297cc6370",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
28
flake.nix
Normal file
28
flake.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
description = "advent of code 2023";
|
||||
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
||||
outputs =
|
||||
{ nixpkgs, ... }:
|
||||
let
|
||||
inherit (nixpkgs.lib) genAttrs;
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-linux"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
forAllSystems = f: genAttrs systems (system: f (import nixpkgs { inherit system; }));
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems (pkgs: {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
nim
|
||||
openssl
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
132
src/aoc.nim
Normal file
132
src/aoc.nim
Normal file
|
@ -0,0 +1,132 @@
|
|||
import std/[
|
||||
httpclient, macros, os,
|
||||
strformat, strutils, terminal, times
|
||||
]
|
||||
|
||||
macro solve*(arg: untyped): untyped =
|
||||
arg.expectKind nnkStmtList
|
||||
result = newStmtList()
|
||||
for stmt in arg:
|
||||
stmt.expectKind nnkCall
|
||||
stmt[0].expectKind nnkStrLit
|
||||
stmt[1].expectKind nnkStmtList
|
||||
for inputs in stmt[1]:
|
||||
inputs.expectKind nnkCall
|
||||
inputs[0].expectKind nnkIdent
|
||||
inputs[1].expectKind nnkStmtList
|
||||
let
|
||||
part = inputs[0]
|
||||
inputFile = stmt[0]
|
||||
output = inputs[1][0]
|
||||
msg = newLit(part.repr & "|" & inputFile.strVal)
|
||||
result.add quote do:
|
||||
block:
|
||||
const input = slurp(getProjectPath() / `inputFile`).strip()
|
||||
let solution = `part`(input)
|
||||
if solution == `output`:
|
||||
stdout.styledWriteLine fgGreen, `msg`
|
||||
else:
|
||||
stdout.styledWriteLine fgRed, `msg`
|
||||
stdout.writeLine " expected: ", $`output`, "; got: ", solution
|
||||
|
||||
|
||||
|
||||
proc errQuit(msg: string) =
|
||||
stderr.styledWriteLine(fgRed, "AOCError", fgDefault, ": ", msg)
|
||||
quit 1
|
||||
|
||||
proc getInput(year, day: int): string =
|
||||
let aocCookie = getEnv("AOC_COOKIE")
|
||||
let url = fmt"https://adventofcode.com/{year}/day/{day}/input"
|
||||
var response: Response
|
||||
var client = newHttpClient()
|
||||
client.headers = newHttpHeaders({"Cookie": aocCookie})
|
||||
try:
|
||||
response = client.request(url)
|
||||
finally:
|
||||
client.close()
|
||||
return response.body().strip()
|
||||
|
||||
proc skeleton(day: int) =
|
||||
let solution = fmt"""
|
||||
import std/[strutils]
|
||||
import aoc
|
||||
|
||||
const example* = slurp("example.txt").strip()
|
||||
const input* = slurp("input.txt").strip()
|
||||
|
||||
proc parseInput(input: string)
|
||||
|
||||
proc partOne*(input: string): int = 0
|
||||
proc partTwo*(input: string): int = 0
|
||||
|
||||
solve:
|
||||
"example.txt":
|
||||
partOne: 0
|
||||
partTwo: 0
|
||||
"input.txt":
|
||||
partOne: 0
|
||||
partTwo: 0
|
||||
"""
|
||||
let d = fmt"solutions/day{day:0>2}"
|
||||
writeFile(d / "solution.nim", solution)
|
||||
|
||||
proc newDay(year, day: int) =
|
||||
let d = fmt"solutions/day{day:0>2}"
|
||||
createDir d
|
||||
let input = getInput(year, day)
|
||||
if input.startsWith "Puzzle inputs differ by user.":
|
||||
errQuit "faild to get input check cookie environment variable, AOC_COOKIE"
|
||||
elif input.startsWith "Please don't repeatedly request this endpoint before it unlocks!":
|
||||
errQuit "don't abuse the service and make sure the day exists first"
|
||||
writeFile(d / "input.txt", input)
|
||||
skeleton(day)
|
||||
|
||||
|
||||
|
||||
when isMainModule:
|
||||
import std/parseopt
|
||||
if not (dirExists(".git") or dirExists(".jj")):
|
||||
errQuit "only run from root dir of project"
|
||||
const help = """
|
||||
!
|
||||
-~*~-
|
||||
/!\
|
||||
/%;@\
|
||||
o/@,%\o
|
||||
/%;`@,\
|
||||
o/@'%',\o
|
||||
'^^^N^^^`
|
||||
|
||||
usage:
|
||||
aoc [opts]
|
||||
|
||||
options:
|
||||
-d, --day int day of the month
|
||||
-y, --year int day of the year
|
||||
"""
|
||||
let today = now()
|
||||
var
|
||||
year = today.year
|
||||
day = parseInt(today.format("d"))
|
||||
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
of cmdArgument:
|
||||
discard
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key:
|
||||
of "y", "year":
|
||||
year = parseInt(val)
|
||||
of "d", "day":
|
||||
day = parseInt(val)
|
||||
of "h", "help":
|
||||
echo help; quit 0
|
||||
of cmdEnd:
|
||||
discard
|
||||
|
||||
echo "Fetching input for: "
|
||||
echo fmt" year -> {year}"
|
||||
echo fmt" day -> {day}"
|
||||
newDay(year, day)
|
||||
|
1
src/config.nims
Normal file
1
src/config.nims
Normal file
|
@ -0,0 +1 @@
|
|||
--define:ssl
|
Loading…
Reference in a new issue