I feel like firstly I should address the elephant in the room: Assignment #1. Thanks to a nice amount of midterms and other assignments, I got started to work on it a little later than I should have. Thankfully, my partner had already begun and thus we were able to breeze through the first four steps. Setting up classes and methods was essentially CSC108 review anyway. While there was quite a bit of polishing that needed to be done to the code, it functioned so we left it be for the time being. The fun part began when we needed to come up with implement the given algorithm to solve the puzzle. The mysterious i value irritated us to no end as we spend quite a long time figuring out what it was. First we tried 1, but that didn't. Then we tried 2, but we started to get errors. Next, we tried to make i dynamic by basing it off of the current n value, but n - 1 and n // 2 to no avail. We finally decided to create a spreadsheet of which i value, for a given n value, would give the ideal number of moves. After we went through it a bit, I noticed a pattern. For odd numbered n's, i was half of n plus one. For even numbered n's, i was half of n. Putting that into programming format, i = (n // 2) + 1, which my partner simplified into i = (n + 1) // 2. Don't worry, I'm done with the shop-talk for now.
Armed with the mystical i value, we were able to start trying to implement the algorithm. Many recursive adventures began at this point, as we aimlessly tried different combinations for a couple hours. Eventually we remembered what was demonstrated in lecture, and broke the problem into two steps. One that would be a recursive function for 4 stools, and another that would be a recursive function to solve for 3 stools. We based our 3 stool function off of the one shown in lecture (giving credit, of course), and gave it the pretty fly name "Anne"-something (it's slipped my memory). Next we made our "pilgrim" function. By a sudden brainwave, I came up with a solution that I didn't fully comprehend (not going to lie, it still boggles my mind how it works), which almost worked but returned an error when the program tried to move a non-existent cheese. After another hour of slamming our heads against the desk, we discovered that in one line we wrote "n - 1" instead of "n - i". This resulted in another hour of slamming our heads against the desk in frustration. I swear, Satan himself manifests in the code sometimes.
After we implemented the mysterious recursive function that by some computer magic actually worked, we decided to leave understanding what on earth we just implemented until later. Now was the fun part: polishing the code. In the process of making the code more efficient, we broke our program and then fixed it. Next, we finalized our docstrings and examples, and were about ready to call it a night. But despite how much the fatigue was setting it, we just had to do the bonus question. It was more difficult than I originally expected it to be, but after thinking through it, it was easily solved using surrogate TOAHModels and a couple for-loops.
All in all it's been a fun (albeit long) week in the world of computer science. I've decided to start regularly posting to this in an attempt to salvage part of my mark. Also, it's actually kind of fun.
Until next week!
No comments:
Post a Comment