Skip to content

Instantly share code, notes, and snippets.

@machisuji
Created December 1, 2021 10:23
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 machisuji/7bca405fac2612c5a9575c056204f773 to your computer and use it in GitHub Desktop.
Save machisuji/7bca405fac2612c5a9575c056204f773 to your computer and use it in GitHub Desktop.
Advent of Code - Day 1
def main(args: Array[String]): Unit = {
val data: Seq[Int] = io.Source.fromFile("input.txt").getLines.filter(_.nonEmpty).map(_.toInt).toSeq
def solution(xs: Seq[Int]): Int = xs.sliding(2, 1).count{case Seq(a, b) => b > a}
val part1 = solution(data)
val part2 = solution(data.sliding(3, 1).map(_.sum).toSeq)
println(s"Part 1: $part1")
println(s"Part 2: $part2")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment