Day 2: Sum calculation in program

This commit is contained in:
jeremy committed 2023-12-03 00:41:30 +01:00
1 parent 64b020ff65
commit a70d9fafee
2 files changed
+10 -8

No files matched your search

+9 -3
View File
@@ -4,9 +4,15 @@ 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()
.readLines() .filter { it.isCompatibleWith(hand) }
.map(Game.Companion::parse) .map(Game::id)
.sum()
private fun readGames(): List<Game> =
File("src/main/resources/day2/input.txt")
.readLines()
.map(Game.Companion::parse)
} }
+1 -5
View File
@@ -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")
} }
} }