Skip to content

Commit 9a63a00

Browse files
committed
refactoring
1 parent b0e18c9 commit 9a63a00

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

README.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,34 @@ After you create a new project based on the current template repository using th
4646
├── Day01.kt An empty implementation for the first AoC day
4747
├── Day01.txt An empty file for the Day 01 input data
4848
├── 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
49+
└── Utils.kt A set of utility methods shared across your days
5050
```
5151

5252
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.
5353
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.
5454

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:
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:
5656

5757
```kotlin
58-
fun part1(input: List<String>): Int {
59-
return input.size
60-
}
61-
6258
fun main() {
59+
fun part1(input: List<String>): Int {
60+
return input.size
61+
}
62+
6363
val input = readInput("Day01")
64-
part1(input).also(::println)
64+
println(part1(input))
6565
}
6666
```
6767

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].
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].
6969

7070
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.
7171
To handle that case, you can put such an input into a separated file and perform a standard assertion against the output, like:
7272

7373
```kotlin
7474
fun main() {
75+
// ...
76+
7577
val testInput = readInput("Day01_test")
7678
assert(part1(testInput) == 13)
7779
}
@@ -82,18 +84,18 @@ The final result of your algorithm will be printed on the screen so that you can
8284
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:
8385

8486
```kotlin
85-
fun part1(input: List<String>): Int {
86-
return 0
87-
}
87+
fun main() {
88+
fun part1(input: List<String>): Int {
89+
return 0
90+
}
8891

89-
fun part2(input: List<String>): Int {
90-
return 0
91-
}
92+
fun part2(input: List<String>): Int {
93+
return 0
94+
}
9295

93-
fun main() {
9496
val input = readInput("Day02")
95-
part1(input).also(::println)
96-
part2(input).also(::println)
97+
println(part1(input))
98+
println(part2(input))
9799
}
98100
```
99101

@@ -114,4 +116,4 @@ If you stuck with Kotlin-specific questions or anything related to this template
114116
[kotlin]: https://kotlinlang.org
115117
[slack]: https://surveys.jetbrains.com/s3/kotlin-slack-sign-up
116118
[file:kotlin]: .github/readme/kotlin.svg
117-
[file:utils]: src/utils.kt
119+
[file:utils]: src/Utils.kt

src/Day01.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
fun part1(input: List<String>): Int {
2-
return input.size
3-
}
1+
fun main() {
2+
fun part1(input: List<String>): Int {
3+
return input.size
4+
}
45

5-
fun part2(input: List<String>): Int {
6-
return input.size
7-
}
6+
fun part2(input: List<String>): Int {
7+
return input.size
8+
}
89

9-
fun main() {
1010
// test if implementation meets criteria from the description, like:
1111
val testInput = readInput("Day01_test")
1212
assert(part1(testInput) == 1)
1313

1414
val input = readInput("Day01")
15-
part1(input).also(::println)
16-
part2(input).also(::println)
15+
println(part1(input))
16+
println(part2(input))
1717
}
File renamed without changes.

0 commit comments

Comments
 (0)