Skip to content

Instantly share code, notes, and snippets.

@theodoreLee
Created September 18, 2015 12:15
Show Gist options
  • Save theodoreLee/f4defd0d9efb0dab0774 to your computer and use it in GitHub Desktop.
Save theodoreLee/f4defd0d9efb0dab0774 to your computer and use it in GitHub Desktop.
import java.io.FileOutputStream
import scala.io.Source
object PowerLevels {
def multifactorialArray:Array[Int] = {
Array.tabulate(9000) {i =>
Math.ceil((9000 until 1 by -(i+1)).map(Math.log10(_)).sum).toInt
}
}
def solve(digits:Int, array:Array[Int]) = {
val factorial = array.indexWhere(digits > _) + 1
if(factorial == 0) "..."
else "IT'S OVER 9000"+"!"*factorial
}
def main(args: Array[String]): Unit = {
val INPUT = "C-large-practice.in"
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out"
val isConsole = false
val itr = Source.fromFile(INPUT).getLines()
val stream = if (isConsole) Console.out else new FileOutputStream(OUTPUT)
try {
Console.withOut(stream) {
val array = multifactorialArray
val sets = itr.next().toInt
(1 to sets).foreach { set =>
println(f"Case #$set: ${solve(itr.next().toInt, array:Array[Int])}")
}
}
} 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