This commit is contained in:
Alexander Gehrke 2021-12-02 23:35:42 +01:00
parent 9017c4379c
commit a9ec0217b1
3 changed files with 2022 additions and 1 deletions

View file

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

2000
input/2021/day1.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,4 +3,15 @@ package de.qwertyuiop.aoc.`2021`
import de.qwertyuiop.aoc.lib.* import de.qwertyuiop.aoc.lib.*
import cats.*, cats.implicits.given import cats.*, cats.implicits.given
def day1(using InputSource): Unit = ??? def day1(using InputSource): Unit =
val numbers = input(_.toInt)
println(countIncreases(numbers))
println(countIncreasesSmoothed(numbers, 3))
/* part 1 */
def countIncreases(input: List[Int]): Int = input.sliding(2).count(l => l(0) < l(1))
/* part 2 */
def countIncreasesSmoothed(input: List[Int], smoothingWindow: Int) =
countIncreases(input.sliding(smoothingWindow).map(_.sum).toList)