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)
	}
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0158

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        count = 0
        while n != 1:
            if n % 2 == 0:
                n //= 2
            else:
                n *= 3
                n += 1
            count += 1
        print(count)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: # coding: utf-8
# Your code here!

while True:
   n = int(input())
   if n == 0: break
   
   c = 0
   while n != 1:
      if n % 2 == 0:
         n /= 2
      else:
         n = n * 3 + 1
      c += 1
   print(c)

Python: while 1:
    n=int(input())
    if n==0:
        break
    s=0        
    while n!=1:
        if n%2==0:
            n=n/2
            s+=1
        else:
            n=n*3+1
            s+=1
    print(s)

Python: def collatz(n):
    if n % 2 == 0:
        return n // 2
    else:
        return n * 3 +1
while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    while n != 1:
        n = collatz(n)
        a += 1
    print(a)

Python: while True :
    n = int(input())
    
    if n == 0 :
        break
    else :
        cnt = 0
        
        while True:
            if n == 1 :
                print(cnt)
                break
            
            elif n % 2 == 0 :
                n /= 2
                cnt += 1
                
            else :
                n *= 3
                n += 1
                cnt += 1

Python: while True:
    n = int(input())
    if n == 0:
        break
    
    ans = 0    
    while n != 1:
        
        if n % 2 == 0:
            n = n/2
        else:
            n = n*3+1
        
        ans += 1
    
    print(ans)

Python: while True:
    a = int(input())
    if a == 0:
        break
    c = 0
    
    while a != 1:
        c += 1
        if a %2:
            a = 3 * a +1
        else:
            a = a//2
    print(c)

Python: def korat(x):
    i = 0
    while x > 1:
        if x % 2:
            x = x * 3 + 1
            i += 1
        while x % 2 == 0:
            x = x // 2
            i += 1
    return i

while True:
    n = int(input())
    if n == 0:
        break
    print(korat(n))

Python: import sys
import math
def koratsu(n,i):
    if(n==1):
        return i
    elif(n%2==0):
        n=n//2
        i=i+1
        return koratsu(n,i)
    else:
        n=3*n+1
        i=i+1
        return koratsu(n,i)
i=0
while i<50:
    n=int(input())
    if(n==0):
        break
    kaisu=koratsu(n,i)
    print(str(kaisu))

Python: while True:
    n=int(input())
    a=0
    if n==0:
        break
    while True:
        if n==1:
            print(a)
            break
        elif n%2==1:
            n*=3
            n+=1
            a+=1
        elif n%2==0:
            n/=2
            a+=1

Python: while True:
    n = int(input())
    
    if n==0:
        break
    
    count = 0
    while True:
        if n==1:
            break
    
        if n%2==0:
            n = int(n/2)
            count += 1
            continue
        if n%2==1:
            n = int(3*n+1)
            count += 1
            continue
        
        if n==1:
            break
    
    print(count)
    
    continue

Python: def x(n):
    if n == 1:
        return 0
    elif n % 2 == 0:
        return x(n/2) + 1
    else:
        return x(n*3 + 1) + 1

while True:
    n = int(input())
    if n == 0:
        break
    print(x(n))

Python: def collatz(n,m):
    if n==1:
        return(m)
    if n % 2 == 0:
        return(collatz(n/2, m+1))
    else:
        return(collatz(3*n+1, m+1))

while True:
    n = int(input().strip())
    if n == 0:
        break
    print(collatz(n,0))

Python: while True:
    n=int(input())
    count=0
    if n==0:
        break
    while True:
        if n==1:
            break
        elif n%2==0:
            n=n/2
            count+=1
        else:
            n=n*3+1
            count+=1
    print(count)

Python: while True:
  N, c = input(), 0
  if not N:
    break
  while N > 1:
    if N % 2:
      N = N * 3 + 1
    else:
      N /= 2
    c += 1
  print(c)

Python: # coding: utf-8
# 81

while True:
    n=int(input())
    c=0
    if n==0:
        break
    while True:
        if n==1:
            break
    
        if n%2==0:
            n = n/2
            c += 1
        
        else:
            n = n*3+1
            c += 1
    print(c)

Python: def collatz(n):
    i=0
    while n != 1:
        if n%2==0:
            n = n/2
            i=i+1
        else:
            n=3*n+1
            i=i+1
    return(i)
    
while True:
    n=int(input())
    if n==0:
        break
    print(collatz(n))

Python: def process(n, x):
    if n != 1:
        if n % 2 == 0:
            x += 1
            return process(n//2, x)
        else:
            x += 1
            return process(n*3+1, x)
    else:
        return x

while True:
    n = int(input())
    if n == 0: break
    print(process(n, 0))

Python: while 1:
    n=int(input())
    if n==0:break
    c=0
    while n!=1:
        n=n*3+1 if n%2 else n/2
        c+=1
    print(c)

Python: def f(n, t):
    if n % 2 == 0:
        n = int(n / 2)
    else:
        n = n * 3 + 1
    t += 1
    if n == 1:
        return t
    else:
        return f(n, t)


while True:
    _n = int(input())
    if _n == 0:
        break
    print(_n if _n == 1 else f(_n, 0))

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
using namespace std;

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n && n>0){
		int c=0;
		while(1){
			if(n==1) break;
			if(n%2) n=3*n+1;
			else n/=2;
			c++;
		}
		o(c);
	}
}

C++: #include <iostream>
#include <unordered_map>

using namespace std;

unordered_map<int, int> memo;

int rec(int n) {
    if (memo.find(n) != memo.end()) {
        return memo[n];
    }
    if (n == 1) {
        return memo[n] = 0;
    }
    if (n % 2 == 0) {
        return memo[n] = 1 + rec(n / 2);
    } else {
        return memo[n] = 1 + rec(n * 3 + 1);
    }
}

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        cout << rec(n) << endl;
    }
}

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

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

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

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