# Help needed on a just-for-fun-exercise

**URL:** <https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763>\
**Category:** Ruby\
**Created:** [August 21, 2006, 8:34am UTC](https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763 "2006-08-21T08:34:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivas\_JONNALAGAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@Srinivas\_JONNALAGAD](https://www.ruby-forum.com/u/Srinivas_JONNALAGAD)\
**Post date:** [August 21, 2006, 8:34am UTC](https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763/1 "2006-08-21T08:34:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Srinivas\_JONNALAGAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@Srinivas\_JONNALAGAD](https://www.ruby-forum.com/u/Srinivas_JONNALAGAD)\
**Post date:** [August 21, 2006, 10:02am UTC](https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763/2 "2006-08-21T10:02:36Z")

</div>

On 8/21/06, Srinivas JONNALAGADDA [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

 \> \> 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/RubyQuines](http://wiki.rubygarden.org/Ruby/page/show/RubyQuines)

hth,  
-Harold

---

<div class="post-metadata">

**Author:** ![Srinivas\_JONNALAGAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@Srinivas\_JONNALAGAD](https://www.ruby-forum.com/u/Srinivas_JONNALAGAD)\
**Post date:** [August 21, 2006, 10:14am UTC](https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763/3 "2006-08-21T10:14:37Z")

</div>

Srinivas JONNALAGADDA wrote:

> 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](http://rubyhacker.com)

Cheers,  
Hal

---

<div class="post-metadata">

**Author:** ![Srinivas\_JONNALAGAD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@Srinivas\_JONNALAGAD](https://www.ruby-forum.com/u/Srinivas_JONNALAGAD)\
**Post date:** [August 23, 2006, 1:50am UTC](https://www.ruby-forum.com/t/help-needed-on-a-just-for-fun-exercise/65763/4 "2006-08-23T01:50:13Z")

</div>

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