day1
This commit is contained in:
parent
9017c4379c
commit
a9ec0217b1
10
input/2021/day1-sample1.txt
Normal file
10
input/2021/day1-sample1.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
2000
input/2021/day1.txt
Normal file
2000
input/2021/day1.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue