Skip to content

Conversation

@tingwong
Copy link

@tingwong tingwong commented Apr 3, 2017

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!
Would you like help/follow up about recursion? I didn't have time to complete the recursion writing or answer the final added-fun portion; I plan to complete it this upcoming weekend, hopefully there's an opportunity to still get feedback?

This means that the recursion is calling itself infinitely and a solution can't be reached (or that no solution is possible).

- Tail Recursion
I think that tail recursion means that rather than performing all your recursion calls first before returning back to calculate the results, you first perform all your calculations then move to the next recursive step. In this way, some efficiency is gained as you don't need to go through the activation chain all over again to perform the recursion.

Choose a reason for hiding this comment

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

I didn't go over this in class, but this is mostly right. I may cover in the future, but it's not terribly important at this moment.

else
return (n%10) + 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.

Hmm... This will definitely change the behavior of what the method does, but perhaps I should have specified what "the way we might expect it to work" is. I wold expect mystery2(-123) to produce -6 not 6. If you expected 6, then your solution is correct. If you wanted -6, then it's not.

end
end
end
```

Choose a reason for hiding this comment

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

Nice job! A couplet things to consider here.

  1. Regex would make this potentially a more sophisticated solution, but yours is maybe easier to read.

  2. Is your assumption that we would want to strip out all non-alpha characters? That's what your solution would produce ==> mystery5("Hi, there!") would be "*******", but what if we wanted it to be "**, *****!" which is what I intended. I will make these instructions more clear for my next iteration of this assignment.

@sudocrystal
Copy link

Recursion Tracing

Looks good!

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