2018-10-22 11:49:29 -04:00
|
|
|
# CollatzConjecture class
|
2018-09-21 09:18:33 -04:00
|
|
|
class CollatzConjecture
|
2018-10-22 11:49:29 -04:00
|
|
|
def self.steps(num, count = 0)
|
|
|
|
raise ArgumentError if num < 1
|
|
|
|
return count if num == 1
|
|
|
|
|
|
|
|
count += 1
|
|
|
|
number = num.even? ? num / 2 : (3 * num) + 1
|
|
|
|
steps(number, count)
|
2018-09-21 09:18:33 -04:00
|
|
|
end
|
|
|
|
end
|