Skip to content

Instantly share code, notes, and snippets.

@waynejo
Last active April 22, 2016 12:16
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 waynejo/87f14cc1e45c91d950a4dcfb525d1019 to your computer and use it in GitHub Desktop.
Save waynejo/87f14cc1e45c91d950a4dcfb525d1019 to your computer and use it in GitHub Desktop.
import java.io.FileOutputStream
import java.io.FileInputStream
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("example.in"))
Console.setIn(new FileInputStream("A-small-attempt0.in"))
Console.setOut(new FileOutputStream("A-small-attempt0.out"))
Console.setIn(new FileInputStream("A-large-practice.in"))
Console.setOut(new FileOutputStream("A-large-practice.out"))
def solve(n:Int): Option[Long] = n match {
case 0 => None
case _ => Stream.iterate((0, Set[Char]())){
case (v, chars) => (v + n, chars ++ (v + n).toString)
}.find(_._2.size == 10).map(_._1)
}
val cases = StdIn.readLine().toInt
(1 to cases) foreach { i => {
val input = StdIn.readLine().toInt
println(s"Case #$i: ${solve(input).map(_.toString).getOrElse("INSOMNIA")}")
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment