Entries from 2007-01-24 to 1 day
# Collatz numbers def collatz(n) while n > 1 yield n if n%2 == 0 then n = n/2 else n = 3*n + 1 end end yield 1 end (1..128).each {|n| count = 0 collatz(n) {|i| count += 1} printf "#{n}:#{count} " } Note the shortest periods at n = 2^k and …