-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
palindrome #16
base: master
Are you sure you want to change the base?
palindrome #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
|
||
def fact(n) | ||
if n == 0 || n == 1 | ||
return 1 | ||
end | ||
|
||
return n * fact(n-1) | ||
end | ||
|
||
def fib(n) | ||
if n == 1 || n == 2 | ||
return 1 | ||
end | ||
|
||
return fib(n-1) + fib(n-2) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good solution. |
||
|
||
def pal(s) | ||
if s.length == 0 || s.length == 1 | ||
return true | ||
end | ||
|
||
if s.chars[0] == s.chars[s.length-1] | ||
s.slice!(0) | ||
s.slice!(s.length-1) | ||
pal(s) | ||
else | ||
return false | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good solution! This implementation is readable and easy to follow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @malderi Thank you for reviewing my code! |
||
|
||
def binary(n) | ||
binary_helper(n) | ||
end | ||
|
||
def binary_helper(digits, binary="", result="") | ||
if digits == 0 | ||
result += binary + " " | ||
return result | ||
else | ||
result = binary_helper(digits-1,binary+"0", result) | ||
result = binary_helper(digits-1,binary+"1", result) | ||
end | ||
return result | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good solution. |
||
|
||
def travel(x,y) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good solution.