Created
December 1, 2021 10:23
-
-
Save machisuji/7bca405fac2612c5a9575c056204f773 to your computer and use it in GitHub Desktop.
Advent of Code - Day 1
This file contains hidden or 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
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