Thursday 4 April 2013

The Product of Sums

During the previous class, we had another opportunity to give our minds a swing at problem solving. This time we had to devise the maximum product that can be formed from a list of numbers. These list of numbers summed up to a positive integer. After some consideration, I came to the conclusion that the best combination of numbers to use in the list, in order to achieve the max product was 2 and 3. The only explanation I have at this point for why this works is that it does for the smaller cases of n. Since it works for these smaller cases i.e. 5-10, therefore it must hold for the larger cases, since the larger cases are merely a combination of smaller ones. At least that's the theory. And being a CSC student, it made sense for me to code it up! And this is what I came up with:

def prod_sum(n):
    prod = 1
    L = []

    while n > 1:
        if n == 4 or n == 2:
            L.append(2)
            n -= 2
        elif n >= 3:
            L.append(3)
            n -= 3

    for x in L:
        prod *= x
    return prod


Its not by any means the most elegant solution, but it seems to work. Recursion might be a better way to attack it, but late Thursday night isn't a good time for recursion...

Thursday 28 March 2013

The Third Trial of Zenness

The other day, my brother was playing a game on the Xbox. What is an Xbox you ask? It sounds so familiar. Well, an Xbox is one of those legendary video game consoles that students would go home and play for hours at end during high school, back when we had the luxury of free time. Anyways back to my brother. He was playing a game called The Cave. For those of you who don't know, The Cave is a hilarious problem solving game (think Portal, without cake) quite dark at times, yet satisfyingly challenging. My brother was stuck on a level in which he had to help a monk achieve 'zenness.' And he swallowed his pride and asked me for help.

In this specific level, there is a sign that says, "An ordered mind seeks equilibrium in all things. A sloppy mind just uses the internet. http://monkpuzzle.com/." Just to the right of the sign was an unbalanced weighing scale with a six gallon jug at one end. Further to the right were two more empty jugs - one capable of holding 7 gallons, and the other 4. Beside that was a lake. It immediately reminded me of the 'penny piles' puzzle from class. My first thought was that I somehow needed to get 2 gallons in the bigger jug and then pour a full 4 gallon jug of water in that, thus giving me the equilibrium level of 6. My steps, in great detail are observed below.

'7' Gallon Jug(A)    '4' Gallon Jug(B)
0                           4 # Fill jug B
4                           Empty # Pour B into A
4                           4 # Refill B
7                           1 # Pour B into A thus leaving one in B
0                           1 # Empty jug A

At this point it was just a repetition of  this algorithm
1                           4 # Pour B into A and refill B
5                           4 # Pour B into A and refill B
7                           2 # Pour B into A... again
2                           4 # Empty A and then pour what's left in B in and then refill B

Aha! I had finally reached the level that I had aspired to. Now it was a simple task. Pour the 4 gallon jar into the 7 gallon jar thus obtaining the required equilibrium level of 6. Level complete. My brother was left in awe yet again.

The next day, as I was on the subway, a thought was nagging me. Yesterday's solution seemed too complex. Surely, there's an easier way to solve the puzzle. After a bit of thinking, I did come up with a 'more efficient' solution.

'7' Gallon Jug(A)    '4' Gallon Jug(B)
7                           0 # Fill A
3                           4 # Pour A into B
3                           0 # Empty B
0                           3 # Pour A into B
7                           3 # Fill A
6                           4 # Pour A into B

And voila, we have equilibrium! This solution was much simpler and much more elegant than the one I conjured up on the previous day. However, the nagging feeling persisted. What was I missing? The better part of the day was spent filling, refilling, and pouring (smashing them served no purpose) water into hypothetical jugs. And after some soul searching I came up with an even better solution. The solution was so blindingly obvious and I don't know how I possibly missed it. It was all in the sign: "An ordered mind seeks equilibrium in all things. A sloppy mind just uses the internet. http://monkpuzzle.com/." And sure enough, there was the answer; on that very website. It was quite maddening really. Kudos to the game designers though. At least, (I tried to console myself), it shows that I have 'an ordered mind.' Small consolation that it was.





Thursday 21 March 2013

Debugging Test 2

What can I say about test two? For one, it wasn't entirely complicated. It was based on material that was already covered at some point in class and therefore, no curve balls were thrown. It was just what the professor promised and the student ordered. I usually am a very slow starter, test-wise, and spend more time than necessary or sensible on the very first question. Don't ask me why, I don't know myself. However, this test was different. I flew through the first question like it wasn't even there. This was mostly because I had a very similar question lurking somewhere in the middle of my cheat sheet! Then came question two. Meh, it was alright. Question 3 did require a bit more ingenuity and thinking but certainly not enough to cause a nervous breakdown. All you needed to do was understand the definition and apply its contrapositive to the proof. I felt extremely good about that test, possibly because the opioids were raging uncontrollably in my head at that point. Its not often that you come out of a test feeling this great, and even rarer so at the fine institution that is U of T; it was a moment to savor. 

