You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Welcome to the Advent of Code[^aoc] Kotlin project created by [%NAME%][github] using the [Advent of Code Kotlin Template][template] delivered by JetBrains.
│ │ ├── Day.kt Base class for Day* implementations
50
-
│ │ ├── Day01.kt An empty implementation for the first AoC day
51
-
│ │ └── utils
52
-
│ │ ├── Resources.kt Utility class for loading input txt files
53
-
│ │ └── utils.kt A set of utility methods shared across your classes
54
-
│ └── resources
55
-
│ └── day01.txt An empty file for the Day 01 input data
56
-
└── test
57
-
└── kotlin
58
-
└── com.github.you.project
59
-
├── DayTest.kt Base test class
60
-
└── Day01Test.kt Class to test your implementation against test data
46
+
├── Day01.kt An empty implementation for the first AoC day
47
+
├── Day01.txt An empty file for the Day 01 input data
48
+
├── Day01_test.txt An optional Day 01 test input data used for assertion
49
+
└── utils.kt A set of utility methods shared across your days
61
50
```
62
51
63
-
After the first puzzle appears, go to the `Day01.kt` and for each `part1` and `part2`classes, provide an algorithm implementation using the provided `input` data loaded from the `day01.txt` file.
52
+
When the first puzzle appears, go to the `Day01.kt` and for each `part1` and `part2`functions, provide an algorithm implementation using the `input` data loaded from the `src/Day01.txt` file.
64
53
This input data is common for both parts, and you can find it on the bottom of each day on the [Advent of Code][aoc] page.
65
54
66
-
To read the input data as a list of strings, you can go with the `String.ints()` utility method provided in the [`utils.kt`][file:utils] file, like:
55
+
To read the input data, you can go with the `readInput(name: String)` utility method provided in the [`utils.kt`][file:utils] file, like:
67
56
68
57
```kotlin
69
-
classDay01 : Day(1) {
70
-
71
-
overridefunpart1(input:String): Int {
72
-
return input.ints().sum()
73
-
}
58
+
funpart1(input:List<String>): Int {
59
+
return input.size
60
+
}
74
61
75
-
// ...
62
+
funmain() {
63
+
val input = readInput("Day01")
64
+
part1(input).also(::println)
76
65
}
77
66
```
78
67
79
-
This file also contains the `String.md5()` method for generating MD5 has out of the given string and expects more helper functions for the sake of the [KISS principle][kiss].
80
-
81
-
To check if everything works as expected during the development, you can use the test data and answers within each day's story and provide them for your `DayTest` test implementation.
82
-
You may want to run such a test case by clicking the _Test All Days_ Run/Debug Configuration provided in the top-right toolbar or check the test result for each day separately.
68
+
The [`utils.kt`][file:utils] file also contains the `String.md5()` method for generating MD5 has out of the given string and expects more helper functions for the sake of the [KISS principle][kiss].
83
69
84
-
To go with the next day, place the `day02.txt` file into the `resources` with relevant input data, create `Day02.kt` file with the class implementation:
70
+
Each puzzle describes some test conditions, a small portion of the information that helps check if the produced value for the given test input is valid.
71
+
To handle that case, you can put such an input into a separated file and perform a standard assertion against the output, like:
85
72
86
73
```kotlin
87
-
classDay02 : Day(2) {
88
-
// ...
74
+
funmain() {
75
+
val testInput = readInput("Day01_test")
76
+
assert(part1(testInput) ==13)
89
77
}
90
78
```
91
79
92
-
Then just provide tests for the second day in a similar manner:
80
+
The final result of your algorithm will be printed on the screen so that you can pass it to the Advent of Code website.
81
+
82
+
To go with the next day, place the `Day02.txt` file into the `src` with relevant input data and create `Day02.kt` file with a similar code scaffold:
93
83
94
84
```kotlin
95
-
classDay02Test : DayTest() {
96
-
97
-
overrideval day =Day02()
85
+
funpart1(input:List<String>): Int {
86
+
return0
87
+
}
98
88
99
-
@Test
100
-
overridefun`Part 1`() {
101
-
assertEquals(0, day.part1("test_input")) // check against test input
102
-
assertEquals(0, day.part1()) // check solution against input data
103
-
}
89
+
funpart2(input:List<String>): Int {
90
+
return0
91
+
}
104
92
105
-
// ...
93
+
funmain() {
94
+
val input = readInput("Day02")
95
+
part1(input).also(::println)
96
+
part2(input).also(::println)
106
97
}
107
98
```
108
99
@@ -123,4 +114,4 @@ If you stuck with Kotlin-specific questions or anything related to this template
0 commit comments