Blah. Tests.

So we just wrote the second test yesterday. I really hate sometimes how hindsight is 20/20. You’re sitting there going through the test and thinking about your answers, you write down some code, and you eventually finish the test. Then you re-read it and are checking your answers and the time is up – and you’ve just realized some mistakes in your code.

But it’s too late to fix it. Just another minute! Just another two minutes! That kind of stuff really sucks.

Anywho, let’s talk about what I did wrong on my test (to my knowledge)…

Question one had us working with binary search trees and posed the question of whether or not an inorder traversal is a sorted list. The fool that I am, I totally forgot that in a binary search tree, all nodes to the left of a root node are smaller than the root node. So you can probably interpolate that I answered no to the question when the answer is, yes, an inorder traversal of a BST is indeed an ordered list.

Here’s the binary tree I constructed as an example (or it was something like this):

5

4            6

3          7            9

So the inorder traversal of that tree would be 3,4,7,5,6,9. The seven and the 5 are out of order. I thought I had proved my point – but at the end of the test, when I was quickly making sure of my answers, I realized that this -wasn’t- a BST since 7 is not allowed to be to the left of 5 in a BST. I did not have time to fix it. I was fixing other mistakes when the time ran out.

The other thing I made a mistake on was returning None if a tree whose leaves were removed became empty. I forgot to make that happen in my code for question #3. It’s such a small, easy-to-do thing, but yet I only realized that I had neglected it in the last 15 or so seconds. Quite literally the last 15 or so seconds. I remember the feeling in my gut.

I know striving to write the correct, perfect code, the first time around is what we should aim for. But that’s quite difficult to do, and I also know that. I should have taken a bit more time to think through what I was doing, probably. But dang, that sucks. Identifying mistakes yourself, -during- a test and simply not having the time to fix them.

Damn. Damn, damn, damn. Ah well. You live and you learn.

Exercise 3 and Assignment 2, Frustrations and Success

Exercise 3 and Assignment 2 were challenging. I quite enjoyed  coding  their  functions, but I won’t lie and say I wasn’t partially defeated by Assignment 2. I know there was an easier way of coding all_regex_permutatins, and I was determined to figure  it out on my own before the deadline of the assignment. Unfortunately  I  could not, and had to submit the ‘find-all-permutations-and-check-them’ method.

That being said, coding regex_match and seeing it work was a real joy. It really was much fun. The biggest hitches I had with that function had to be handling DotTrees and StarTrees, but I got them to work, and my tests completed. Though I’m not sure I successfully tested every scenario of regex, so I’m hoping all goes well during the marking.

Now when it came to Exercise 3, part A was a breeze. PArt B took some thinking, however. Finding out how I wanted to utilize a helper function to identify the deepest paths was the trick. It really m ade me appreciate the use of helper functions in a function itself, especially for recursive purposes. It’s really interesting though – because Stacks (an iterative method) and recursive functions can both achieve the goals of some functions, but deciding which one to use is a bit of a grey area for me.

I’ve usually favoured the recursive code over using Stacks, but I always wonder if it would be terrible to use Stacks instead – considering they’re such an awesome ADT. Then again, I don’t even use an explicit Stack. I just create a list and treat it as a Stack for the purposes of my function.

Recursion is Beautiful

Reading week is over and we’re back at it in classes now. I played an absolutely unhealthy amount of Dark Souls during my break, and of course did work as well! I also made my presence on the course discussion board again, which I haven’t done in a while. I missed my post last week as well, which I can’t make a good excuse for, but I’m aware of it!

I spent a bunch of time looking at Assignment 2 and understanding it. I actually thoroughly love using regular expressions. My first real foray into it was not very long ago, where I looked into the nuances and limitations of regular expressions for a website I was working on as a hobby. It’s really cool what a well-designed RegEx can identify for you.

After working on and finishing part 1 of the assignment, then talking to Dan about it and refining my code (it’s pretty damn sexy code now, if I do say so myself), I took a break. This was primarily due to the fact that part 2’s base is only to be released to us after part 1’s due-date was reached. Then I realized that I could just use placeholder names for classes until such time as I knew what they were!

