-
-
Save waynejo/e8dd7546cc4104831cc2fe49f8ad8305 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
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