#! /usr/bin/env python # ulam or 3n+1 conjecture: # python illustration by o. knill, 8/6/2001 def ulam(n): k=0 while n>1: k=k+1 if n % 2==0: n=n/2 else: n=3*n+1 return k def main(): i=2 max=1 limit=10000000000L show_frequency=1000 while i <= limit: i=i+1 l=ulam(i) if l>max: max=l; if i % show_frequency==0: print "Maximal number of iterations needed until",i,": ",max main()