Skip to content

Instantly share code, notes, and snippets.

@theodoreLee
Last active April 20, 2017 07:18
Show Gist options
  • Save theodoreLee/9d0c7ca64cb14e714dae to your computer and use it in GitHub Desktop.
Save theodoreLee/9d0c7ca64cb14e714dae to your computer and use it in GitHub Desktop.
import java.io.FileOutputStream
import scala.io.Source
object IOError {
def solve(seq: Seq[String]) = {
val str = seq(1).replaceAll("I","1").replaceAll("O","0")
str.grouped(8).map(Integer.parseInt(_, 2).toChar).mkString
}
def main(args: Array[String]): Unit = {
val INPUT = "A-small-practice.in"
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out2"
val isConsole = false
val itr = Source.fromFile(INPUT).getLines()
val stream = if (isConsole) Console.out else new FileOutputStream(OUTPUT)
try {
Console.withOut(stream) {
val sets = itr.next().toInt
(1 to sets).foreach { set =>
val seq = Seq(itr.next(),itr.next())
println(f"Case #$set: ${solve(seq)}")
}
}
} finally {
stream.flush()
if (!isConsole) stream.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment