generated from jpillora/aoc-in-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·58 lines (52 loc) · 1.13 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -euf -o pipefail
# functions
function echogrey() {
echo -e "\033[0;90m$1\033[0m"
}
function template() {
cat <<EOF
package main
import (
"github.com/jpillora/puzzler/harness/aoc"
)
func main() {
aoc.Harness(run)
}
// on code change, run will be executed 4 times:
// 1. with: false (part1), and example input
// 2. with: true (part2), and example input
// 3. with: false (part1), and user input
// 4. with: true (part2), and user input
// the return value of each run is printed to stdout
func run(part2 bool, input string) any {
// when you're ready to do part 2, remove this "not implemented" block
if part2 {
return "not implemented"
}
// solve part 1 here
return 42
}
EOF
}
# two args YEAR and DAY
YEAR="${1:-}"
DAY="${2:-}"
if [ -z "$YEAR" ] || [ -z "$DAY" ]; then
echo "Usage: $0 <YEAR> <DAY>"
exit 1
fi
# pad DAY to 2 digits
DAY=$(printf "%02d" $DAY)
DIR="./$YEAR/$DAY"
# create missing files as needed
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR"
echogrey "Created directory $DIR"
fi
if [ ! -f "$DIR/code.go" ]; then
template >"$DIR/code.go"
echogrey "Created file code.go"
fi
# go run
cd "$DIR" && go run code.go