-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-source.sh
More file actions
executable file
·100 lines (81 loc) · 1.68 KB
/
create-source.sh
File metadata and controls
executable file
·100 lines (81 loc) · 1.68 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Common functions
function real_base_name () {
target=$1
(
while true; do
cd "$(dirname "$target")"
target=$(basename "$target")
link=$(readlink "$target")
test "$link" || break
target=$link
done
echo "$(pwd -P)"
)
}
function output () {
echo "$@"
}
function output_error () {
>&2 echo "$@"
}
function fail () {
>&2 echo "$@"
exit 1
}
function usage {
output_error "Usage: $BASH_SOURCE [--year <YEAR> --day <DAY>]"
output_error "--year: Year, defaults to current"
output_error "--day: Day, defaults to current"
exit 1
}
YEAR="$(date +"%Y")"
DAY="$(date +"%-d")"
TOKEN="$AOC_SESSION_TOKEN"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help)
usage
;;
--day)
shift
DAY="$1"
;;
--year)
shift
YEAR="$1"
;;
*)
output_error "Unknown option: $key"
usage
;;
esac
shift # past argument or value
done
SCRIPT_DIR=$(real_base_name "$0")
cd "$SCRIPT_DIR"
mkdir -p "./src/main/kotlin/com/behindmedia/adventofcode/year${YEAR}/day${DAY}"
FILE="./src/main/kotlin/com/behindmedia/adventofcode/year${YEAR}/day${DAY}/Day${DAY}.kt"
if [ -f "$FILE" ]; then
fail "File $FILE already exists"
fi
cat > "$FILE" << EOF
package com.behindmedia.adventofcode.year${YEAR}.day${DAY}
import com.behindmedia.adventofcode.common.*
import kotlin.math.*
private fun solve(fileName: String, part: Int) {
val data = parseLines("/${YEAR}/" + fileName) { line ->
line
}
println(data)
}
fun main() {
for (part in 1..2) {
solve("day${DAY}-sample1.txt", part)
solve("day${DAY}.txt", part)
}
}
EOF
output "Wrote file $FILE"