🎄Advent of Code - Day 6 part 2

This commit is contained in:
Denis-Cosmin NUTIU 2023-12-06 12:30:29 +02:00
parent 4d189a1a28
commit 09d89a9562

View file

@ -31,8 +31,7 @@ class WaitForIt : Puzzle("2023", "6") {
override fun partTwo() {
listOf(Race(49787980, 298118510661181)).map {
// here we transform a race into a list of all the possible combinations that we can have
(1..<it.raceTime).toList().parallelStream().map { time -> Race((it.raceTime - time)* time, it.distance) }.collect(
Collectors.toList())
(1..<it.raceTime).map { time -> Race((it.raceTime - time)* time, it.distance) }
}.map {
// Here we filter out the losing races
it.parallelStream().filter { it.raceTime > it.distance }.count()