Thursday, 13 February 2014

week of february 12, 2014 csc148h1 winter 2014

This week was tough, >10 hour spent finishing up a1.
This is the first time in this course i have been implementing recursion, and i have implement it in two ways:
1) using recursion to calculate i, the integer constant 1<=i<n in the M(n) function. M(n) is function that generates the number of moves needed to finish a stool of n cheeses. There is always an i that minimizes the number of moves you need to make. What i did was that i used a for loop to iterate i 1<i<n and plugged into the M(n) equation. The M(n) values are then appended into an empty list. Then the appendix of the list is returned to produce i. I feel almost a little proud because they say that this is the hardest part of the assignment and i finished this function in <20 minutes.Most people tried to return --- in 1 line, but that was simply too complicated for python to operate. Instead, i created a helper function to be called within my main function, and that worked without bugs.
2) the second implementation of recursion was a bit unlike to what i understand recursion to be. if number of cheeses > 1, the order of the stools of the parameters in the move function are shuffled in different orders. again, like M(n), i called a 3-stool move function within my 4-stool move function, this is because when there are cheeses on the intermediate stool, there are only 3 stools you can use to work with (the origin stool is being occupied by the longer cheeses). The greatest challenge of this part is working with parameters i have not defined, tracing through where the recursion is working on, and coming up with a complete algorithm that moves the cheeses when moved over and over again.
All in all, i feel very accomplished that i have learned how to adequately implement recursion, however i do hope that the test will not be as difficult. =(

No comments:

Post a Comment