Quine (#207)

On Sun, May 31, 2009 at 12:34 AM, Martin DeMello
[email protected] wrote:

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

–
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 D. [email protected] 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 -----

On Sun, May 31, 2009 at 12:21 AM, Rick DeNatale
[email protected] wrote:

On Sat, May 30, 2009 at 6:18 PM, Robert D. [email protected] wrote:

0 bytes, what else?

And how do you execute it and prove it works, mon ami?
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

–
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]

From: “Bill K.” [email protected]

I have 30 characters, w/out cheating. It does output a warning
on 1.8.6, but not 1.8.7 or 1.9.1. (And since the warning is on
stderr, it doesn’t affect the quine output really, I guess.)

Here 'tis. It’s 29 characters plus a linefeed.

p eval _=“print’p eval =';”

Regards,

Bill

On Sun, May 31, 2009 at 7:10 PM, Pascal J. Bourguignon
[email protected] wrote:

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:

–
Pascal B.

–
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]

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 <

2009/6/1 Pascal J. Bourguignon [email protected]:

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

Here is a variant version of the above:

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

Regards,
Park H.

Is using File considered cheating?

puts File.readlines __FILE__

On Mon, Jun 1, 2009 at 11:17 AM, Aureliano C.

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}

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

On May 31, 2009, at 10:45 PM, Martin DeMello wrote:

echo | ruby -p q.rb

$_=c #$0

martin

That was essentially my original cheat, then my friend pointed out
this simple modification to get to 8 bytes:

cat a
$><<a

ruby a
$><<a

which a
/usr/local/bin/a

cat which a
#!/usr/bin/env ruby
puts ‘$><<a’

  • Josh

On Mon, Jun 1, 2009 at 10:00 AM, Matthew W. [email protected]
wrote:

Version 3, cheating (unix only):

puts cat #{$0}

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

Am Montag 01 Juni 2009 06:30:16 schrieb Matthew W.:

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

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

Is using File considered cheating?

puts File.readlines FILE

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

James G. wrote:

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

Is using File considered cheating?

puts File.readlines FILE

It usually is, yes.

I’d suggest you pipe the source code into the ruby interpreter:

cat quine.rb | ruby

cat quine.rb | ruby | diff -u quine.rb -

That eliminates tricks with FILE and $0.

On Mon, Jun 1, 2009 at 3:20 PM, Brian C. [email protected]
wrote:

cat quine.rb | ruby

cat quine.rb | ruby | diff -u quine.rb -

That eliminates tricks with FILE and $0.

Good thinking, but the “optimal” solution still passes :wink:

xxx | ruby | diff -u xxx -

N.B. this “>” ain’t a quote :wink:
Robert

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 D. wrote:

On Mon, Jun 1, 2009 at 3:20 PM, Brian C. [email protected]
wrote:

ĂŻÂżÂœ ĂŻÂżÂœcat quine.rb | ruby

ĂŻÂżÂœ ĂŻÂżÂœcat quine.rb | ruby | diff -u quine.rb -

That eliminates tricks with FILE and $0.

Good thinking, but the “optimal” solution still passes :wink:

Sure - the trivial quine is valid. I can also run it on my network which
has zero nodes.

Brian C. [email protected] writes:

cat quine.rb | ruby

cat quine.rb | ruby | diff -u quine.rb -

That eliminates tricks with FILE and $0.

A better solution would be to compile the ruby program. Then $0 would
be a binary file and that trick would fail.

On Mon, Jun 1, 2009 at 3:54 PM, Brian C. [email protected]
wrote:

Good thinking, but the “optimal” solution still passes :wink:

Sure - the trivial quine is valid. I can also run it on my network which
has zero nodes.
True but you cannot test it on your network with zero nodes, but I
have a network with zero nodes too, maybe we can come up with
something like Map Reduce ( or was that Collect Inject :-O)

Posted via http://www.ruby-forum.com/.

–
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]

Many of these were far more interesting than mine, but it’s available
here:

Nice work everyone!

-Dana