danmcb
May 31, 2009, 6:31pm
21
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
â
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]
danmcb
May 31, 2009, 7:11pm
22
Robert D. [email protected] writes:
Ok, the shortest solution did not have much success, what about a long
one then
http://pastie.org/495692
$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
danmcb
May 31, 2009, 2:25pm
23
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
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]
danmcb
May 31, 2009, 11:34pm
24
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
danmcb
May 31, 2009, 7:26pm
25
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
â
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]
danmcb
June 1, 2009, 5:17am
26
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 <
danmcb
June 1, 2009, 5:01am
27
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.
danmcb
June 1, 2009, 6:00am
28
Is using File considered cheating?
puts File.readlines __FILE__
On Mon, Jun 1, 2009 at 11:17 AM, Aureliano C.
danmcb
June 1, 2009, 6:31am
29
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}
danmcb
June 1, 2009, 5:17am
30
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.
danmcb
June 1, 2009, 7:59am
31
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
â
danmcb
June 1, 2009, 7:48am
32
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
danmcb
June 1, 2009, 2:40pm
33
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
danmcb
June 1, 2009, 2:48pm
34
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
danmcb
June 1, 2009, 3:18pm
35
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.
danmcb
June 1, 2009, 3:37pm
36
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
xxx | ruby | diff -u xxx -
N.B. this â>â ainât a quote
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]
danmcb
June 1, 2009, 3:54pm
37
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
Sure - the trivial quine is valid. I can also run it on my network which
has zero nodes.
danmcb
June 1, 2009, 4:56pm
38
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.
danmcb
June 1, 2009, 4:56pm
39
On Mon, Jun 1, 2009 at 3:54 PM, Brian C. [email protected]
wrote:
Good thinking, but the âoptimalâ solution still passes
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]
danmcb
June 1, 2009, 6:30pm
40
Many of these were far more interesting than mine, but itâs available
here:
Nice work everyone!
-Dana