[QUIZ] Quine (#207)

R

Robert Dober

$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
Seems you managed without parens ;)



--=20
Toutes les grandes personnes ont d=92abord =E9t=E9 des enfants, mais peu
d=92entre elles s=92en souviennent.

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

[Antoine de Saint-Exup=E9ry]
 
B

Bill Kelly

From: "Bill Kelly said:
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
 
H

Heesob Park

2009/6/1 Pascal J. Bourguignon said:
$ echo ----- ; cat quine.rb ; echo ----- ; ruby quine.rb ; echo -----
Here is a variant version of the above:

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


Regards,
Park Heesob
 
A

Aureliano Calvo

[Note: parts of this message were removed to make it a legal post.]

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

Aureliano Calvo

[Note: parts of this message were removed to make it a legal post.]

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
 
J

Jorrel

[Note: parts of this message were removed to make it a legal post.]

Is using File considered cheating?

puts File.readlines __FILE__


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
 
M

Matthew Williams

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}`
 
M

Martin DeMello

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
 
J

Joshua Ballanco

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

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
 
S

Sebastian Hungerecker

Am Montag 01 Juni 2009 06:30:16 schrieb Matthew Williams:
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
 
J

James Gray

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 Gray II
 
B

Brian Candler

James said:
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.
 
R

Robert Dober

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

=A0 =A0cat quine.rb | ruby

=A0 =A0cat 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
--=20
Toutes les grandes personnes ont d=92abord =E9t=E9 des enfants, mais peu
d=92entre elles s=92en souviennent.

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

[Antoine de Saint-Exup=E9ry]
 
B

Brian Candler

Robert said:
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.
 
P

Pascal J. Bourguignon

Brian Candler said:
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.

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

Robert Dober

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)


--=20
Toutes les grandes personnes ont d=E2=80=99abord =C3=A9t=C3=A9 des enfants,=
mais peu
d=E2=80=99entre elles s=E2=80=99en souviennent.

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

[Antoine de Saint-Exup=C3=A9ry]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top