Day 1 part 1 complete - slight refactor
This commit is contained in:
parent
da70cebc2d
commit
07594c5d9a
1 changed files with 5 additions and 1 deletions
|
@ -7,10 +7,14 @@ import java.util.stream.Collectors
|
|||
class Day1 {
|
||||
fun run(inputFile: Path): Long {
|
||||
return loadFile(inputFile).parallelStream()
|
||||
.map { it.toLong().div(3).minus(2) }
|
||||
.map {calculateCost(it)}
|
||||
.collect(Collectors.summingLong { it } )
|
||||
}
|
||||
|
||||
private fun calculateCost(x: String): Long {
|
||||
return x.toLong().div(3).minus(2)
|
||||
}
|
||||
|
||||
private fun loadFile(inputFile: Path): List<String> {
|
||||
return Files.readAllLines(inputFile)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue