Day 2: Sum calculation in program
This commit is contained in:
1 parent
64b020ff65
commit
a70d9fafee
2 files changed
+8
-6
No files matched your search
@@ -4,7 +4,13 @@ import java.io.File
|
|||||||
|
|
||||||
object Day2 {
|
object Day2 {
|
||||||
|
|
||||||
fun readGames(file: File = File("src/main/resources/day2/input.txt")): List<Game> = file
|
fun sumOfCompatibleGames(hand: Hand) = readGames()
|
||||||
|
.filter { it.isCompatibleWith(hand) }
|
||||||
|
.map(Game::id)
|
||||||
|
.sum()
|
||||||
|
|
||||||
|
private fun readGames(): List<Game> =
|
||||||
|
File("src/main/resources/day2/input.txt")
|
||||||
.readLines()
|
.readLines()
|
||||||
.map(Game.Companion::parse)
|
.map(Game.Companion::parse)
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ class Day2Test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun readGames() {
|
fun readGames() {
|
||||||
val compatibleGames = Day2.readGames().filter { game ->
|
assert(Day2.sumOfCompatibleGames(Hand(12, 13, 14)) == 8)
|
||||||
Hand(12, 13, 14).let(game::isCompatibleWith)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(compatibleGames.map(Game::id).joinToString(separator=",") == "1,2,5")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user