From 12b957a64d0764105bc5b01b6d7b335ca54a3162 Mon Sep 17 00:00:00 2001 From: dnutiu Date: Mon, 4 Dec 2023 18:24:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=84Advent=20of=20Code=20-=20Day=204=20?= =?UTF-8?q?=E2=9C=A8=20part=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/AdventOfCode2023/day4/Scratchcards.kt | 13 ++++++------- src/main/kotlin/Main.kt | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) 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