From 4dad375d17362a751a06e9750ef3448f476e21db Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 16 Dec 2023 22:00:28 -0700 Subject: [PATCH] Open challenge in browser when generating code for new day --- build.gradle.kts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 21dee45..80b6762 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +import java.awt.Desktop +import java.net.URI + plugins { kotlin("jvm") version "1.9.21" } @@ -22,8 +25,8 @@ tasks { val (prevDayNum) = Regex("Day(\\d\\d)").find(it.name)!!.destructured prevDayNum.toInt() } - val newDayNum = String.format("%02d", prevDayNum + 1) - File("$projectDir/src", "Day$newDayNum.kt").writeText( + val newDayNum = (prevDayNum + 1).toString() + File("$projectDir/src", "Day${newDayNum.padStart(2, '0')}.kt").writeText( """fun main() { fun part1(input: List): Int { return input.size @@ -34,15 +37,18 @@ tasks { } // 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) - val input = readInput("Day${newDayNum}") + val input = readInput("Day${newDayNum.padStart(2, '0')}") part1(input).println() + check(part2(testInput) == 0) 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}_test.txt").createNewFile() }