fork(1) 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,%d,0)%n",2*n,n);
  23. System.out.println(tarai(2*n,n,0,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 1.56s 35304KB
stdin
Standard input is empty
stdout
-------------
tarai(2,1,0)
2
count: 9
depth: 3
-------------
tarai(4,2,0)
4
count: 53
depth: 8
-------------
tarai(6,3,0)
6
count: 673
depth: 18
-------------
tarai(8,4,0)
8
count: 12605
depth: 32
-------------
tarai(10,5,0)
10
count: 343073
depth: 50
-------------
tarai(12,6,0)
12
count: 12604861
depth: 72
-------------
tarai(14,7,0)
14
count: 588802013
depth: 98