[QUIZ] Quine (#207)

Ha, I just made one with 0 chars. Top that!

Hehe.

We did quines on ruby-talk back in 2002, and that is
indeed where we ended up.

(Although, personally, I tend to find nonzero length
quines more interesting) ;D

Regards,

Bill

···

From: "Sebastian Hungerecker" <sepp2k@googlemail.com>

Bill Kelly <billk@cts.com> writes:

From: "Pascal J. Bourguignon" <pjb@informatimago.com>

I've got one that is more than 40 characters, but it's _readable_!

Did you mean: ((I've got (one)) (that is more than ((40) characters)), ((but) (it's _readable_!)) ?

:wink:

Well I could have done something like that, yes, but I restrained myself this time :slight_smile:

Too bad we've got only oneliners, a subsidiary questions would have
been to produce a reversed quine, a quine that outputs the source
lines in the reverse order. (In C it's funny).

···

--
__Pascal Bourguignon__

Bill Kelly wrote:

From: "Pascal J. Bourguignon" <pjb@informatimago.com>

I've got one that is more than 40 characters, but it's _readable_!

Did you mean: ((I've got (one)) (that is more than ((40) characters)), ((but) (it's _readable_!)) ?

:wink:

There is only one way to respond to that mess of redundant )

(
   (I've got
     (one
   (that is more than
     (
       (40
       characters,
   (
     (but
     (it's _readable_!

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Ok, I'm at 17 if I ***cheat*** & assume *NIX.
and 28 if I don't cheat.

Still kinda fun, though.... the one at 28 bytes is not anything I'd use in real life, however. Definitely not maintainable.

Matt

···

--
"... if you do follow your bliss you put yourself on a kind of
track that has been there all the while, waiting for you, and the life
that you ought to be living is the one you are living. When you can
see that, you begin to meet people who are in your field of bliss, and
they open doors to you. I say, follow your bliss and don't be afraid,
and doors will open where you didn't know they were going to be." --
Joseph Campbell

On Sat, 30 May 2009, Matthew K. Williams wrote:

I've got one that's 197 characters, but it:

+ is readable and formatted nicely
+ uses gems
+ uses a class
+ shows the inheritence of said class
+ has more than one instance of "end"
+ took me less than 5 minutes to write

:wink:

Now to try for brevity....

Matt
--
"... if you do follow your bliss you put yourself on a kind of
track that has been there all the while, waiting for you, and the life
that you ought to be living is the one you are living. When you can
see that, you begin to meet people who are in your field of bliss, and
they open doors to you. I say, follow your bliss and don't be afraid,
and doors will open where you didn't know they were going to be." --
Joseph Campbell

On Sat, 30 May 2009, Pascal J. Bourguignon wrote:

Sebastian Hungerecker <sepp2k@googlemail.com> writes:

Am Samstag 30 Mai 2009 02:17:54 schrieb Sebastian Hungerecker:

14 if it only needs to run on unixoid-systems.

Well, 15 if it needs to work correctly :wink:

I've got one that is more than 40 characters, but it's _readable_!

--
__Pascal Bourguignon__

0 bytes, what else?

And how do you execute it and prove it works, mon ami? <G>

···

On Sat, May 30, 2009 at 6:18 PM, Robert Dober <robert.dober@gmail.com> wrote:

0 bytes, what else?

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

I'd show you but the spoiler-free period hasn't expired yet :slight_smile:

martin

···

On Sun, May 31, 2009 at 3:51 AM, Rick DeNatale <rick.denatale@gmail.com> wrote:

On Sat, May 30, 2009 at 6:18 PM, Robert Dober <robert.dober@gmail.com> wrote:

0 bytes, what else?

And how do you execute it and prove it works, mon ami? <G>

I have foreseen everything :wink:

507/7 > touch prog && ruby prog > xxx && diff prog xxx
robert@roma:~/log/ruby/quiz 14:24:48
508/8 > echo $?
0

···

On Sun, May 31, 2009 at 12:21 AM, Rick DeNatale <rick.denatale@gmail.com> wrote:

On Sat, May 30, 2009 at 6:18 PM, Robert Dober <robert.dober@gmail.com> wrote:

0 bytes, what else?

And how do you execute it and prove it works, mon ami? <G>

--
Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exupéry]

Ok, the shortest solution did not have much success, what about a long
one then :wink:

http://pastie.org/495692

Cheers
Robert

Bummer I forgot that there is only one program of size 0, apologies :wink:

···

On Sun, May 31, 2009 at 12:34 AM, Martin DeMello <martindemello@gmail.com> wrote:

On Sun, May 31, 2009 at 3:51 AM, Rick DeNatale <rick.denatale@gmail.com> wrote:

On Sat, May 30, 2009 at 6:18 PM, Robert Dober <robert.dober@gmail.com> wrote:

0 bytes, what else?

And how do you execute it and prove it works, mon ami? <G>

I'd show you but the spoiler-free period hasn't expired yet :slight_smile:

martin

--
Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exupéry]

Robert Dober <robert.dober@gmail.com> writes:

Ok, the shortest solution did not have much success, what about a long
one then :wink:

http://pastie.org/495692

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----

···

-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----

--
__Pascal Bourguignon__

Robert Dober <robert.dober@gmail.com> writes:

Ok, the shortest solution did not have much success, what about a long
one then :wink:

http://pastie.org/495692

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----

Seems you managed without parens :wink:

···

On Sun, May 31, 2009 at 7:10 PM, Pascal J. Bourguignon <pjb@informatimago.com> wrote:

--
__Pascal Bourguignon__

--
Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exupéry]

Here is a variant version of the above:

puts (_="puts (_=%c%s%c)%%[34,_,34]")%[34,_,34]

Regards,
Park Heesob

···

2009/6/1 Pascal J. Bourguignon <pjb@informatimago.com>:

Robert Dober <robert.dober@gmail.com> writes:

Ok, the shortest solution did not have much success, what about a long
one then :wink:

http://pastie.org/495692

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----

I did something like that, but with parenthesis.

s="s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)

It is based on the C quine that uses printf on the wikipedia page.

···

On Sun, May 31, 2009 at 2:10 PM, Pascal J. Bourguignon < pjb@informatimago.com> wrote:

Robert Dober <robert.dober@gmail.com> writes:

> Ok, the shortest solution did not have much success, what about a long
> one then :wink:
>
> http://pastie.org/495692

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----

--
__Pascal Bourguignon__

And I did one with a carriage return:

s="s=%c%s%c;printf(s,34,s,34,13,10)%c%c";printf(s,34,s,34,13,10)

A little longer but looks nicer

···

On Mon, Jun 1, 2009 at 12:16 AM, Aureliano Calvo <aurelianocalvo@gmail.com>wrote:

I did something like that, but with parenthesis.

s="s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)

It is based on the C quine that uses printf on the wikipedia page.

On Sun, May 31, 2009 at 2:10 PM, Pascal J. Bourguignon < > pjb@informatimago.com> wrote:

Robert Dober <robert.dober@gmail.com> writes:

> Ok, the shortest solution did not have much success, what about a long
> one then :wink:
>
> http://pastie.org/495692

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----
q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
-----

--
__Pascal Bourguignon__

Is using File considered cheating?

    puts File.readlines __FILE__

···

On Mon, Jun 1, 2009 at 11:17 AM, Aureliano Calvo <aurelianocalvo@gmail.com>wrote:

And I did one with a carriage return:

s="s=%c%s%c;printf(s,34,s,34,13,10)%c%c";printf(s,34,s,34,13,10)

A little longer but looks nicer

On Mon, Jun 1, 2009 at 12:16 AM, Aureliano Calvo > <aurelianocalvo@gmail.com>wrote:

> I did something like that, but with parenthesis.
>
> s="s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)
>
> It is based on the C quine that uses printf on the wikipedia page.
>
>
>
> On Sun, May 31, 2009 at 2:10 PM, Pascal J. Bourguignon < > > pjb@informatimago.com> wrote:
>
>> Robert Dober <robert.dober@gmail.com> writes:
>>
>> > Ok, the shortest solution did not have much success, what about a long
>> > one then :wink:
>> >
>> > http://pastie.org/495692
>>
>>
>> $ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
>> -----
>> q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
>> -----
>> q=34;printf a="q=34;printf a=%c%s%c,q,a,q;puts",q,a,q;puts
>> -----
>>
>>
>>
>>
>>
>> --
>> __Pascal Bourguignon__
>>
>>
>

--
jorrel

Version 1: The "pretty" one with 'end's

require 'rubygems'
require 'ruby2ruby'

class Quine < Object
  def initialize
    puts "require 'rubygems'\nrequire 'ruby2ruby'\n#{Ruby2Ruby.translate
self.class}\nQuine.new\n"
  end
end
Quine.new

Version two, much less maintainable:

a="a=%p;puts a%%a";puts a%a

Version 3, cheating (unix only):

puts `cat #{$0}`

It usually is, yes. Your version can be shortened though:

   puts File.read __FILE__

You can also do it more creatively, if a bit longer:

   DATA.rewind
   puts DATA.read
   __END__

James Edward Gray II

···

On May 31, 2009, at 10:59 PM, Jorrel wrote:

Is using File considered cheating?

   puts File.readlines __FILE__

here's my extremely cheating 10-byte version:

# sudo ln -s /bin/cat /usr/local/bin/c
# echo | ruby -p q.rb
$_=`c #$0`

martin

···

On Mon, Jun 1, 2009 at 10:00 AM, Matthew Williams <matt@harpstar.com> wrote:

Version 3, cheating (unix only):

puts `cat #{$0}`

The problem with that is that it won't work when the file name contains spaces
or shell meta-characters. This will however:
system"cat",$0

···

Am Montag 01 Juni 2009 06:30:16 schrieb Matthew Williams:

puts `cat #{$0}`