Help needed on a just-for-fun-exercise

  • Thread starter Srinivas JONNALAGADDA
  • Start date
S

Srinivas JONNALAGADDA

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) }\nprint \"\\\"\"\nputs s"
print "s = \""
0.upto(s.length) { |i| printf("%c", ?s) }
print "\""
puts s

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

Greetings,
JS
 
H

Hal Fulton

Srinivas said:
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) }\nprint \"\\\"\"\nputs s"
print "s = \""
0.upto(s.length) { |i| printf("%c", ?s) }
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://rubyhacker.com


Cheers,
Hal
 
D

David Vallner

Srinivas said:
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
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top