Created
December 31, 2021 11:49
-
-
Save sungkmi/c757adde2b0dd8ea9eca3967b89708cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lascala.aoc2021.day1_10.day1 | |
def countDeeper(depths: Seq[Int]): Int = | |
depths.init zip depths.tail count { case (a, b) => a < b } | |
def countDeeperWindoes(depths: Seq[Int]): Int = | |
val windows = depths.sliding(3, 1).map(_.sum).toSeq | |
countDeeper(windows) | |
def depths(s: String): Seq[Int] = s.split("\n").map(_.toInt) | |
def solve1(s: String): Int = | |
countDeeper(depths(s)) | |
def solve2(s: String): Int = | |
countDeeperWindoes(depths(s)) | |
@main def part1: Unit = | |
val ans = solve1(input) | |
println(ans) | |
@main def part2: Unit = | |
val ans = solve2(input) | |
println(ans) | |
//val input = ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lascala.aoc2021.day1_10.day1 | |
import minitest.SimpleTestSuite | |
import hedgehog.minitest.HedgehogSupport | |
import hedgehog.* | |
object Day1Test extends SimpleTestSuite with HedgehogSupport: | |
val depths: Seq[Int] = """199 | |
200 | |
208 | |
210 | |
200 | |
207 | |
240 | |
269 | |
260 | |
263""".split("\n").map(_.toInt).toSeq | |
example("day1 - countDeeper") { | |
countDeeper(depths) ==== 7 | |
} | |
example("day1 - countDeeperWindoes") { | |
countDeeperWindoes(depths) ==== 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment