We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c1fa297 commit 54c9ef1Copy full SHA for 54c9ef1
adventofcode2023/Day04.kt
@@ -0,0 +1,23 @@
1
+package adventofcode2023
2
+
3
+import java.io.File
4
+import kotlin.math.pow
5
6
+object Day04 {
7
+ fun part1(inputs: List<String>) {
8
+ println(inputs.sumOf { line ->
9
+ val numbers = line.split(": ")[1].split(" | ")
10
+ val winningNumbers = numbers[0].split(" ").filter { it != "" }
11
+ val actualNumbers = numbers[1].split(" ").filter { it != "" }
12
+ val correctNumbersCount = actualNumbers.count { winningNumbers.contains(it) }
13
14
+ if (correctNumbersCount == 0) 0
15
+ else 2.0.pow(correctNumbersCount - 1).toInt()
16
+ })
17
+ }
18
+}
19
20
+fun main() {
21
+ val inputs = File("resources/adventofcode2023/Day04.txt").readLines()
22
+ Day04.part1(inputs)
23
0 commit comments