Open challenge in browser when generating code for new day

This commit is contained in:
William Brawner 2023-12-16 22:00:28 -07:00
parent ef147fdf0b
commit 4dad375d17
Signed by: wbrawner
GPG key ID: 8FF12381C6C90D35

View file

@ -1,3 +1,6 @@
import java.awt.Desktop
import java.net.URI
plugins { plugins {
kotlin("jvm") version "1.9.21" kotlin("jvm") version "1.9.21"
} }
@ -22,8 +25,8 @@ tasks {
val (prevDayNum) = Regex("Day(\\d\\d)").find(it.name)!!.destructured val (prevDayNum) = Regex("Day(\\d\\d)").find(it.name)!!.destructured
prevDayNum.toInt() prevDayNum.toInt()
} }
val newDayNum = String.format("%02d", prevDayNum + 1) val newDayNum = (prevDayNum + 1).toString()
File("$projectDir/src", "Day$newDayNum.kt").writeText( File("$projectDir/src", "Day${newDayNum.padStart(2, '0')}.kt").writeText(
"""fun main() { """fun main() {
fun part1(input: List<String>): Int { fun part1(input: List<String>): Int {
return input.size return input.size
@ -34,15 +37,18 @@ tasks {
} }
// test if implementation meets criteria from the description, like: // test if implementation meets criteria from the description, like:
val testInput = readInput("Day${newDayNum}_test") val testInput = readInput("Day${newDayNum.padStart(2, '0')}_test")
check(part1(testInput) == 0) check(part1(testInput) == 0)
val input = readInput("Day${newDayNum}") val input = readInput("Day${newDayNum.padStart(2, '0')}")
part1(input).println() part1(input).println()
check(part2(testInput) == 0)
part2(input).println() part2(input).println()
} }
""" """
) )
val challengeUrl = "https://adventofcode.com/2023/day/$newDayNum"
Desktop.getDesktop().browse(URI.create(challengeUrl))
File("$projectDir/src", "Day$newDayNum.txt").createNewFile() File("$projectDir/src", "Day$newDayNum.txt").createNewFile()
File("$projectDir/src", "Day${newDayNum}_test.txt").createNewFile() File("$projectDir/src", "Day${newDayNum}_test.txt").createNewFile()
} }