{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_Su2010_Solutions5_4-5

# E7_Su2010_Solutions5_4-5 - Lab 5 Partial Solutions Lab 5...

This preview shows pages 1–3. Sign up to view the full content.

Lab 5, Partial Solutions Contents Problem 4 (Towers of Hanoi) (a) (b) (c) (d) Problem 5 (Fibonacci Sequence) (a) (b) (c) Problem 4 (Towers of Hanoi) (a) According to Figure 12, It takes _S(N)_ steps to uncover disk _N+1_. It takes just one step to move disk _N+1_ to its final position. It takes another _S(N)_ steps to put the remaining _N_ disks back on top of disk _N+1_. Therefore, _S(N+1) = S(N) + 1 + S(N) = 2*S(N) + 1_. (b) type towersteps function S = towersteps(N) if N == 1 S = 1; else % Use the recurrence relation from part (a) S = 2*towersteps(N-1) + 1; end towersteps(1) ans = 1 towersteps(2) ans = 3 7/19/2010 Lab 5, Partial Solutions C:/…/lab05soln.html 1/5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
towersteps(3) ans = 7 towersteps(10) ans = 1023 towersteps(64) ans = 1.8447e+019 (c) numDisks = towersteps(64); disksPerSecond = 1; secondsPerMin = 60; secondsPerHour = 60*secondsPerMin; secondsPerDay = 24*secondsPerHour; secondsPerYear = 365*secondsPerDay; numYears = numDisks/disksPerSecond/secondsPerYear numYears = 5.8494e+011 (d) type towers function towers(n,initialTower,finalTower) if n == 1 % If we only have one disk to move, that disk is always 'Disk 1'.
This is the end of the preview. Sign up to access the rest of the document.
• Summer '08
• Patzek
• Fibonacci number, Tower Tower Tower, Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern