开发者

Shortest Ruby Quine [closed]

开发者 https://www.devze.com 2022-12-23 16:33 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discuss开发者_高级运维ion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/

In it, the author argues the case for using a quine as an interview question. I'm not sure I agree but thats not what this question is about.

He goes on to construct a quine in Ruby and refactor it to make it shorter. He then challenges the reader to try to make it even shorter.

I played around with it for a while and came up with the following:

s="s=;puts s[0,2]+34.chr+s+34.chr+s[2,36]";puts s[0,2]+34.chr+s+34.chr+s[2,36]

This is the first time I have ever attempted a quine and I can't figure out how to make it any shorter.

What is the shortest Ruby quine you can come up with? Please post an explanation if your implementation requires it.


Unfortunately RubyGarden doesn't exist anymore. Here are a couple of links to make up for it (the one Kevin posted is not the shortest one anymore by the way):

The first quines in Ruby

s="s=%c%s%c; printf s,34,s,34,10%c"; printf s,34,s,34,10

ruby quine slightly smaller than python quine

_="_=%p;puts _%%_";puts _%_

shortest nozero [sic!] ruby quine

puts <<2*2,2
puts <<2*2,2
2


Even shorter:

$><<IO.read($0)

15 characters, not including the newline

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号