So I started working on part 2 of A2. And man, has it helped me see how absolutely stunning recursion is. I was a bit worried earlier, because Dan had mentioned in class that he felt that the concept of recursion and utilizing it is like a gateway concept for most computer scientists/programmers. I was worried about the possibility of me not grasping this concept. But I’ve got to say, once the grasp is in place, it is, quite frankly, a whole new world. *Cue Aladdin music*

No but really. Really.. Recursion makes writing these seemingly complex functions so simple at times. Remembering back to when I first looked at the details for A2 Part 2, I thought to myself, “Oh boy. That’s going to be interesting to code,” as I looked at the function list. But when I am actually sitting down and working on said functions, I think and realize how useful recursive calls are. How simple they are, and then all of a sudden, I know what to do. And I write the code, and… “Wow.” It was that simple? It boggles the mind.

And there’s this kind of unspoken joy I experience when I comment a section of code. I format the comment, even. I also love – absolutely LOVE getting a bunch of things done in few lines of code. Of course I’m also very much for readability, but minimizing lines of code is one heck of a thing I’m into as well. Recursion just makes me so happy.

Damn.

‘Til next time!

Wow, it’s been a while. Here’s to Assignment 1!

It’s been nearly a month since my last post, ai ai ai. Well, today Assignment 1 is due. I spent a lot of time working on it and debugging it. Admittedly I took a while getting a start on it – I’ve been a bit distracted.

But let’s talk about the Assignment. Wow was it frustrating, but fun. The first 70% worth of the assignment was rather easy-going though. It’s that last 22% (not counting the animation of the console). There was a lot of time spent staring at the debugger in IDLE. I spent long hours contemplating how my mind went about performing moves when I played the game, and how I could translate that into an algorithm for the program to follow.

In hindsight, now that the assignment is completed and handed in, the solution feels rather obvious. Or, at least, you  can state in in a manner whereby one feels ridiculous for not having noticed that from the onset.

The most fun part about it for me was finding the optimal i value. For a while, I was sure it was i//2, but as I delved more into the debugger and understood errors, I quickly learned the importance of the number 3. Indeed, I wish I had thought about it more. Looking back at the idea of induction, it’s fairly glaring that 3 is one of the most important numbers to deal with as one tackles this problem.

This was a really fun foray into recursion and OOP. There were many “wtf”s from me, and scribbles with pen and paper holding my thoughts. Many a commented section of code was written and re-written and edited. They joy of programming, eh?

Slog Entry – January 23

It’s alive! And with a decent subdomain url, too. Pretty fantastic.

And this is my first post! It’s been a busy week. Being new to Python (outside of this and CSC108, my experience with it has been nil), I’m really enjoying what we’re starting to learn now.

Python was my first real exposure to learning object-oriented coding, and it couldn’t have come at a better time. I was delving back into PHP programming and working on expanding what I know about it – essentially to object-oriented things in the language. Having the introduction to classes and objects in CSC108 and now diving deeper into them in 148 is fantastic. It feels like it’s a bit perfect, the timing, and it makes me ecstatic.

A lot of what we’re learning in lectures nowadays is, I find, interesting and rather intuitive after an introduction. Exceptions are really rather neat, too! I’ve experienced try blocks with using PDO in PHP, and running into them in Python again is another one of those perfect-timing moments.

I talked with Dan recently in his office hours about why it was that exceptions are preferable over printed errors, and he told me that it allows larger programs to be utilized without deciding how to handle errors for the developer; that is, the developer gets to decide how to handle exceptions, rather than having a string of words suddenly printed where it shouldn’t be. Though admittedly, that would still be jarring enough to want to fix the issue. Maybe not so nice though, hah. It was a very good answer and made me really appreciate the exceptions.

Exercise 2 was also posted today. I took a look at it and worked on and finished it. Not too bad, I think. I think the pep8 Checker() function is a bit finicky though. I don’t really like those blank line errors.  It’s one too many blank lines for my coding preferences.

def function():
    pass


def function2():
    pass

It’s going to be odd, but I can live with it. Easy marks are easy marks, after all! Honestly, I just did that to test out the code tags on this WordPress shindig, hah.

Welp, that’s it for now! Until later!