Skip to content

Commit cf2f45d

Browse files
committed
Only trim line breaks at the end of input file
The general trim() function trims at the file's start, too. This is a problem when whitespace at the beginning of the first line is essential (as in 2017, day 19's input). Also: Add a line break in the Grid class for better debugging.
1 parent f82370b commit cf2f45d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/main/kotlin/de/ronny_h/aoc/AdventOfCode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class AdventOfCode<T>(val year: Int, val day: Int) {
1818

1919
fun readInput(): List<String> {
2020
val inputFile = "/$year/Day${paddedDay()}.txt"
21-
return AdventOfCode::class.java.getResource(inputFile)?.readText()?.trim()?.lines()
21+
return AdventOfCode::class.java.getResource(inputFile)?.readText()?.trimEnd('\n')?.lines()
2222
?: error("The input file for day $day, year $year could not be found. Expected at '$inputFile' in the resources folder.")
2323
}
2424

src/main/kotlin/de/ronny_h/aoc/extensions/grids/Grid.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ abstract class Grid<T>(
6161
}
6262

6363
protected fun initGrid(input: List<String>) = input.forEachIndexed { row, line ->
64-
line.forEachIndexed { col, char -> grid[row][col] = char.toElementType() }
64+
line.forEachIndexed { col, char ->
65+
grid[row][col] = char.toElementType()
66+
}
6567
}
6668

6769
/**

0 commit comments

Comments
 (0)