-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuzzle
executable file
·54 lines (47 loc) · 1.4 KB
/
puzzle
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
#!/bin/bash
usage() {
echo "Usage: puzzle <year> <day> [<type1> <type2>]
<year> - 4-digit number denoting the year of the puzzle
<day> - number denoting the day of the puzzle, [1; 31]
<type1> - return type for the solution of the first part of the puzzle, default - Any
<type2> - return type for the solution of the second part of the puzzle, default - Any"
}
getinput() {
local folder=src/main/resources/input/year$YEAR/
if [[ ! -d $folder ]]; then
mkdir "$folder"
fi
if source .secret && [[ -n $SECRET ]]; then
echo "Fetching input data"
curl -H "$SECRET" -A "$UA" https://adventofcode.com/$YEAR/day/$DAY/input > src/main/resources/input/year$YEAR/day$DAY.in
else
echo "Opening input file for editing"
"${EDITOR:-vim}" src/main/resources/input/year$YEAR/day$DAY.in
fi
}
invalidparam() {
echo "$1"
usage
exit 1
}
if [[ -z $1 || -n $1 && -z $2 || -n $3 && -z $4 ]]; then
usage
exit 1
fi
YEAR=$1
DAY=$2
TYPE1=${3:-Any}
TYPE2=${4:-Any}
[[ $YEAR =~ ^[0-9]{4}$ ]] || invalidparam "Invalid year."
[[ $DAY =~ ^[1-9][0-9]?$ ]] || invalidparam "Invalid day."
echo "Creating puzzle for $YEAR, Day $DAY..."
source tools/createpuzzlefile
createpuzzlefile $YEAR $DAY $TYPE1 $TYPE2
if [[ $? -eq 0 ]]; then
source tools/createrunconfig
getinput
source tools/createtestfiles
createtestfile $YEAR $DAY $TYPE1 $TYPE2
createrunconfig $YEAR $DAY
echo "All done! Happy coding!"
fi