刚刚读完这篇博文:http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/
中在此,作者论证了使用奎因作为访谈问题的理由。我不确定我是否同意,但这不是这个问题的目的。
他继续用 Ruby 构建了一个 quine 并重构它以使其更短。然后他要求读者尽量把它写得更短。
我玩了一段时间,得出了以下结论:
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]
这是我第一次尝试 quine,我不知道如何让它变得更短。
你能想出的最短的 Ruby quine 是什么?如果您的实现需要,请发布解释。
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.
发布评论
评论(2)
不幸的是 RubyGarden 已经不存在了。这里有几个链接可以弥补这一点(顺便说一句,Kevin 发布的链接不再是最短的):
Ruby 中的第一个 quines
ruby quine 略小于 python quine
最短的 nozero [原文如此!] ruby quine
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
ruby quine slightly smaller than python quine
shortest nozero [sic!] ruby quine
更短:
15 个字符,不包括换行符
Even shorter:
15 characters, not including the newline