Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day 2: String Reverse and Palindrome problem Ruby Implementation (#31)
* 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
- Loading branch information
1 parent
40c87f7
commit 82fbf88
Showing
6 changed files
with
250 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ youtube/ | |
Instagram/ | ||
a.out | ||
.vscode/ | ||
test/ | ||
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
=begin | ||
@author: aaditkamat | ||
@date: 22/12/2018 | ||
=end | ||
require './reverse' | ||
|
||
def solution(str) | ||
str != nil and str === short_solution(str) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
=begin | ||
@author: aaditkamat | ||
@date: 22/12/2018 | ||
=end | ||
|
||
def short_solution(str) | ||
if str.class != String or str === nil | ||
return nil | ||
end | ||
str.reverse | ||
end | ||
|
||
def long_solution_iterative(str) | ||
if str.class != String or str === nil | ||
return nil | ||
end | ||
reverse = '' | ||
i = 0 | ||
until i >= str.length do | ||
reverse.insert(0, str[i]) | ||
i += 1 | ||
end | ||
reverse | ||
end | ||
|
||
def long_solution_recursive(str) | ||
if str.class != String or str === nil | ||
return nil | ||
end | ||
if str === '' | ||
return '' | ||
end | ||
return long_solution_recursive(str[1..-1]) + str[0] | ||
end | ||
|
||
|
Oops, something went wrong.