Skip to content

Commit 54c9ef1

Browse files
committed
Add 2023 Day 04 Part 1 solution
1 parent c1fa297 commit 54c9ef1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

adventofcode2023/Day04.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy