

An Interview Question That Prints Out Its Own Source Code (In Ruby) - skorks
http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/

======
jared314
Another "How would you move Mount Fuji?" interview question. If only people
would realize they don't need someone to move Mount Fuji.

------
koenigdavidmj
Hint in Perl, Python, or Ruby: blank programs are valid.

~~~
lsb
Given how nitpicky the rules for quines are, this would be valid unless a non-
zero-length source was mandatory.

------
1331
Check out this "quine relay!" <http://d.hatena.ne.jp/ku-ma-me/20090916/p1>

The Ruby program outputs Python that outputs Perl that outputs Lua that
outputs OCaml that outputs Haskell that outputs C that outputs Java that
outputs Brainfuck that outputs Whitespace that outputs Unlambda that outputs
the original Ruby program.

(I was unable to get it to work when I tested it, but I still find it quite
impressive!)

------
jchonphoenix
So here is a much more interesting problem. Can you code a program that runs a
function on its own source code?

Hint: It is a generalization of a quine.

------
raganwald
I've heard of a quine but only confuse myself trying to think of a way to
write one in Ruby that doesn't involve something like eval-ing strings. Reg
Braithwaite -> FAIL.

That being said, something tickles the back of my head... Are quines
combinatorial? Something about a program that prints its own source code makes
me think of some of Raymond Smullyan's various problems in the field...

~~~
cschneid
My first thought was to parse the AST, then print it back out. No string
manipulation needed. (at least not fancy)

------
techiferous
Dang, I would've failed that interview question. Fortunately, my day-to-day
work doesn't involve writing quines as much as trying to configure the right
versions of Ruby, Postgres, and Rails 3. Wait--I'm failing at that one, too...
;)

------
paulbaumgart
Handy Bash function for testing your quine:

    
    
      function quine_test { diff <(ruby $1) <(cat $1); }
    

Usage:

    
    
      $ quine_test quine.rb

------
timmorgan
Cool because I had never heard of a quine before (so I guess I would probably
fail the interview question).

~~~
erlanger
The better for you. I can't juggle but I don't think that will exclude me from
any jobs worth having.

