Skip to content

Conversation

@EricaJCasePhD
Copy link

Recursion Tracing

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
Did you define all the recursion terms? Yes!
How do you feel about tracing recursive problems? (good, bad, ugly, neutral) Good -- I think it is fun
Would you like help/follow up about recursion? No

else
return s[0] + mystery5(s[1..-1])
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

return ""
end
return s[(s.length - 1)] + mystery6(s[0...(s.length-1)])
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code looks like Java code ;)

else
return (n%10) * n / n.abs + mystery2(n/10)
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it may work - but is a little hard to follow. Here's another solution that's perhaps more readable.

def mystery2(n)
  if n < 0
    return -1 * mystery2(-n)
  elsif n < 10
    return n
  else
    return (n%10) + mystery2(n/10)
  end
end

@sudocrystal
Copy link

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants