Go: // AOJ Collatz's Problem :http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0158

package main

import (
	"fmt"
)

func main() {
	for {
		var n int

		fmt.Scanf("%d", &n)

		if n == 0 {
			break
		}

		count := 0
		for n != 1 {
			if n%2 == 0 {
				n /= 2
			} else {
				n = n*3 + 1
			}
			count++
		}
		fmt.Println(count)
	}
}

C++: #include<iostream>
using namespace std;

int main(){

	int n, cnt;
	
	while(cin >> n){
		if(n == 0) break;
		cnt = 0;
		
		if(n == 1){
			cout << '0' << endl;
			continue;
		} 
		
		while(1){
			if(n % 2 == 0) n /= 2;
			else n = 3 * n + 1;
			cnt++;
			if(n == 1) break;
		}
		
		cout << cnt << endl;
	}

	return 0;

}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e9;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号


int main(){
	long n;
	while(cin>>n){
		if(n==0)break;
		long cnt=0;
		while(n!=1){
			if(n%2==0)n/=2;
			else n=n*3+1;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		int co=0;
		while(n!=1){
			if(n%2)n=n*3+1;
			else n/=2;
			co++;
		}
		cout<<co<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int in;
  while(cin>>in,in){
    int co=0;
    while(in!=1){
      co++;
      if(in%2)in=in*3+1;
      else in/=2;
    }
    cout<<co<<endl;
  }


}

C++: #include <iostream>
#include <cstdio>
using namespace std;

int main(){
	while(1){
		long n, ans=0;
		
		scanf(" %ld", &n);
		if(n==0) break;
		
		while(n!=1){
			if(n%2==0) n/=2;
			else n=3*n+1;
			++ans;
		}
		
		printf("%ld\n", ans);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

main(){
  int i,j,n,c;
  while(1){
    cin >> n;
    c = 0;
    if(n == 0) break;
    while(n != 1){
      if(n % 2 == 0){
	n /= 2;
	c++;
      }
      else{
	n *= 3;
	n += 1;
	c++;
      }
    }
    cout << c << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main(){
  int n,cnt;
  while(1){
  cin >> n;
  if(n==0)break;
  cnt=0;
  for(;n!=1;cnt++){
    if(n%2==0) n/=2;
    else n=n*3+1;
  }
  cout << cnt << endl;
  }
}

C++: #include <iostream>

using namespace std;

int main() {

  int n;

  int count;


  while(1) {

    cin >> n;

    if(n==0) break;

    count=0;

    while(n>1) {

      if(n%2==0) n/=2;

      else n=3*n+1;

      count++;

    }

    cout << count << endl;

  }

  return 0;

}

C++: #include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int cnt=0;
    while(n!=1){
      if(n%2==0)n/=2;
      else n=3*n+1;
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = 0;
        while(n != 1){
            if(n % 2 == 0)
                n /= 2;
            else
                ++ (n *= 3);
            ++ ret;
        }
        cout << ret << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>

#define ll long long
ll solve(ll n,ll k){
    if(n==1)return k;
    if(n%2==0)return solve(n/2,k+1);
    else return solve(3*n+1,k+1);
}
using namespace std;

int main(){
    ll n = 1;
    while(cin >> n && n != 0){
        cout << solve(n,0) << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int dp[1000002];
int rec(int a) {
  int prev = a;
  if (dp[a] >= 0) return dp[a];
  if (a == 1) return 0;
  if (a % 2) {
    a *= 3;
    a++;
  } else {
    a >>= 1;
  }
  return dp[prev] = 1 + rec(a);
}

int main() {
  memset(dp, -1, sizeof dp);
  int n;
  while (cin >> n, n) {
    cout << rec(n) << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

int a[1000000];

int colpro(int m){
    if(a[m] >= 0){
    }else if(m % 2 == 0){
        int ret = colpro(m / 2);
        a[m] = ret + 1;
    }else{
        int ret = colpro(3 * m + 1);
        a[m] = ret + 1;
    }
    return a[m];
}

int main(){
    for(int i = 0; i < 1000000; i++){
        a[i] = -1;
    }
    a[1] = 0;
    a[2] = 1;
    a[3] = 7;
    a[4] = 2;
    a[5] = 5;
    a[8] = 3;
    a[10] = 6;
    a[16] = 4;
    a[20] = 7;
    a[21] = 7;
    a[32] = 5;
    a[64] = 6;
    a[128] = 7;
    for(;;){
        int n;
        if(cin >> n){
            if(n == 0){
                break;
            }
            cout << colpro(n) << endl;
        }else{
            break;
        }
    }
    return 0;
}