-
-
Save krikit/151c6bb6609db47965da 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.{File, PrintWriter} | |
object PowerLevels extends App { | |
def log9000(bang: Int): Int = { | |
(for (k <- 0 to (9000 / bang)) yield { | |
Math.log10(9000 - bang * k) | |
}).sum.ceil.toInt | |
} | |
val numBang = List(0) ++ (1 to 8999).map(log9000(_)) | |
def answer(d: Int): String = { | |
if (d < 4) "..." | |
else { | |
val bang = (numBang.zipWithIndex.filter { x: (Int, Int) => | |
x._1 >= d | |
}).size + 1 | |
"IT'S OVER 9000" + ("!" * bang) | |
} | |
} | |
// main | |
val lines = io.Source.fromFile("C-small-practice.in").getLines() | |
val out = new PrintWriter(new File("C-small-practice.out" )) | |
for (i <- 1 to lines.next.toInt) { | |
out.println(s"Case #${i}: ${answer(lines.next.toInt)}") | |
} | |
out.close | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment