[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

shortest nozero ruby quine

meinrad recheis

10/18/2003 9:28:00 AM


> :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...)

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?...

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

12 Answers

Melanie Fielder

10/18/2003 10:26:00 AM

0

"henon" <meinrad.recheis@gmx.at> skrev i en meddelelse
news:qI7kb.68322$Lo.1167263@news.chello.at...
> 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 ;-)

--
Simon Strandgaard


sabbyxtabby

10/18/2003 3:30:00 PM

0

henon <meinrad.recheis@gmx.at> wrote:

> 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.

aero6dof

10/18/2003 6:43:00 PM

0

henon <meinrad.recheis@gmx.at> wrote in message news:<qI7kb.68322$Lo.1167263@news.chello.at>...

> 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

gabriele renzi

10/18/2003 10:24:00 PM

0

il 18 Oct 2003 11:43:15 -0700, aero6dof@yahoo.com (Alan Chen) ha
scritto::

>henon <meinrad.recheis@gmx.at> wrote in message news:<qI7kb.68322$Lo.1167263@news.chello.at>...
>
>> 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?
I suppose it is cheating :)
OTOH, if this was not cheating you could just do
print IO.read($0)

meinrad recheis

10/19/2003 10:59:00 AM

0

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


meinrad recheis

10/19/2003 11:11:00 AM

0

Sabby and Tabby wrote:

> henon <meinrad.recheis@gmx.at> 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.

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

meinrad recheis

10/19/2003 11:14:00 AM

0

Sean Ross wrote:

[...]
>>
>>Hi. This is the shortest Python quine that I'm aware of (29 characters):
>>
>>_='_=%r;print _%%_';print _%_
>>
>
doesn't print (in python) add a newline? then strictly spoken this has
30 chars.

-- henon

sabbyxtabby

10/20/2003 6:58:00 AM

0

henon <meinrad.recheis@gmx.at> wrote:

> 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.
>
> 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

Kero van Gelder

10/22/2003 10:26:00 PM

0

>> 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?

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 ----------------------- kero@chello.nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k... ---+

Alan Davies

10/23/2003 12:06:00 PM

0

Sabby and Tabby wrote:
> 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!