Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kb9agt

  • 2 years ago

Hey kids, This lets you play test recursion at home without the Fisher Price Toys. He he! http://www.cs.cmu.edu/~cburch/survey/recurse/hanoi.html Have fun.

  • This Question is Open
  1. rsmith6559
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    IMHO, reversing a string, testing for a palindrome and converting base 10 numbers to other bases are more understandable programs to learn recursion than the Towers of Hanoi or the Towers of Brahma.

  2. KevinT
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    cool link, always looking for free resources

  3. kb9agt
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I agree that it's not the best example for recursion but is fun to play with. Something to try is this. def printMove(fr, to): global numCalls numCalls += 1 ## print('move from ' + str(fr) + ' to ' + str(to)) def Towers(n, fr, to, spare): if n == 1: printMove(fr, to) else: Towers(n-1, fr, spare, to) Towers(1, fr, to, spare) Towers(n-1, spare, to, fr) numCalls = 0 Towers(26, 'A', 'B', 'C') print numCalls notice I commented out the print in the printMove() function. This takes a little time to run but it gives you an idea of the complexity. Imagine how long it would take for 64 disks. Would I dare let it run that long? I don't know. Maybe some day. I would first want to put in some time start and time end markers.

  4. kb9agt
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    For complexity I get 2^n-1. Is that about right?

  5. kb9agt
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    For 64 disks then it would be 18446744073709551615 moves.

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.