最短的Ruby Quine [英] Shortest 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.
他继续在Ruby中构建一个Quine,并对其进行重构以使其更短.然后,他向读者提出挑战,力求使其更短一些.
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.
您能想到的最短的Ruby Quine是什么?如果您的实现需要,请发布说明.
What is the shortest Ruby quine you can come up with? Please post an explanation if your implementation requires it.
推荐答案
不幸的是,RubyGarden不再存在.这里有一些链接可以弥补这一点(顺便说一句,凯文发布的链接不再是最短的链接了):
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):
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 _%_
puts <<2*2,2
puts <<2*2,2
2
这篇关于最短的Ruby Quine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!