Skip to content

Instantly share code, notes, and snippets.

@seoh
Created September 4, 2015 11:41
Show Gist options
  • Save seoh/66a45fa53a35e405b22b to your computer and use it in GitHub Desktop.
Save seoh/66a45fa53a35e405b22b to your computer and use it in GitHub Desktop.
import java.io.{PrintWriter, File}
/**
* Created by seoh on 04/09/2015.
*/
object Main {
def decode(str: String): String =
str.grouped(8).map(_.reverse.zipWithIndex).map(v =>
v.map({
case ('I', i) => math.pow(2, i)
case _ => 0
}).sum.toChar
).mkString
def main(args: Array[String]) {
val lines = io.Source.fromFile("A-small-practice.in").getLines()
val count = lines.next.toInt
val result = lines.grouped(2).map(_(1)).zipWithIndex.map({
case (str, i) => s"Case #${i+1}: ${decode(str)}"
})
val out = new PrintWriter(new File("A-small-practice.out" ))
out.write(result.mkString("\n"))
out.close
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment