-
-
Save sangkeon/b4d09ec67b02f308fb34b5d554e9d855 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 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