-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem
More file actions
executable file
·55 lines (47 loc) · 1.42 KB
/
problem
File metadata and controls
executable file
·55 lines (47 loc) · 1.42 KB
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
#!/bin/bash
usage() {
echo "Usage: problem <year> <day> [<type1> <type2>]
<year> - 4-digit number denoting the year of the problem
<day> - number denoting the day of the problem, [1; 31]
<type1> - return type for the solution of the first part of the problem, default - Any
<type2> - return type for the solution of the second part of the problem, default - Any"
}
getinput() {
local folder=input/$YEAR/main/
if [[ ! -d $folder ]]; then
mkdir -p "$folder"
fi
if [[ -f $folder/input$DAY.in ]] && [[ -s $folder/input$DAY.in ]]; then
echo "Input already exists; skipping..."
elif [[ -f .secret ]]; then
echo "Fetching input data"
curl -b session="$(cat .secret)" https://adventofcode.com/"$YEAR"/day/"$DAY"/input > "$folder"/input"$DAY".in
else
echo "Opening input file for editing"
"${EDITOR:-vim}" "$folder"/input"$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 problem for Year $YEAR, Day $DAY..."
source tools/createproblemfile
createproblemfile "$YEAR" "$DAY" "$TYPE1" "$TYPE2"
if [[ $? -eq 0 ]]; then
getinput
source tools/createtestfiles
createtestfile "$YEAR" "$DAY" "$TYPE1" "$TYPE2"
echo "All done! Happy coding!"
fi