-
Notifications
You must be signed in to change notification settings - Fork 32
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
Janice Lichtman - Recursion Tracing #25
base: master
Are you sure you want to change the base?
Conversation
Answers to added fun: def mystery2(n)
if n < 0
return -1 * mystery2(-n)
elsif n < 10
return n
else
return (n%10) + mystery2(n/10)
end
end
def mystery5(s)
if s.length == 0
return ""
elsif s[0].match(/[a-zA-Z]/)
return "*" + mystery5(s[1..-1])
else
return s[0] + mystery5(s[1..-1])
end
end
def mystery6(s)
if s.length < 2
return s
else
return mystery6(s[1..-1]) + s[0]
end
end |
a = (m%10) + mystery2(m/10) | ||
return -a | ||
end | ||
end |
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.
This looks like it works. I also just posted an alternative solution that is perhaps more readable.
end | ||
end | ||
end | ||
|
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.
This looks like it works. I did post another solution to consider.
One thing is to figure out if you think I intended mystery5("Hi, there!") to produce "*******" or "**, *****!"
I intended the latter, but didn't specify so you+others assumed and wrote solutions for the former.
else | ||
return mystery6B(s[1..-1]) + s[0] | ||
end | ||
end |
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.
+1 my solution too. Though I wrote the base case differently, they are essentially the same. I didn't account for nil though.
Nice job! |
Recursion Tracing
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions