day1
This commit is contained in:
parent
9017c4379c
commit
a9ec0217b1
3 changed files with 2022 additions and 1 deletions
|
@ -3,4 +3,15 @@ package de.qwertyuiop.aoc.`2021`
|
|||
import de.qwertyuiop.aoc.lib.*
|
||||
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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue