Skip to content

Commit da00627

Browse files
committed
Solve 2025 day 5 part 2
1 parent 8eb8a82 commit da00627

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/scala/eu/sim642/adventofcode2025/Day5.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package eu.sim642.adventofcode2025
22

3-
import eu.sim642.adventofcode2016.Day20.Interval
3+
import eu.sim642.adventofcode2016.Day20.{Interval, mergeIntervals}
44

55
object Day5 {
66

@@ -11,6 +11,10 @@ object Day5 {
1111
available.count(id => fresh.exists(_.contains(id)))
1212
}
1313

14+
def countFresh(database: Database): Long = {
15+
mergeIntervals(database.fresh).map(_.size).sum
16+
}
17+
1418
def parseInterval(s: String): Interval = s match {
1519
case s"$i-$j" => Interval(i.toLong, j.toLong)
1620
}
@@ -26,5 +30,6 @@ object Day5 {
2630

2731
def main(args: Array[String]): Unit = {
2832
println(countFreshAvailable(parseDatabase(input)))
33+
println(countFresh(parseDatabase(input)))
2934
}
3035
}

src/test/scala/eu/sim642/adventofcode2025/Day5Test.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ class Day5Test extends AnyFunSuite {
2525
test("Part 1 input answer") {
2626
assert(countFreshAvailable(parseDatabase(input)) == 679)
2727
}
28+
29+
test("Part 2 examples") {
30+
assert(countFresh(parseDatabase(exampleInput)) == 14)
31+
}
32+
33+
test("Part 2 input answer") {
34+
assert(countFresh(parseDatabase(input)) == 358155203664116L)
35+
}
2836
}

0 commit comments

Comments
 (0)