mirror of
https://github.com/daylinmorgan/advent-of-code-2023.git
synced 2024-12-22 03:10:44 -06:00
add starter files for 2023
This commit is contained in:
parent
88ea2deff4
commit
613cc75237
5 changed files with 182 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
input.txt
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Advent of Code 2023
|
||||||
|
|
||||||
|
![tree](./assets/tree.svg)
|
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 |
112
tools/aoc.nim
Normal file
112
tools/aoc.nim
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
import std/[httpclient, os, strformat, strutils, terminal, times]
|
||||||
|
|
||||||
|
let aocCookie = getEnv("AOC_COOKIE")
|
||||||
|
|
||||||
|
proc errQuit(msg: string) =
|
||||||
|
stderr.styledWriteLine(fgRed, "AOCError", fgDefault, ": ", msg)
|
||||||
|
quit 1
|
||||||
|
|
||||||
|
proc getInput(year, day: int): string =
|
||||||
|
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) =
|
||||||
|
const solution = """
|
||||||
|
import std/[strutils]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
echo partOne(example)
|
||||||
|
echo partOne(input)
|
||||||
|
echo partTwo(example)
|
||||||
|
echo partTwo(input)
|
||||||
|
"""
|
||||||
|
let test = fmt"""
|
||||||
|
import std/unittest
|
||||||
|
import ./solution
|
||||||
|
|
||||||
|
suite "day {day}":
|
||||||
|
test "part one":
|
||||||
|
check partOne(example) == 0
|
||||||
|
check partOne(input) == 0
|
||||||
|
test "part two":
|
||||||
|
check partTwo(example) == 0
|
||||||
|
check partTwo(input) == 0
|
||||||
|
|
||||||
|
"""
|
||||||
|
let d = fmt"solutions/day{day:0>2}"
|
||||||
|
writeFile(d / "solution.nim", solution)
|
||||||
|
writeFile(d / "test.nim", test)
|
||||||
|
|
||||||
|
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 environemnt 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":
|
||||||
|
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 = today.weekday.ord
|
||||||
|
|
||||||
|
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
tools/aoc.nim.cfg
Normal file
1
tools/aoc.nim.cfg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
-d:ssl
|
Loading…
Reference in a new issue