brewersfan1976

hailstone_sequence.rb

Feb 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.26 KB | None | 0 0
  1. def hailstoneSequence(n)
  2.     count = 0
  3.    
  4.     while (n != 1)
  5.           if n % 2 == 0 then
  6.              n = n / 2
  7.           else
  8.              n = 3 * n + 1
  9.           end
  10.              
  11.           count = count + 1
  12.     end
  13.        
  14.     return count
  15. end
Advertisement
Add Comment
Please, Sign In to add comment