[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Help needed on a just-for-fun-exercise

Srinivas Jonnalagadda

8/21/2006 6:32:00 AM

Dear all,

I was trying the well-known problem of writing a program that outputs
itself. Here is first trial.

s = "\nprint \"s = \\\"\"\n0.upto(s.length) { |i| printf(\"%c
\", ?s[i]) }\nprint \"\\\"\"\nputs s"
print "s = \""
0.upto(s.length) { |i| printf("%c", ?s[i]) }
print "\""
puts s

However, I am having a difficulty self-printing the literal line. Could
someone help?

Greetings,
JS


3 Answers

Harold Hausman

8/21/2006 8:01:00 AM

0

On 8/21/06, Srinivas JONNALAGADDA <srinivas.j@siritech.com> wrote:
> Dear all,
>
> I was trying the well-known problem of writing a program that outputs
> itself. Here is first trial.
>
<snip>
>
> Greetings,
> JS
>

It's not an answer to your question, but this page may be of some
interest to you:
http://wiki.rubygarden.org/Ruby/page/show/...

hth,
-Harold

Hal E. Fulton

8/21/2006 8:13:00 AM

0

Srinivas JONNALAGADDA wrote:
> Dear all,
>
> I was trying the well-known problem of writing a program that outputs
> itself. Here is first trial.
>
> s = "\nprint \"s = \\\"\"\n0.upto(s.length) { |i| printf(\"%c
> \", ?s[i]) }\nprint \"\\\"\"\nputs s"
> print "s = \""
> 0.upto(s.length) { |i| printf("%c", ?s[i]) }
> print "\""
> puts s
>
> However, I am having a difficulty self-printing the literal line. Could
> someone help?

All I can say is, find the tutotials and follow them.

I have difficulty reading other people's quines. :)
Maybe it is a one-person task, like driving nails.

The first ones I wrote are at http://ruby...


Cheers,
Hal

David Vallner

8/22/2006 11:50:00 PM

0

Srinivas JONNALAGADDA wrote:
> I was trying the well-known problem of writing a program that outputs
> itself. Here is first trial.

Off the top of my head comes the absolutely oldest cheat in the book:

print File.read($0)

Try not to groan too loud.

David Vallner