Wednesday 13 November 2013

Midterm 2

I thought I did well, but I just realized that I made an incredibly absentminded mistake.  Instead of using n.item/n.right/n.left, I accidentally used self.______ instead. I'm actually feeling pretty disappointed in myself because I'm almost 100% certain that if I were to replace every instance of self.______ with the appropriate n._____, then my code would work just fine. I don't know, it's just a very brutal mistake to me, because I don't think I'm normally that incompetent. Furthermore, I didn't do particularly well on the last midterm, either, so this is all kinds of disheartening. Mistakes happen, and I'll try to let it go. Maybe I'll ask Danny how much I could possibly lose for it; knowing will probably alleviate some of my anxiety.

Sunday 3 November 2013

On Assignment 2: Part 2

So what I've been doing isn't working. I have no idea how to handle this; what an incredibly frustrating situation. I know exactly where the problem is, but I have no workaround. No, that's false; I have a way to deal with the problem, but it's ugly and long-winded. Also, I feel like I'm a bad partner for being unable to get this done. These are the four test cases I'm trying to make our code work with:

    >>> string_to_tree('(0***.1)')
    DotNode(StarNode(StarNode(StarNode(RegexTreeNode(0, [])))), RegexTreeNode(1, []))
    >>> string_to_tree('(0|(0.1***))')
    BarNode(RegexTreeNode(0, []), DotNode(RegexTreeNode(0, []), StarNode(StarNode(StarNode(RegexTreeNode(1, []))))))
    >>> string_to_tree('(0***.1***)')
    DotNode(StarNode(StarNode(StarNode(RegexTreeNode(0, [])))), StarNode(StarNode(StarNode(RegexTreeNode(1, [])))))
    >>> string_to_tree('(0|(0.1)***)')
    BarNode(RegexTreeNode(0, []), StarNode(StarNode(StarNode(DotNode(RegexTreeNode(0, []), RegexTreeNode(1, []))))))

Unfortunately for me, it just won't happen. The first case is the simplest that we're trying to make work. Then the nested scenario. Then multiple instances of nested StarNodes, then one in which the StarNode applies to another BinaryNode. It works if the string were, say, '(0|(((0.1)*)*)*)', but trying to construct a new string has been an exercise in, if not futility, than absolute madness. I'm not too sure what else to do, though. Creating a new string with brackets around the designated areas is difficult, but trying to fix the current mutually recursive helper functions is also ridiculously difficult, too. What a pain.

On Assignment 2: Part 1

Or however many parts I'll be going through.

There's something wrong with how we're parsing the strings. It fails only in this one, very specific scenario. And the harshest part about it failing is that the way we've coded the parser means that a) it works perfectly fine for anything else of arbitrary complexity, and b) it's mutually recursive. My partner handled the main bulk of it, and I'm trying to edit it now, but it's really tough to not screw up all the previously working test cases. At this point, I'm working around it in the most convoluted way, which irritates me because, well, bad code is bad code.

Thursday 31 October 2013

On Exercise 6

I’m actually disappointed this week’s exercise explicitly forbids it. I was wondering about whether or not last week's success was a fluke. However, this exercise did make me feel a bit nostalgic for the ease of CSC108. Also, it's been a while since I've used a 'while loop'. Some upper year CSC students I've spoken to mentioned that they rarely used any variation of a 'while loop', at all. I almost did this:

def __contains__(self, item):
            return str(item) in str(self)
out of sheer laziness, but I think I would’ve automatically failed for calling on a function that uses recursion even if I personally did not use it at all. I ended up doing something else which should work, although it has yet to undergo pre-marking. Once I get it pre-marked, though, I’ll resubmit with “return str(item) in str(self)”; I'm just really curious about whether or not it would be successful at all.

On Exercise 5



Last week’s exercises were good. Actually, they were pretty great. There’s something satisfying about doing something recursively and trusting that it works. So, happily for me, I think I can confidently say that I’m finally comfortable with recursion. set_depth was exactly six lines of code, which is great because I think the handout mentioned that approximately six lines were optimal? Regardless, I'm pretty happy about how quickly I was able to piece it together; it just felt really good after a semester of being really confused about recursion. I wonder if it's at all possible to shorten set_depth even further, but I don I think I can with the way I've set it up. My leaves_and_internals function could probably have been better, though. I looking through it this week and it just seems so long-winded. I almost want to see other people's code just to see how I could make my own more efficient. I originally tried to write it with a list comprehension, but I think I messed it up, so I ended up doing something else, instead. Perhaps I should try tackling it again.

Assignment 1 Reflection



Late night programming
Should’ve started earlier
Oh god, fml

Dear brain: code better
Let me get some sleep tonight
I have tests this week

What is happening?
Damn, why isn’t this working?
Oh… wait a minute…

Oh my god, it works
Ah, progress is beautiful
Almost done, I swear

Dear Partner:  good job!
I can’t believe we’ve finished
Hope we do okay.

Alright, lesson learnt
Don’t procrastinate ever
Too stressful for me

As the due date for Assignment 2 approaches, I thought it'd be a good idea to post this. It's been a while, but I remember that we originally misinterpreted something which prevented from making any progress; that was quite stressful. We're doing a lot better with Assignment 2, because (I think) we're understanding the material better, and binary trees are fun to parse through.

Tuesday 22 October 2013



Last week was stressful. I had had two midterms (and a quiz) on Wednesday, then an additional midterm on Thursday; then this week, I had two midterms on Monday, I’ll have a test tomorrow, and an assignment due for Friday. I don’t think I did well on the midterm for this class; I think I misinterpreted a bunch of different stuff, which is disappointing because I definitely don’t think I’m a bad programmer. 
 
The exercises for last week were pretty fun, though. I was stressing out for a bit on Friday because neither make_tree nor sum_to_the_deepest were working properly, but it turned out that I had had a few typos. I made the function name make_treelist instead of make_tree, for example. It really threw me off because make_treelist was working exactly as specified so I didn’t realize why it was failing the premarking. I thought, since I was still uncomfortable with recursion, that it had been my code that was the problem, but nope; I had just misread the function name. I made a silly error for sum_to_the_deepest, as well; when comparing the depths of the left side vs. the right side, I switched the numbers around (right = nested_depth(t[1]), left = nested_depth(t[2]) instead of t[2] and t[1], respectively). I’ve learnt my lesson: late night programming is a bad idea.