diff --git a/src/main/kotlin/AdventOfCode2023/day4/Scratchcards.kt b/src/main/kotlin/AdventOfCode2023/day4/Scratchcards.kt index bfeec2e..6786fa7 100644 --- a/src/main/kotlin/AdventOfCode2023/day4/Scratchcards.kt +++ b/src/main/kotlin/AdventOfCode2023/day4/Scratchcards.kt @@ -3,7 +3,7 @@ package AdventOfCode2023.day4 import AdventOfCode.Puzzle import kotlin.collections.ArrayDeque -data class Card(val number: Int, val data: String) +data class Card(val number: Int, val wonCards: Int) class Scratchcards : Puzzle("2023", "4") { override fun partOne() { @@ -26,14 +26,13 @@ class Scratchcards : Puzzle("2023", "4") { override fun partTwo() { var cardsTotal = 0 - val cardsList = inputData.mapIndexed { index, s -> Card(index + 1, s) }.toList() + val cardsList = inputData.mapIndexed { index, s -> Card(index + 1, getWinningNumbersForCard(s)) }.toList() val stack = ArrayDeque(cardsList) while (!stack.isEmpty()) { val card = stack.removeFirst() - val wonCards = getWinningNumbersForCard(card) - if (wonCards > 0) { - val wonCardsList = cardsList.slice(card.number.. 0) { + val wonCardsList = cardsList.slice(card.number.. cleanParts.contains(number) }.count() diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 98a29e8..63dc290 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,7 +1,11 @@ import AdventOfCode2023.day4.Scratchcards +import kotlin.system.measureTimeMillis fun main(args: Array) { val t = Scratchcards() // t.partOne() - t.partTwo() + val time = measureTimeMillis { + t.partTwo() + } + println("Took $time ms.") } \ No newline at end of file