fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int count = 0;
  11. static int maxDepth = 0;
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. for (int i = 1; i <= 7; i++)
  15. call(i);
  16.  
  17. }
  18.  
  19. static void call(int n) {
  20. count = 0;
  21. System.out.println("-------------");
  22. System.out.printf("tarai(%d,0,%d)%n",n,n+1);
  23. System.out.println(tarai(n,0,n+1,1));
  24. System.out.println("count: " + count);
  25. System.out.println("depth: " + maxDepth);
  26. }
  27.  
  28. static int tarai(int x, int y, int z, int d) {
  29. count++;
  30. if (x <= y) {
  31. maxDepth = Math.max(maxDepth, d);
  32. return y;
  33. } else {
  34. return tarai(tarai(x-1,y,z,d+1),tarai(y-1,z,x,d+1),tarai(z-1,x,y,d+1),d+1);
  35. }
  36. }
  37. }
Success #stdin #stdout 0.16s 34768KB
stdin
Standard input is empty
stdout
-------------
tarai(1,0,2)
2
count: 5
depth: 2
-------------
tarai(2,0,3)
3
count: 17
depth: 5
-------------
tarai(3,0,4)
4
count: 57
depth: 9
-------------
tarai(4,0,5)
5
count: 213
depth: 14
-------------
tarai(5,0,6)
6
count: 893
depth: 20
-------------
tarai(6,0,7)
7
count: 4137
depth: 27
-------------
tarai(7,0,8)
8
count: 20885
depth: 35