Wednesday, October 15, 2014

MakerSquare Day 35: Teamwork--without ping pong (8/2)

Last night, I tested a friend's quiz program (a really neat one). This afternoon, a friend helped me debug a use of the Soundcloud API. Earlier this evening, I ran a friend through a white-boarding exercise.

Besides bragging about all the friends I have--three!--I bring up these three stories just because I like them. OK, that's not entirely why. I like those anecdotes because in each I am occupying a different role, sometimes getting help, sometimes giving help (or, in the case of testing the quiz program, sometimes trying to break a friend's code in any way I can. And good news! I am very skilled at breaking code by doing the wrong thing, just like most end-users).

Also and more seriously: because in each, what we make with a little bit of teamwork is better than what we make alone.

Which brings me to the (slightly longer) anecdote I really want to tell you, about our morning coding challenge. (I could tell you about the bulk of today's work, working with Rails, but it's less anecdotable.

Today's coding challenge was to tell if a string was also a palindrome, disregarding non-letters and not paying attention to case. Pretty easy to get a rough version functioning: just downcase the string, use a regex to get rid of everything you don't want, make a copy that you reverse and compare them. Easy peasy--but not very nice.

(Aside: Nothing involving Regex is ever easy.)

One of my very algorithmically-minded peers had a different version, where you set an index at the beginning and at the end, and letter-by-letter, move to the middle of the word, checking that each letter is the same (after downcasing and skipping over non-letters). It was weird-looking, but super-efficient--except that he set a counter that incremented for each letter that matched and at the end of the loop, he checked that the counter was equal to half the string's length.

And suddenly I saw a way that we could skip all that and use a failure case to end the loop early, thus cutting out a few lines of code and stopping the function early if the string wasn't a palindrome. I was so excited by this that I almost ran to the board to ask our instructor if it would work. And here's a paraphrase:

"Together, this class created the most efficient version of this function."

Which I think is pretty neat, especially since we no longer have ping pong to bond us.

(Did I tell you that I miss ping pong?)

No comments:

Post a Comment