By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Quite Smart RIddle

P: n/a
I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

Have a good day.

Jun 9 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I know the article 'll be Ken Thompson's classical code.
I tried to do it.
But never came anywhere near to his idea.
Still i don't know how he is printing it using the string.
If anyone know can you please explain it to me?

Deepak.
sn*****@gmail.com wrote:
I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

Have a good day.


Jun 9 '06 #2

P: n/a
sn*****@gmail.com <sn*****@gmail.com> wrote:
I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.


A Quine?
What'd you say if I showed you a quine in C that was also a palindrome?
(That's if I can still find it, although you can probably google for it).
Look on wikipedia for Quine. There you can find information about them
if you are interested.

If you are talking about a quine then you have to know that the program
prints its source code and not itself.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Jun 9 '06 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sn*****@gmail.com wrote:
[a post that is, sans C code, generally considered of topic in clc]
I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.
Most of us have written C quines at least once.
I suggest that you google for 'quine'. There are quite a few C solutions
available.
Have a good day.


You too.

- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEiZaLagVFX4UWr64RAgFeAJ48wUfdiEhyw63aHl/1CXh1XuU2ZgCg8d3+
nFjXk3M9/ny90RSI4ThT65k=
=KZZr
-----END PGP SIGNATURE-----
Jun 9 '06 #4

P: n/a
Quines are quite interesting. There is an article at Wikipedia which
shows a C version.
____
Compilr - http://www.caller.me.uk/Compilr - the online C, C#, VB.NET,
Fortran compiler

Jun 9 '06 #5

P: n/a

bc*****@gmail.com wrote:
Quines are quite interesting. There is an article at Wikipedia which
shows a C version.
____
Compilr - http://www.caller.me.uk/Compilr - the online C, C#, VB.NET,
Fortran compiler


Thank you all-I didn't know that the name of its problem is Quine

Jun 9 '06 #6

P: n/a

sn*****@gmail.com wrote:
I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.


Ok:

/*This is my ugly C quine.*/
#include <stdio.h>
char *quine="void quotate(char
*s){while(*s){if(*s=='\\\\'||*s=='\\\"')putchar('\ \\\');putchar(*s);s++;}}int
main(){printf(\"/*This is my ugly C quine.*/\\n#include
<stdio.h>\\nchar
*quine=\\\"\");quotate(quine);printf(\"\\\";\\n%s\ ",quine);}";
void quotate(char
*s){while(*s){if(*s=='\\'||*s=='\"')putchar('\\'); putchar(*s);s++;}}int
main(){printf("/*This is my ugly C quine.*/\n#include <stdio.h>\nchar
*quine=\"");quotate(quine);printf("\";\n%s",quine) ;}

Not very compact or clever, but it works (before Google Groups messes
with the line breaks, anyway).

Jun 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.