Here's an awesome take on the test:

http://notaslug.blogspot.ca/2013/03/post-7-post-test-stress.html#

Thursday 7 March 2013

WCS

Two down, one to go. The conclusion of assignment deux signals the end of the chapter on proofs. And just as I was starting to enjoy and get the hang of it too! But I'm not greatly disheartened by that because term test 2 is just around the corner, which implies more proving. Awesome. Bazinga! Either ways, I thought that the second assignment was moderate in difficulty, and some of the questions certainly needed one to dust and then don on their thinking caps.

For now though, its on to a new topic - calculating the efficiency of a program in its worst case - or as I like to call it, determining the worst case scenario. So far, I'm enjoying this topic as it involves running through programs and finding the number of 'steps' required for any given algorithm. (This is where the Python compiler in my head earns its pay) I realize that 'steps' is an arbitrary number which varies based on the definition. No one knows for sure, or at least at our level it is impossible to determine how much work a computer does to perform any given task. For now though, I'm going to try and concentrate on the upcoming test.

Wednesday 20 February 2013

We're Halfway There

Last week we got our tests back. To be honest I did not expect to do so well. Like I mentioned in my previous post, I spent a minimal amount of time preparing for it. And I was relieved that this risk somewhat payed off. The one thing that really annoyed me about the test were those despicable delta-epsilons! It was and is a continuing source of grief for me.The negation itself was no problem. But the explanation proved to be quite challenging. On the test, I seriously contemplated leaving it blank and invoking the '20%' rule. However, I went with my gut and wrote down what I thought it meant. Luckily, this move was beneficial if only by the skin of my teeth. I ended up with a mark of 1 for each question, and if my math is accurate, 2.0 > 1.2.

Reading week marks the halfway point in the semester and therefore the halfway point in this course. Looking back on the last six short weeks, CSC165 has so far been an unpredictable course. There has been a variety of material ranging from quantifiers and implications to delta-epsilon and now to proofs. The latter of which will get a fair share of my attention this week. Proving that a statement is true can be quite rigorous and more often than not, it requires a great deal of insight, foresight and a willingness to think way outside the box. Hopefully, this sort of work will open my mind in a new direction. You just never know. And as surprising as this sounds, I'm looking forward to what the next six weeks have to offer.

Tuesday 12 February 2013

Testing. Testing.

And that ladies and gentlemen was term test 1. Personally, I wouldn't say that it was a breeze, but it certainly wasn't a storm either. Friday was just one of those days. If you know what I mean. To be honest, I didn't spend as much time as I would have liked studying for this test since I had test in econ shortly after. (And if you're in econ you know how crazy those tests can be) So my preparation for this test included a quick glance through the course notes, quizzes, past tests, and the assignment and leaving the rest to the cheat sheet. It proved to be a blessing and a curse. Thanks to it, I was ready to face the full wrath of any and all quantifiers. However, when it came down to delta epsilon, it seemed no amount of 'cheating' would help. It took me a long time to reason with myself, (and my enemy) and to convince myself that I had the right answer. Maybe I should have left it blank, I don't know. But we'll find out soon enough.

The last couple of weeks were spent in proving various mathematical statements. For example, if n is an odd natural number, prove that it's square is also an odd natural number. The structure of a proof may turn out to be by guardian angel! Admittedly, my mind isn't creative enough to conjure up proofs. I can somewhat reason out why a statement would be true or not, but when it comes time to express what's in my mind, I freeze up. I guess I have the inability to express myself with mathematical reasoning and expression. And maybe that's why this course is going to be invaluable to my overall development.

Anyways, the answer to last weeks riddle was 'Rhombus'. You would use a 'RhOMbus' to go to the R.O.M.  HA-HA, yeah i know.

Thursday 31 January 2013

Bring on the test!

So last weekend came and went, and as surprising as I found it, I actually got down to work! It's  something you don't see often, like the Leafs stringing three victories together. It proved to be a very useful thing to do too. I definitely underestimated how annoying Assignment 1 was going to be. At first the questions seemed pretty straightforward, but when I actually got down to working on them, it seemed like each question had several possible answers. It took a great deal of test cases, patience, resisting the urge to kick-box my computer, and caffeine to keep me going. But at the end of the day, the race was won, and boy was I glad to see the end of that assignment. Note to self: get a head start on assignment 2. But for now, bring on the test! The really optimistic side of me hopes that the quizzes are foreshadowing the difficulty of the test. Much to my delight, the quizzes have so far been quite simple which I assume is their objective.

If there is one piece of advice I can offer anyone in this course is... use a TRUTH TABLE! They are unbelievably helpful. They solve any problem involving quantifiers, conjunctions, disjunctions and implications. I have found them extremely useful especially in the assignment when I had to convince myself of several answers.

I'm going to try and post a question for your minds to dig into every now and then. Here's a simple one to get things rolling

What form of transportation would you use to go to the R.O.M?