Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created December 31, 2021 11:26
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 waynejo/e8dd7546cc4104831cc2fe49f8ad8305 to your computer and use it in GitHub Desktop.
Save waynejo/e8dd7546cc4104831cc2fe49f8ad8305 to your computer and use it in GitHub Desktop.
import java.io.FileInputStream
import scala.annotation.tailrec
import scala.io.StdIn
def solve1_1(inputs: Vector[Int]): Int = {
inputs.sliding(2).count(v => v(0) < v(1))
}
def solve1_2(inputs: Vector[Int]): Int = {
solve1_1(inputs.sliding(3).map(_.sum).toVector)
}
@main def solve1(): Unit =
val in = new FileInputStream("example1-2.in")
System.setIn(in)
val inputs = Iterator.continually(StdIn.readLine())
.takeWhile(line => null != line && line.trim.nonEmpty)
.map(_.toInt)
.toVector
println(solve1_1(inputs))
println(solve1_2(inputs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment