Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		k := 0
		for n > 1 {
			if n&1 != 0 {
				n = n+((n+1)>>1)
				k+=2
			} else {
				n >>= 1
				k++
			}
		}
		fmt.Println(k)
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int i=0;
		for(i=0;N!=1;i++){
			if((N&1)==0) N /= 2;
			else N = N*3+1;
		}
		printf("%d\n",i);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        
        function<int(int)> count = [&](int x) -> int {
            if (x == 1) return 0;

            if (x % 2) x = x * 3 + 1;
            else x /= 2;
            return count(x) + 1; 
        };
        
        cout << count(n) << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;


int main(){
	int n,i,j,k;

	while (1){
		j = 0;
		cin >> n;
		if (n == 0){
			break;
		}

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

}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define N 1000002
vector<int> cl(N,0);
class Queue{
	vector<int> v;
	int low;
	int high;
public:
	Queue():v(N,0),low(N-1),high(N-1){}
	void push(const int &t){
		v[low]=t;
		--low;
	}
	void pop(int &t){
		t=v[high];
		--high;
	}
	bool empty(){
		return high==low;
	}
} ;
int main()
{
	Queue q;
	cl[1]=0;
	q.push(1);
	while( !q.empty() ){
		int t;
		q.pop(t);
		if( t*2<N ){
			if( cl[t*2]==0 ){
				cl[t*2]=cl[t]+1;
				q.push(t*2);
			}
		}
		if( (t-1)%3==0&&t>1 ){
			if( cl[(t-1)/3]==0 ){
				cl[(t-1)/3]=cl[t]+1;
				q.push((t-1)/3);
			}
		}
	}

	while(true){
		int n;
		
		cin>>n;
		if(n==0)break;

		cout << cl[n] << endl;
	}
	return 0;
}

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

int main()
{
    int n;

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.collatz", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){

		int n;
		stringstream ss(str);

		ss >> n;

		if (n == 0){
			break;
		} // end if

		int res = 0;

		while (n != 1){
			if (n % 2 == 0){
				n /= 2;
			}else{
				n = 3*n + 1;
			} // end if
			++res;
		} // end while

		cout << res << endl;

	} // end loop

	return 0;
}

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int collatz(int n) {
	static unordered_map<int, int> m;
	if (m.count(n))
		return m[n];
	return m[n] = n == 1 ? 0 : (n % 2 ? collatz(n * 3 + 1) : collatz(n / 2)) + 1;
}

int main() {
	for (int n; (n = in());)
		outl(collatz(n));
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 1000000;
int n;
int dp[MAX_N+1];

int solve(int n)
{
  if(dp[n] >= 0) return dp[n];
  if(n & 1) return dp[n] = solve(3 * n + 1) + 1;
  else return dp[n] = solve(n / 2) + 1;
}

int main()
{
  erep(i, 0, MAX_N) dp[i] = -1;
  dp[1] = 0;
  while(~scanf(" %d", &n) && n) printf("%d\n", solve(n));

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

long long n, m;
vector<pi>s;
int dp[1024];

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

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

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

C++: #include <iostream>
#include <stdio.h>

using namespace std;

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

C++: #include <iostream>
using namespace std;
int main(){
	int n,c;
	while(cin>>n,n){
		for(c=0;n-1;c++)n%2?n=3*n+1:n/=2;
		cout<<c<<endl;
	}
}

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