Skip to content

Commit c6e8173

Browse files
committed
Add 2022 boilerplate based on 2015
1 parent 7977685 commit c6e8173

15 files changed

+590
-0
lines changed

2015/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Advent of Code 2025
2+
My solutions to the [Advent of Code 2015](https://adventofcode.com/2015) puzzles.
3+
4+
## Test
5+
6+
Run test in IDE or invoke command:
7+
8+
```sh
9+
gradle test --tests Day<padded day number>Test --info
10+
11+
# Example
12+
gradle test --tests Day01Test --info
13+
```
14+
15+
## Create new day boilerplate
16+
17+
```sh
18+
gradle addDay -Pday=<day number>
19+
20+
# Example
21+
gradle addDay -Pday=1
22+
```

2022/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gradle
2+
.idea
3+
*.iml
4+
build

2022/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Advent of Code 2025
2+
My solutions to the [Advent of Code 2015](https://adventofcode.com/2015) puzzles.
3+
4+
## Test
5+
6+
Run test in IDE or invoke command:
7+
8+
```sh
9+
gradle test --tests Day<padded day number>Test --info
10+
11+
# Example
12+
gradle test --tests Day01Test --info
13+
```
14+
15+
## Create new day boilerplate
16+
17+
```sh
18+
gradle addDay -Pday=<day number>
19+
20+
# Example
21+
gradle addDay -Pday=1
22+
```

2022/build.gradle.kts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import org.gradle.configurationcache.extensions.capitalized
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
kotlin("jvm") version "1.7.20"
6+
application
7+
}
8+
9+
group = "nl.justinform"
10+
version = "1.0-SNAPSHOT"
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
implementation(gradleApi())
18+
testImplementation(kotlin("test"))
19+
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
20+
}
21+
22+
tasks.test {
23+
useJUnitPlatform()
24+
}
25+
26+
tasks.withType<KotlinCompile> {
27+
kotlinOptions.jvmTarget = "16"
28+
}
29+
30+
application {
31+
mainClass.set("MainKt")
32+
}
33+
34+
// Add new day template task
35+
36+
val day: String by project
37+
38+
task("addDay") {
39+
doFirst {
40+
if (!project.hasProperty("day")) {
41+
error("Missing required argument 'day'")
42+
}
43+
44+
val paddedDay = day.padStart(2, '0')
45+
println("Create Day$paddedDay")
46+
47+
createFile(
48+
"src/main/kotlin/day$paddedDay/Day$paddedDay.kt",
49+
"""
50+
package day$paddedDay
51+
52+
class Day$paddedDay {
53+
54+
companion object {
55+
56+
fun part1(input: List<String>): Int {
57+
TODO("IMPLEMENT")
58+
}
59+
60+
fun part2(input: List<String>): Int {
61+
TODO("IMPLEMENT")
62+
}
63+
}
64+
}
65+
""".trimIndent()
66+
)
67+
68+
createFile(
69+
"src/test/resources/day$paddedDay.txt",
70+
"Replace with day$paddedDay puzzle input"
71+
)
72+
73+
createFile(
74+
"src/test/kotlin/Day${paddedDay}Test.kt",
75+
"""
76+
import day$paddedDay.Day$paddedDay
77+
import org.junit.jupiter.api.Test
78+
79+
import org.junit.jupiter.api.Assertions.*
80+
import org.junit.jupiter.params.ParameterizedTest
81+
import org.junit.jupiter.params.provider.CsvSource
82+
83+
internal class Day${paddedDay}Test {
84+
85+
@ParameterizedTest
86+
@CsvSource(
87+
"input, 0",
88+
)
89+
fun `part1 examples`(input: String, expectedResult: Int) {
90+
assertEquals(expectedResult, Day$paddedDay.part1(listOf(input)))
91+
}
92+
93+
@Test
94+
fun `part1 puzzel input`() {
95+
val input = Resource.readFileLines("day$paddedDay")
96+
assertEquals(0, Day$paddedDay.part1(input))
97+
}
98+
99+
@ParameterizedTest
100+
@CsvSource(
101+
"input, 0",
102+
)
103+
fun `part2 examples`(input: String, expectedResult: Int) {
104+
assertEquals(expectedResult, Day$paddedDay.part2(listOf(input)))
105+
}
106+
107+
@Test
108+
fun `part2 puzzel input`() {
109+
val input = Resource.readFileLines("day$paddedDay")
110+
assertEquals(0, Day$paddedDay.part2(input))
111+
}
112+
}
113+
""".trimIndent()
114+
)
115+
}
116+
}
117+
118+
fun createFile(path: String, content: String) {
119+
val file = File(path)
120+
file.parentFile.mkdirs()
121+
122+
// Create and check new file
123+
val isNewFileCreated :Boolean = file.createNewFile()
124+
125+
if(!isNewFileCreated){
126+
error("$file already exists.")
127+
}
128+
129+
file.writeText(content)
130+
}

2022/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official
58.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)