Skip to content
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

Changing representation of base case to help understand form of recursion #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bharatagarwal
Copy link
Contributor

This is an opinionated suggestion, feel free to not merge.

I think the fact that height == 0 is the base case for the function is implicit, and maps slightly separately to the way the text talks about the base case.

By making a return explicit when height == 0, it helps to visualise how the call stack is being used.

@robot-dreams
Copy link
Collaborator

I agree this is a bit confusing. Is it also worth changing the text, which currently says "A tower of one disk will be our base case." (the base case should be a tower of zero disks)?

Alternatively, should we have something like:

if height == 1:
    move_disk(from_pole, to_pole)
else:
    move_tower(...)
    move_disk(...)
    move_tower(...)

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