Professional Web Applications Themes

shortest nozero ruby quine - Ruby

> :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 [url]http://www.nyx.net/~gthompso/quine.htm[/url]) 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. ...

  1. #1

    Default shortest nozero ruby quine

    > :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 [url]http://www.nyx.net/~gthompso/quine.htm[/url])
    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:

    [url]http://www.rubygarden.org/ruby?RubyQuines[/url]

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

    henon Guest

  2. #2

    Default Re: shortest nozero ruby quine

    "henon" <meinrad.recheisgmx.at> skrev i en meddelelse
    news:qI7kb.68322$Lo.1167263news.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


    Simon Strandgaard Guest

  3. #3

    Default Re: shortest nozero ruby quine

    henon <meinrad.recheisgmx.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.
    Sabby and Tabby Guest

  4. #4

    Default Re: shortest nozero ruby quine

    henon <meinrad.recheisgmx.at> wrote in message news:<qI7kb.68322$Lo.1167263news.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
    Alan Chen Guest

  5. #5

    Default Re: shortest nozero ruby quine

    il 18 Oct 2003 11:43:15 -0700, [email]aero6dof[/email] (Alan Chen) ha
    scritto::
    >henon <meinrad.recheisgmx.at> wrote in message news:<qI7kb.68322$Lo.1167263news.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)

    gabriele renzi Guest

  6. #6

    Default Re: shortest nozero ruby quine

    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 Guest

  7. #7

    Default Re: shortest nozero ruby quine

    Sabby and Tabby wrote:
    > henon <meinrad.recheisgmx.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

    henon Guest

  8. #8

    Default Re: shortest nozero ruby quine

    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 Guest

  9. #9

    Default Re: shortest nozero ruby quine

    henon <meinrad.recheisgmx.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
    Sabby and Tabby Guest

  10. #10

    Default Re: shortest nozero ruby quine

    >> 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 ----------------------- [email]kerochello.nl[/email] ---+
    | all the meaningless and empty words I spoke |
    | Promises -- The Cranberries |
    +--- M38c --- [url]http://httpd.chello.nl/k.vangelder[/url] ---+

    Kero Guest

  11. #11

    Default Re: shortest nozero ruby quine

    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 Guest

  12. #12

    Default Re: shortest nozero ruby quine

    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 Guest

  13. #13

    Default Re: shortest nozero ruby quine

    In article <3F97C421.3010504yahoo.co.ukNOSPAM>, 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 Guest

  14. #14

    Default Re: shortest nozero ruby quine

    "henon" <meinrad.recheisgmx.at> wrote in message
    news:qI7kb.68322$Lo.1167263news.chello.at...
    > 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 Guest

  15. #15

    Default Re: shortest nozero ruby quine


    "Sean Ross" <srossconnectmail.carleton.ca> wrote in message
    news:Zwdkb.12975$PM2.1448514news20.bellglobal.com ...
    > "henon" <meinrad.recheisgmx.at> wrote in message
    > news:qI7kb.68322$Lo.1167263news.chello.at...
    > > 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
    [url]http://radio.weblogs.com/0104369/[/url]. 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 Guest

Similar Threads

  1. Replies: 0
    Last Post: November 1st, 05:21 PM
  2. Replies: 1
    Last Post: October 29th, 07:52 PM
  3. ruby-talk: 80813 (Rite/Ruby2.0 & Ruby vs OCaml)
    By Steven Lumos in forum Ruby
    Replies: 0
    Last Post: October 9th, 10:21 PM
  4. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139