Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. object Main {
  2. def main(args: Array[String]) {
  3. val Array(x, y, z) = args map {_.toInt}
  4. println(tarai_(x, y, z))
  5. // これは遅い
  6. // println(tarai(x, y, z))
  7. }
  8.  
  9. def tarai_(x: => Int, y: => Int, z: => Int): Int =
  10. if (x <= y)
  11. y
  12. else
  13. tarai_(
  14. tarai_(x - 1, y, z),
  15. tarai_(y - 1, z, x),
  16. tarai_(z - 1, x, y)
  17. )
  18.  
  19. def tarai(x: Int, y: Int, z: Int): Int =
  20. if (x <= y)
  21. y
  22. else
  23. tarai(
  24. tarai(x - 1, y, z),
  25. tarai(y - 1, z, x),
  26. tarai(z - 1, x, y)
  27. )
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement