4 ms·
An Interview Question That Prints Out Its Own Source Code (In Ruby)
- timmorgan 17y agoCool because I had never heard of a quine before (so I guess I would probably fail the interview question).
- erlanger 17y agoThe better for you. I can't juggle but I don't think that will exclude me from any jobs worth having.
- koenigdavidmj 17y agoHint in Perl, Python, or Ruby: blank programs are valid.
- lsb 17y agoGiven how nitpicky the rules for quines are, this would be valid unless a non-zero-length source was mandatory.
- jared314 17y agoAnother "How would you move Mount Fuji?" interview question. If only people would realize they don't need someone to move Mount Fuji.
- raganwald 17y agoI'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 17y agoMy first thought was to parse the AST, then print it back out. No string manipulation needed. (at least not fancy)
- techiferous 17y agoDang, 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 17y agoHandy Bash function for testing your quine: function quine_test { diff <(ruby $1) <(cat $1); } Usage: $ quine_test quine.rb
- jchonphoenix 17y agoSo 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.
- 1331 17y agoCheck out this "quine relay!" http://d.hatena.ne.jp/ku-ma-me/20090916/p1 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!)