fork(3) download
  1. class Ideone{
  2. int a(int n){if(n<2)return 0;int f=a(n-1),b,i,c;do{f++;for(b=1,i=1;i<n;i++)for(c=i==2?4:a(i);c>1;c=c%2>0?c*3+1:c/2)b=c==f?0:b;}while(b<1);return f;}
  3. public static void main (String[] args){
  4. for(int i=1;i<10;i++){
  5. System.out.println(i+" -> "+new Ideone().a(i));
  6. }
  7. }
  8. }
Success #stdin #stdout 0.05s 320576KB
stdin
Standard input is empty
stdout
1 -> 0
2 -> 1
3 -> 3
4 -> 6
5 -> 7
6 -> 9
7 -> 12
8 -> 15
9 -> 18