generated from kotlin-hands-on/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·110 lines (78 loc) · 3.28 KB
/
generate
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
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
# This script is used to generate files for a new Advent of Code day.
# Require a year number and day number as an argument.
if [ $# -ne 2 ]; then
echo "Usage: $0 <year> <day>"
exit 1
fi
# It takes two arguments, the year number and the day number.
year=$1
day=$2
# pad day number with leading zero
padded_day=$(printf "%02d" "$day")
# It creates the folder "solutions/src/main/kotlin/fr/triozer/aoc/y$year" if it doesn't exist.
mkdir -p "solutions/src/main/kotlin/fr/triozer/aoc/y$year"
# If the file "solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$1.kt" already exists return an error
if [ -f "solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt" ]; then
echo "Error: $year Day $padded_day already exists"
exit 1
fi
# Then it creates the blog folder is it doesn't exist.
mkdir -p "blog/docs/$year"
# Then it touch the file "blog/docs/$year/index.md" if it doesn't exist.
if [ ! -f "blog/docs/$year/index.md" ]; then
touch "blog/docs/$year/index.md"
fi
# Then it create a file "day-$1.md" in the directory "blog/docs/"
cat <<EOF > blog/docs/"$year"/day-"$padded_day".md
# [Day $padded_day](https://adventofcode.com/$year/day/$day)
## Introduction
Explain briefly the challenge here.
### Input
<<< @/../../solutions/src/main/resources/$year/day$day/test.in{txt}
### Other
::: details Click to view other
<<< @/../../solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt#other{kotlin}
:::
## Part 1
<<< @/../../solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt#part1{kotlin}
## Part 2
<<< @/../../solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt#part2{kotlin}
## Conclusion
Lorem impsun dolor sit amet.
Difficulty: ⭐️ / ⭐️⭐️⭐️⭐️⭐️\\
Source
code: [Day$padded_day.kt](https://github.com/triozer/aoc-2022/blob/main/solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt)
EOF
echo "Created article post: blog/docs/$year/day-$padded_day.md"
# Then it creates a file "Day$1.kt" in the directory "solutions/src/main/kotlin/fr/triozer/aoc/y$year"
cat <<EOF > solutions/src/main/kotlin/fr/triozer/aoc/y"$year"/Day"$padded_day".kt
package fr.triozer.aoc.y$year
import fr.triozer.aoc.utils.readInput
// #region other
// #endregion other
// #region part1
private fun part1(input: List<String>) = 0
// #endregion part1
// #region part2
private fun part2(input: List<String>) = 0
// #endregion part2
private fun main() {
val testInput = readInput($year, $day, "test")
check(part1(testInput) == 0)
check(part2(testInput) == 0)
println("Checks passed ✅")
val input = readInput($year, $day, "input")
println(part1(input))
println(part2(input))
}
EOF
echo "Created solution file: solutions/src/main/kotlin/fr/triozer/aoc/y$year/Day$padded_day.kt"
# And it creates two files "input.in" and "test.in" in the directory "solutions/src/resources/$year/day$1"
mkdir -p solutions/src/main/resources/"$year"/day"$day"
touch solutions/src/main/resources/"$year"/day"$day"/input.in
echo "Created input file: solutions/src/main/resources/$year/day$day/input.in"
touch solutions/src/main/resources/"$year"/day"$day"/test.in
echo "Created test file: solutions/src/main/resources/$year/day$day/test.in"
# Touch the blog config file to trigger a rebuild in dev
touch blog/docs/.vitepress/config.js