shortest nozero ruby quine

Discussion in 'Ruby' started by henon, Oct 18, 2003.

  1. henon

    henon Guest


    > :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
    henon, Oct 18, 2003
    #1
    1. Advertising

  2. "henon" <> skrev i en meddelelse
    news:qI7kb.68322$...
    > 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
    Simon Strandgaard, Oct 18, 2003
    #2
    1. Advertising

  3. henon <> 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.
    Sabby and Tabby, Oct 18, 2003
    #3
  4. henon

    Alan Chen Guest

    henon <> wrote in message news:<qI7kb.68322$>...

    > 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
    Alan Chen, Oct 18, 2003
    #4
  5. il 18 Oct 2003 11:43:15 -0700, (Alan Chen) ha
    scritto::

    >henon <> wrote in message news:<qI7kb.68322$>...
    >
    >> 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)
    gabriele renzi, Oct 18, 2003
    #5
  6. henon

    henon Guest

    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
    henon, Oct 19, 2003
    #6
  7. henon

    henon Guest

    Sabby and Tabby wrote:

    > henon <> 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
    henon, Oct 19, 2003
    #7
  8. henon

    henon Guest

    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
    henon, Oct 19, 2003
    #8
  9. henon <> 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
    Sabby and Tabby, Oct 20, 2003
    #9
  10. henon

    Kero Guest

    >> 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 ----------------------- ---+
    | all the meaningless and empty words I spoke |
    | Promises -- The Cranberries |
    +--- M38c --- http://httpd.chello.nl/k.vangelder ---+
    Kero, Oct 22, 2003
    #10
  11. henon

    Alan Davies Guest

    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!
    Alan Davies, Oct 23, 2003
    #11
  12. henon

    Alan Davies Guest

    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!
    Alan Davies, Oct 23, 2003
    #12
  13. In article <>, Alan Davies wrote:
    > 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!


    "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 :)
    Jason Williams, Oct 23, 2003
    #13
  14. henon

    Sean Ross Guest

    "henon" <> wrote in message
    news:qI7kb.68322$...
    > 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 _%_
    Sean Ross, Dec 18, 2003
    #14
  15. henon

    Sean Ross Guest

    "Sean Ross" <> wrote in message
    news:Zwdkb.12975$...
    > "henon" <> wrote in message
    > news:qI7kb.68322$...
    > > 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 _%_
    >


    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 ;)
    Sean Ross, Dec 18, 2003
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Emlyn Corrin

    C++ quine

    Emlyn Corrin, Sep 15, 2003, in forum: C++
    Replies:
    10
    Views:
    2,891
    Emlyn Corrin
    Sep 16, 2003
  2. singlepoint

    Quine

    singlepoint, Mar 20, 2007, in forum: C Programming
    Replies:
    11
    Views:
    746
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
    Mar 21, 2007
  3. Daniel Pitts

    Short Java Quine.

    Daniel Pitts, Feb 14, 2008, in forum: Java
    Replies:
    11
    Views:
    3,195
    Daniele Futtorovic
    Feb 15, 2008
  4. Limo Driver

    Shortest Ruby crash #49

    Limo Driver, Aug 19, 2008, in forum: Ruby
    Replies:
    13
    Views:
    208
    Charles Oliver Nutter
    Aug 20, 2008
  5. Daniel Moore

    [QUIZ] Quine (#207)

    Daniel Moore, May 29, 2009, in forum: Ruby
    Replies:
    42
    Views:
    462
    serialhex
    Dec 24, 2010
Loading...

Share This Page