Skip to content

Commit 1e0b11e

Browse files
committed
scripts: new-day.sh
1 parent bc0115c commit 1e0b11e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/new-day.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Creates a new day solution template. Run from the root of the project.
5+
#
6+
# Parameters (all optional):
7+
# - DAY -- day index defaulting to today
8+
# - YEAR -- year defaulting to this year
9+
# - SUFFIX -- suffix for the filename with solution. Don't forget the leading `-`.
10+
#
11+
# Assumes:
12+
# - Y$YEAR/day-N.hs exists with a day solution template
13+
#
14+
# Effects:
15+
# - Creates Y$YEAR/day-$DAY.hs from the template (see Assumes)
16+
# - Adds an executable component day-$DAY to the cabal file of the year
17+
#
18+
19+
: "${YEAR:=$(date +%Y)}"
20+
: "${DAY:=$(date +%-d)}"
21+
# : "${SUFFIX:=}"
22+
DAYFILE="day-$DAY$SUFFIX.hs"
23+
24+
cp "Y$YEAR/day-N.hs" "Y$YEAR/$DAYFILE"
25+
echo -n "
26+
executable day-$DAY
27+
import: base
28+
main-is: $DAYFILE
29+
" >> Y$YEAR/y$YEAR.cabal
30+
31+
wget "https://adventofcode.com/$YEAR/day/$DAY" -O - | ./scripts/extract-html-code.hs > Y$YEAR/input/day-$DAY-small.txt

0 commit comments

Comments
 (0)