Image Provided By: www.StockMonkeys.com

December 31, 2014 by Daniel P. Clark

Do it for the puzzle!

Have you considered how much you enjoy a “good challenge”?  Do you recall as a child some one challenging your ability to do something?  Often it’s in our nature to say within ourselves “Challenge Accepted”.  We can use this nature for good.

If you run, do you run for exercise, distance, time, or something else?  Try running for each of the different reasons.  When you do it for exercise you will find yourself burdened by the task as you do it.  If you run for a distance you will find yourself doing decently for the first half plus, but as you get near the end then you get into a psychological “finish it strong”, or “I’m going to die but I’ve got to make it”.  The interesting thing with a fixed amount of time is that all the excuses go away.  It turns into a discipline of pacing yourself.  These facts can vary per person… but pay attention to your own mindset and how you perceive things and how it affects your performance.  The best way to run is to run for fun.  That will take a lot of habitual practice to get to a point where your mind and body are comfortable with it… but once you’re there the pain and burden is gone and you don’t want to stop.

Like running your perception will play into anything you do in life.  Your practice and habits you develop will also be key to mastery and enjoyment.  If you like a challenge, and you like puzzles, then continue to feed  your mind by giving it puzzles.

I’m always looking for something to intrigue my mind.  Some things fairly simple can lead to challenging puzzles.  For example.  As you may well know, Youtube hosts videos.  Those videos are mostly public but some are unlisted and some are private.  Well have you ever thought about stumbling across an unlisted video?  That’s a puzzle.

I myself thought this would be a great challenge so I used my own unlisted video as a template.  I figured out how to use Mechanize to pull a Youtube page and see if it said the video was unlisted.  Great!  That works.  So now how would you find another one?  Well if you pay attention to the links in the Youtube videos you’ll notice they are all 11 characters long.  And if you pay attention to how many characters are used you’ll find that there are 64 unique characters per video code.  So it would seem we could catalogue all unlisted Youtube videos by trying every possible combination of 11 character Base64 numbers.

Some of you may have already grasped the magnitude of the situation.  I didn’t figure that out until I had written some working scratch code.  I tested out about a 100 or so requests and didn’t even find a listed video.  Not only that, but the requests each take time.  If I can load 5 pages per second, how long will it take me to catalogue Youtube?

Here are the numbers.  If each video has 64 character possibilities per digit space then we multiply 64 to the 11th power.  That comes out to: 4,722,366,482,869,645,213,696 videos.  That’s over 4 sextillion.  After doing the math of loading so many pages per second I found it would take me over 3 trillion of my human years to complete it.  Even finding one video this way looks slim to nil.  So I decided this was in no way worthwhile to attempt.

But that didn’t stop my mind from churning over it.  For example, if there was a mesh network of many thousands of computers performing it, then something might turn up in my lifetime.  I think the idea feels uber cool.  But this would be highly frowned upon as this crosses over into territory of attackers on the internet.  So unless you are Google working on your own site, don’t do it.

Another thing that I saw as a challenge when looking into the Youtube video cataloguing was the question of whether the 11 digit codes had any repeating characters.  At the time I didn’t see any.  So I figured I could scrape off a trillion years if I ran through all Base64 permutations and thereby eliminating lots of checks.  This lead to some good work.  I found a project on github called Base62.  I then forked that project and rewrote it into BaseCustom: which allows you to define any base numbering system you want.  Video Example available.

As for permutations I opened up a Code Golf Challenge on a StackExchange site designed for puzzles and challenges.  That wasn’t a good experience.  Apparently the people who use that site have very low comprehension skills so you need to spell out EVERYTHING and make sure you use words common people wouldn’t recognize… geeky puzzle words.  But I was able to complete a Base 64 Permutation Golf Challenge.  I also opened up a StackOverflow question to which Cary Swoveland practically wrote a full book for an answer to Ruby: How do you set an Enumerator’s state?.  The issue was dealing with wasted CPU cycles and Ruby’s standard permutations not being able to handle how big Base64 made everything.

So I in no way catalogued Youtube.  But I got some great knowledge, experience, and built some great tools all in puzzling over the challenge.

Puzzles don’t have to be big.  Something simple like figuring out how many duplicate files you have on your computer.  You know you backup your media/photos so many times you have them in folders everywhere over the years.  Well you can write code for that, and I did that with Duplicate File Manager.  I wrote it to check in two different ways: one by file checksum, and the other by name.  It’s now a command line utility which may be helpful to many.

Twitter is both an easy resource, and a great one for challenges.  You can automate many things.  Just keep in mind you need to follow their rules and guidelines and it should be okay.

There are a couple of websites out there for puzzles.  Project Euler specializes in mathematical challenges beyond most humans ability.  So that leads you to write computer code to solve it.  You enter your answer and keep track of your progress there along the way.  They have over 300 challenges.  If you’d like something challenging yet not so mathematical you can use Puzzle Node.  I was part of a Ruby meetup who did challenge #11 of an ascii water fall challenge.  Here’s my repo on that Hitting Rock Bottom.  At the Ruby meetup we performed anonymous reviews of the code.  That was quite enjoyable.  One other cool puzzle site I’ve found is Ruby Quiz

There are so many things that can be a great challenge and learning experience.  Look for them and you will find them.  Go out and raise your awareness of alternate ways of doing things.  Different patterns and challenges make for new insights and perspectives.  If you can get a code puzzle buddy that would be most excellent!  Nothing like a little friendly competition.

gist.github.com is a great place for scratching through puzzles.  I tried refactoring an acquaintances script on Computing DNA Hamming Pairings.  On that gist you can click on the revision history and see changes over time.  So it’s a bit like a documentary.  Another way you can go about it is to write comments on your own snippet like my Refactoring Complexity out of a Game Object.  In this example I asked another acquaintance on Twitter for some input and insights on how I might go about improving it.  So my comments were like “I’m just thinking out loud.”  I feel I prefer this method.  Ask some one a question from a gist on Twitter, and then while you wait for a response feel free to “Think out loud” on it.  It’s helpful when you’re able to talk through a process.  Even if another person doesn’t see it.

I see coding as a fun challenge.  Detective work of a mostly refreshing nature.  Just like with running, your mindset will “make you” when it comes to programming.  Don’t burn yourself out.  Look for the interesting and tinker away!

I hope you enjoyed this!  Happy Coding! Please comment, share, subscribe to my RSS Feed, and follow me on twitter @6ftdan!

God Bless!
-Daniel P. Clark

Image Provided By: www.StockMonkeys.com

#challenge#golf#methodology#mindset#programming#puzzle#thinking

Leave a Reply

avatar
  Subscribe  
Notify of