Skip to content

Instantly share code, notes, and snippets.

@sungkmi
Created December 31, 2021 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sungkmi/c757adde2b0dd8ea9eca3967b89708cd to your computer and use it in GitHub Desktop.
Save sungkmi/c757adde2b0dd8ea9eca3967b89708cd to your computer and use it in GitHub Desktop.
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 = ...
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