fork download
  1. object Main extends App {
  2. def reverseFactorial(n: Float, pow: Int = 0): String = {
  3. n match {
  4. case 1.0 => s" = $pow!"
  5. case x if x < 1.0 => " NONE"
  6. case _ => reverseFactorial(n / (pow + 1), pow + 1)
  7. }
  8. }
  9.  
  10. List(120, 150, 3628800, 479001600, 6, 18)
  11. .map(x => s"$x${reverseFactorial(x)}")
  12. .foreach(println)
  13. }
Success #stdin #stdout 0.15s 322432KB
stdin
Standard input is empty
stdout
120 = 5!
150  NONE
3628800 = 10!
479001600 = 12!
6 = 3!
18  NONE