Monday, August 20, 2012

August 20 - About quines

I've started to do daily programming puzzles.  They have been helping me hone my programming / reasoning skills.  I'm going to start using the daily puzzles to learn other languages as well since I think it will be good to learn the constructs of other languages this way (even the smallest puzzles exercise my knowledge of C++ STl...not much, but I were new to C/C++ I would have a hard time).

So the website I've been looking at is http://sixrevisions.com/resources/10-puzzle-websites-to-sharpen-your-programming-skills/ , specifically the first link has tiny little puzzles on it.

So far I've done two from this website (Sum4, Scalar Product), each of them taking a short while to think and program up.  They are essentially interview questions. 

The other day while reading Ken Thompson's Touring Award speech "Trusting Trust", and I encountered the Quine...a self-reproducing program.  For example, in C, you would write a C program that when compiled would produce the original source, character-for-character.  This sounds easy, but the naive way to go about solving this will show you that it's a little trickier than it sounds.  Anyways, after a canceled flight at DFW airport and a stay in the Holiday Inn Express, I gave it a try.  I figured out the solution, and I got it working the next day,  It's suprisingly simple once you figure it out...but I saw some of the other results (in C) and it amazed me at just how small you can get the program.  In fact, this used to be a little game with Ken Thompson and Dennis Ritchie when they were in College.  They used to see how small of a Quine they could produce.  This also led me to the discovery of "multiquines":  A program written in one language produces source code for another language, which if compiled in run would reproduce the original language's source code...this is so cool!!! I might try it some day.   For now, I must move on to work on Oblivion Wars...good day.

No comments:

Post a Comment