-
-
Save seoh/66a45fa53a35e405b22b 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.{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