Skip to content

Commit 47df62a

Browse files
Aadit KamatMadhavBahl
authored andcommitted
Add Ruby solution for Day 24 problem (#191)
* Add @aaditkamat as a contributor * Add Ruby code for Day 1: FizzBuzz problem * Add Ruby code for Day 2: String reverse problem * Update README.md for Day 2 * Modify Ruby code and README * Add condition for nil and wrong type edge cases * Add a seperate Ruby source code file for palindrome * Modify code for reverse.rb * Add seperate palindrome and reverse code sections in README * Update gitignore * Refactor palindrome.rb and rename heading in README * Add solution for Day 3: Hamming Problem * Add condition for strings of unequal lengths * Update README * Change project name and owner in.all-contributorsrc * Remove merge conflict lines * Add @shivank86 as a contributor * Add C++ files for different patterns * Add author and date comments at the top of C++ files * Update README.md * Add solution for Day 6 Problem in Python * Update README * Refactor code files * Modify string representation of output in python files * Add Ruby solutions for Day 6 problem * Update README for Ruby code * Add first version of solutions for Day 7 problem in C++, Java & Ruby * Modify solutions * Update Day 7 README * Remove merge conflicts from CONTRIBUTORS.md * Add back removed lines in CONTRIBUTORS.md * Add code sections contributed by @imkaka to day 6 README * Update README.md * Add C++ solution * Add Day 8 solution in C++ * Add Day 8 solution in Java * Add Day 8 solution in Ruby * Add Day 8 solution in Python * Add credits at the top of the code * Update README * Update C++ implementation * Update Python implementation * Add solution for Day 10: String Permutation Problem in Python Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Update Day 10 README Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Change heading in README and remove empty directory in day 9 Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Update README.md * Add Ruby solutions for Day 13 * Update README * Add credits to the code * Add Python solution for Day 13 * Update Day 13 README * Update fibonacci.py * Modify Fibonacci python code section in day 13 README * Add Ruby solution to Day 16 problem Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Update Day 16 README with Ruby implementation Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Change wording of print statement Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Add Python solution to Day 17 problem Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Add Python implementation to Day 17 README Signed-off-by: Aadit Rahul Kamat <aadit.k12@gmail.com> * Add solution to Day 18 Question A: Frequency Counter * Add solution to Day 18 Question B: Count Uniques * Add solution to Day 18 Question C: Check Power N * Update day 18 README with personal Python solution * Update check_power_n.py * Update count_uniques.py * Add Python implementation for Day 19 and update Day 18 solutions Signed-off-by: Halid Altuner <aadit.k12@gmail.com> * Add CMakeLists.txt to gitignore Signed-off-by: Aadit Kamat <aadit.k12@gmail.com> * Add Ruby Solution to day 24 problem Signed-off-by: Aadit Kamat <aadit.k12@gmail.com> * Add Ruby solution to day 24 README Signed-off-by: Aadit Kamat <aadit.k12@gmail.com>
1 parent 3c5df79 commit 47df62a

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
CMakeLists.txt
12
node_modules/
23
playground/
34
youtube/

day24/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,50 @@ function isRotation (arr1, arr2) {
5858
console.log (isRotation ([1, 2, 3, 4, 5, 6, 7], [4, 5, 6, 7, 1, 2, 3])); // true
5959
console.log (isRotation ([1, 2, 3, 4, 5, 6, 7], [7, 1, 2, 3])); // false
6060
console.log (isRotation ([1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1])); // false
61+
```
62+
63+
## Ruby Implementation
64+
65+
### [Solution](./Ruby/circular_rotation.rb)
66+
67+
```ruby
68+
=begin
69+
@author: aaditkamat
70+
@date: 22/01/2019
71+
=end
72+
73+
def check_rotation(first, second)
74+
if first.length != second.length
75+
return false
76+
end
77+
i = 0
78+
curr = second.index(first[0])
79+
if curr == nil
80+
return false
81+
end
82+
i += 1
83+
curr = (curr + 1) % (first.length)
84+
until i >= second.length
85+
if first[i] != second[curr]
86+
return false
87+
end
88+
i += 1
89+
curr = (curr + 1) % (first.length)
90+
end
91+
true
92+
end
93+
94+
def parse_input_array()
95+
gets.chomp!.gsub(/\]|\[/, '').split(',').map{|s| s.to_i}
96+
end
97+
98+
def main
99+
print "Enter the first array: "
100+
first = parse_input_array()
101+
print "Enter the second array: "
102+
second = parse_input_array()
103+
puts check_rotation(first, second)
104+
end
105+
106+
main
61107
```

day24/Ruby/circular_rotation.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=begin
2+
@author: aaditkamat
3+
@date: 22/01/2019
4+
=end
5+
6+
def check_rotation(first, second)
7+
if first.length != second.length
8+
return false
9+
end
10+
i = 0
11+
curr = second.index(first[0])
12+
if curr == nil
13+
return false
14+
end
15+
i += 1
16+
curr = (curr + 1) % (first.length)
17+
until i >= second.length
18+
if first[i] != second[curr]
19+
return false
20+
end
21+
i += 1
22+
curr = (curr + 1) % (first.length)
23+
end
24+
true
25+
end
26+
27+
def parse_input_array()
28+
gets.chomp!.gsub(/\]|\[/, '').split(',').map{|s| s.to_i}
29+
end
30+
31+
def main
32+
print "Enter the first array: "
33+
first = parse_input_array()
34+
print "Enter the second array: "
35+
second = parse_input_array()
36+
puts check_rotation(first, second)
37+
end
38+
39+
main

0 commit comments

Comments
 (0)