Skip to content

Commit 6975a06

Browse files
authored
Add gradle task to generate next day
From kotlin-hands-on/advent-of-code-kotlin-template#17
1 parent c6c876b commit 6975a06

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

build.gradle.kts

+30
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,33 @@ tasks {
1313
gradleVersion = "8.5"
1414
}
1515
}
16+
17+
task("generateNextDay") {
18+
doLast {
19+
val prevDayNum = fileTree("$projectDir/src").matching {
20+
include("Day*.kt")
21+
}.maxOf {
22+
val (prevDayNum) = Regex("Day(\\d\\d)").find(it.name)!!.destructured
23+
prevDayNum.toInt()
24+
}
25+
val newDayNum = String.format("%02d", prevDayNum + 1)
26+
File("$projectDir/src", "Day$newDayNum.kt").writeText(
27+
"""
28+
fun main() {
29+
fun part1(input: List<String>): Int {
30+
return 0
31+
}
32+
fun part2(input: List<String>): Int {
33+
return 0
34+
}
35+
// test if implementation meets criteria from the description, like:
36+
val testInput = readInput("resources/Day${newDayNum}_test")
37+
check(part1(testInput) == 0)
38+
val input = readInput("resources/Day$newDayNum")
39+
println(part1(input))
40+
println(part2(input))
41+
}
42+
"""
43+
)
44+
}
45+
}

0 commit comments

Comments
 (0)