Tuesday, May 28, 2013

My struggle with a simple problem

Over the long weekend I took some small amount of time to continue with my Udacity class. Right now I'm on a little section of 5 exercises.. not really being taught any new material, but demonstrating understanding of basic concepts.

It's these kinds of exercises that I look forward to. I like being able to look at a problem, conceptualize the solution in my mind, and work through it with the basic building blocks I have been given.

I told a friend once that I thought my problem with Python was that I would encounter a problem and wonder "How can I solve this? How can I deconstruct this seemingly simple process into a step-by-step process?" Usually I'd give up after a while.. the last time I did this I was supposed to take a number of letters and print every possible combination of said letters.

One afternoon I sat in the bathroom at work on my phone, typing on my notepad how to maaaybe make this work. Lots of loops and some math.. I never really worked it out. Eventually, I got fed up and googled how other people did it; they'd just import some crap and throw the variable into a function within that package.

It was like cheating! How can we ever innovate if we just take what is given to us without trying to work through it ourselves first? I had this big mess of code and repeatedly failed at printing all the scrambled-up versions of "Asshattery" and some douche gives me 5 lines of code as the grand solution to my problem.. ridiculous.

---

I wrote to Mr Dan yesterday, after being in bed on my chromebook for 3 hours messing around on the internetz, about my current problem in Udacity. It was an incredibly simple process for a human.. but the instructor had given it a *GOLD STAR* which meant it was tough to code.

Define a function "median" which finds the median number in a set of three numbers. The numbers may all be different, or 2 or all of the numbers may be the same value.

Great! The instructor had given us predetermined functions, which we had made earlier in the class, called "bigger" which returns the bigger of two numbers and "biggest" which returns the biggest of three.

I sat there for a minute thinking about where to start.. then my brain was farting all over the place. I actually took a quarter, nickel, and dime and thought through the code visually. Using less-than and greater-than was annoying because the values could all be the same, and then what would I do? I only had if statements, while loops.. we hadn't even really covered "or" or "and" so I didn't want to use those.. even if I did I may not have figured it out on my own.

Dan and I figured sorting would be the best, since we had a set number of values and could just sort them numerically and print the 2nd item in the list. I couldn't use a sort function so a few lines of comparing numbers and switching them about eventually wound up in my code and I executed it. Everything worked out. I thanked Dan for his help, and felt disappointed in myself.

When I watched the instructor's solution, I felt even more ashamed.. it seemed so simple. Determine the "Biggest" number, then write a few if-statements..

if a == biggest(a,b,c):
    return bigger(b,c)
if b == biggest(a,b,c):
    return bigger(a,c)
if c == biggest(a,b,c):
    return bigger(a,b)

The solution Dan helped me with had a few less lines.. so I figured "Ha! We are superior! Dan the Man and Mike the... uh....dyke?" but my brief soiree into lesbianism didn't lift my spirits for long. I had failed to look at the plain-as-hell clues right in front of me. You have these tools, look at them! These functions which you can use.. just think about it! Understand why they make your life easier, how to utilize them to enhance your experience as a coder!

It will take some more time, but I'm getting over my weird issue, which I attribute to some ego I have. Sure, you could write every program known to man with just some if-statements, loops, and a little understanding of math.. but you'd be an idiot for doing so or even wanting to do so.

Use the tools that are available to you. When a new wrench or power-drill turns up on the market, don't look at it like it's some barrier in-between yourself and your dream of being the l33t3$t c0d3r 4L1\/3. Realize it's there to help you get there, to your end goal: to enslave all computers.

No comments:

Post a Comment