Skip to content

Instantly share code, notes, and snippets.

@sangkeon
Created January 8, 2021 12:38
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 sangkeon/b4d09ec67b02f308fb34b5d554e9d855 to your computer and use it in GitHub Desktop.
Save sangkeon/b4d09ec67b02f308fb34b5d554e9d855 to your computer and use it in GitHub Desktop.
import scala.io.Source;
object Main {
def main(args: Array[String]): Unit = {
val lines = Source.fromFile("input.txt").getLines
val ids = lines.map(x=> Integer.parseInt(transform(x), 2) )
val seatIds = ids.toList.sorted
val highest = seatIds.last
val seat = seatIds.sliding(2).toList.filter(xs => xs(1) - xs(0) == 2).head(0) + 1
println (highest)
println (seat)
}
def transform(seat : String) : String = {
seat map charToNum
}
def charToNum(c: Char) : Char = {
c match {
case 'B' => '1'
case 'R' => '1'
case _ => '0'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment