This week, we learned more about recursion and scopes. Although
I have not yet finished the assignment, I have gained some insights to how the assignment
should be able to do after Monday’s lecture. In the assignment, we are expected
to write codes that let the user to play the ‘Towers of Anne Hoy’ game. The game
we have to create is based on the ideas of ‘Tower of Hanoi’. ‘Tower of Hanoi’ starts with a stack of disks stacked
on one rod of three in ascending order with the smallest on the top and largest
at the bottom. The main objective is to
stack all the disks onto another rod in the same order using the least numbers
of moves possible.
Using recursion, possible least numbers of moves can be
predicted and puzzle can be solved as numbers of disks increases. During the lecture,
we learned top disks can be distributed to the intermediate rods so the bottom
disk can be stacked on the rod we wanted all the disks be stacked on. Using
recursion, the rest the disks can then be redistributed the same way, so the next
largest disk can be stacked on the previously stacked disk.
During this week’s
lab, we worked on tracing recursive function calls as well as writing recursive
codes. In comparison the lab of the previous week, I experienced fewer
difficulties during this week’s lab. Having
used doctest to check for test cases this lab saved us tons of time checking
through the codes’ correctness. Under circumstances when the actual result is
different from the expected result, I notice tracing can be applied during the process
of debugging.
No comments:
Post a Comment