Skip to content

Commit 84194cf

Browse files
committed
exercism 56
1 parent 01bd56e commit 84194cf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ solution of many challenges of [Leetcode](https://leetcode.com/), [Exercism](htt
273273
53. [ETL](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/etl.rb)
274274
54. [Nucleotide Count](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/nucleotide_count.rb)
275275
55. [Pythogorean Triplet](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/pythogorean_triplet.rb)
276+
56. [Collatz Conjecture](https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/blob/master/exercism/collatz_conjecture.rb)
276277

277278
<a name="leetcode"/>
278279

exercism/collatz_conjecture.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#Problemm: https://exercism.org/tracks/ruby/exercises/collatz-conjecture
2+
3+
#Solution
4+
class CollatzConjecture
5+
def self.steps(num)
6+
raise ArgumentError if num<=0
7+
step_count = 0
8+
until num==1
9+
num = num%2==0 ? num/2 : (3*num+1)
10+
step_count+=1
11+
end
12+
step_count
13+
end
14+
end

0 commit comments

Comments
 (0)