shortest nozero ruby quine

H

henon

:quine: /kwi:n/ /n./ [from the name of the logician Willard van Orman
Quine, via Douglas Hofstadter] A program that generates a copy of its
own source text as its complete output. Devising the shortest
possible quine in some given programming language is a common hackish
amusement. (see http://www.nyx.net/~gthompso/quine.htm)

hi,

i have created this quine of length 32 and i believe that a
nonzero-ruby-quine cannot be shorter and more in the spirit of ruby than
that:

eval s=%q(puts"eval s=%q(#{s})")

until anyone comes up with a shorter nonzero quine i claim this to be
the shortest nonzero-ruby-quine.
it's even shorter than the shortest (i know of) in python:
l='l=%s;print l%%`l`';print l%`l`
which has 33 characters.

i have created a rubygarden wiki page for quines:

http://www.rubygarden.org/ruby?RubyQuines

you can see there ruby-quines i found qoogling the web
cheers,
-- henon
 
S

Simon Strandgaard

henon said:
i have created this quine of length 32 and i believe that a
nonzero-ruby-quine cannot be shorter and more in the spirit of ruby than
that:

eval s=%q(puts"eval s=%q(#{s})")


Nice.. compared to most other quine's this one is actually very readable.
Quine's is a very interesting science, keep up the good work ;-)
 
S

Sabby and Tabby

henon said:
i have created this quine of length 32 and i believe that a
nonzero-ruby-quine cannot be shorter and more in the spirit of ruby than
that:

eval s=%q(puts"eval s=%q(#{s})")

until anyone comes up with a shorter nonzero quine i claim this to be
the shortest nonzero-ruby-quine.

Well, technically, your quine is 33 characters in length; the output
includes a "\n" at the end, so the source must also. Using a global
variable shortens it by one character:

eval$s=%q(puts"eval$s=%q(#$s)")

A Ruby version of Robin Houston's Perl quine is 31 characters:

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


Note that there is a blank line (or two "\n") at the end.
 
A

Alan Chen

henon said:
i have created this quine of length 32 and i believe that a
nonzero-ruby-quine cannot be shorter and more in the spirit of ruby than
that:

eval s=%q(puts"eval s=%q(#{s})")

until anyone comes up with a shorter nonzero quine i claim this to be
the shortest nonzero-ruby-quine.

How about:

puts open($0).gets

Or is it cheating to use file io?

Cheers,
- alan
 
G

gabriele renzi

il 18 Oct 2003 11:43:15 -0700, (e-mail address removed) (Alan Chen) ha
scritto::
How about:

puts open($0).gets

Or is it cheating to use file io?
I suppose it is cheating :)
OTOH, if this was not cheating you could just do
print IO.read($0)
 
H

henon

Sabby and Tabby wrote:
[...]
A Ruby version of Robin Houston's Perl quine is 31 characters:

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


Note that there is a blank line (or two "\n") at the end.

sorry, but i get a syntax error with yours:
can't find string "" anywhere before EOF
 
H

henon

Sabby said:
A Ruby version of Robin Houston's Perl quine is 31 characters:

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


Note that there is a blank line (or two "\n") at the end.

wow this is very cool. you beat me by one character.
i knew someone would come up with a shorter one!! i put it on the
RubyQuines wiki page.

cheers,
- henon
 
H

henon

Sean Ross wrote:

[...]doesn't print (in python) add a newline? then strictly spoken this has
30 chars.

-- henon
 
S

Sabby and Tabby

henon said:
wow this is very cool. you beat me by one character.
i knew someone would come up with a shorter one!! i put it on the
RubyQuines wiki page.

Wiki formatting is strange. Here's a shorter, non-italic variation:

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

Kero

eval s=%q(puts"eval s=%q(#{s})")
How about:

puts open($0).gets

Or is it cheating to use file io?

Wouldn't call this cheating per se, but it doesn't run in irb and
doesn't run from the command line, whereas the others do...

+--- Kero ----------------------- (e-mail address removed) ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k.vangelder ---+
 
A

Alan Davies

Sabby said:
Wiki formatting is strange. Here's a shorter, non-italic variation:

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

Can someone explain how this works? I am completely lost!
 
A

Alan Davies

Sabby said:
Wiki formatting is strange. Here's a shorter, non-italic variation:

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

Can someone explain how this works? I am completely lost!
 
J

Jason Williams

Can someone explain how this works? I am completely lost!

"puts <<2" - print all the text from after this statement until you
reach the string "2".

...."*2" - Print that string twice
....",2" - And then print the value 2

The second "puts <<2*2,2" is just text, and the final "2" is the
delimiter.

Something like that, anyway :)
 
S

Sean Ross

henon said:
it's even shorter than the shortest (i know of) in python:
l='l=%s;print l%%`l`';print l%`l`
which has 33 characters.

Hi. This is the shortest Python quine that I'm aware of (29 characters):

_='_=%r;print _%%_';print _%_
 
S

Sean Ross

Sean Ross said:
Hi. This is the shortest Python quine that I'm aware of (29 characters):

_='_=%r;print _%%_';print _%_

And, if you want to cheat a little, check out this log entry
http://radio.weblogs.com/0104369/. If you include interactive mode on the
python interpreter, then strictly speaking, the shortest quine in Python
(and in Ruby, I suspect) will be to hit the enter key ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top