[Caml-list] Palindromic Quine

38 views
Skip to first unread message

Keisuke Nakano

unread,
Jan 28, 2008, 10:25:08 AM1/28/08
to caml...@inria.fr
Hello,

A 'Palindromic Quine' code is now wanted by a shortest-code contest at:

http://golf.shinh.org/p.rb?Palindromic+Quine

The code should be a Quine, which prints its own code without reading
its source file. Additionally, the code should be palindromic, which
reads the same forward as it does backward. Shorter code is better.
Lots of programming languages are available including OCaml, of course.

Please submit your palindromic Quine to the above contest if you find
it.
The deadline is Thursday, 7 February 2008, 16:46:39, GMT.
All submitted programs will be revealed after the deadline.
At present the shortest code in OCaml has 205 bytes.

Cheers,

Keisuke Nakano <ksk _at_ mist.i.u-tokyo.ac.jp>

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Loup Vaillant

unread,
Jan 28, 2008, 10:37:53 AM1/28/08
to Keisuke Nakano, caml...@inria.fr
You should have said the input must not be empty!
It gave me false hopes :-(

Cheers,
Loup

2008/1/28, Keisuke Nakano <k...@mist.i.u-tokyo.ac.jp>:

Till Varoquaux

unread,
Jan 28, 2008, 10:45:53 AM1/28/08
to Alain Frisch, Keisuke Nakano, caml...@inria.fr
Thought about it ;-) but it does say entries should be >1B.

Till

On Jan 28, 2008 3:39 PM, Alain Frisch <al...@frisch.fr> wrote:


> Keisuke Nakano wrote:
> > The code should be a Quine, which prints its own code without reading
> > its source file. Additionally, the code should be palindromic, which
> > reads the same forward as it does backward. Shorter code is better.
> > Lots of programming languages are available including OCaml, of course.
>

> I've one with 0 bytes. Should I submit it?
>
> -- Alain


>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
http://till-varoquaux.blogspot.com/

Loup Vaillant

unread,
Jan 28, 2008, 10:48:19 AM1/28/08
to Till Varoquaux, Keisuke Nakano, caml...@inria.fr, Alain Frisch
2008/1/28, Till Varoquaux <till.va...@gmail.com>:

> Thought about it ;-) but it does say entries should be >1B.

That makes 3 of us...

Keisuke Nakano

unread,
Jan 28, 2008, 10:50:09 AM1/28/08
to caml...@inria.fr
Sorry, Loup and Alain.
I should have said empty code is not allowed.

Keisuke


On 2008/01/29, at 0:37, Loup Vaillant wrote:
> You should have said the input must not be empty!
> It gave me false hopes :-(
>

On 2008/01/29, at 0:39, Alain Frisch wrote:

> Keisuke Nakano wrote:
>> The code should be a Quine, which prints its own code without reading
>> its source file. Additionally, the code should be palindromic, which
>> reads the same forward as it does backward. Shorter code is better.
>> Lots of programming languages are available including OCaml, of
>> course.
>

> I've one with 0 bytes. Should I submit it?
>
> -- Alain
>

Romain Bardou

unread,
Jan 28, 2008, 10:51:13 AM1/28/08
to caml...@inria.fr
Actually a Quine can be empty AND >1B, can't it?

--
Romain Bardou

Till Varoquaux a écrit :

Loup Vaillant

unread,
Jan 28, 2008, 12:13:10 PM1/28/08
to Romain Bardou, caml...@inria.fr
2008/1/28, Romain Bardou <Romain...@lri.fr>:

> Actually a Quine can be empty AND >1B, can't it?

Are you thinking about a source that contains only 1 or two white
spaces? I can only think of whitespace
(http://compsoc.dur.ac.uk/whitespace/) to manage such a crazy feat.

<going_nuts>
Another idea: submit a single entry wich works as BOTH Ocaml and whitespace...
</going_nuts>

Martin Jambon

unread,
Jan 28, 2008, 2:13:20 PM1/28/08
to Keisuke Nakano, caml...@inria.fr
On Tue, 29 Jan 2008, Keisuke Nakano wrote:

> Hello,
>
> A 'Palindromic Quine' code is now wanted by a shortest-code contest at:
>
> http://golf.shinh.org/p.rb?Palindromic+Quine
>
> The code should be a Quine, which prints its own code without reading
> its source file. Additionally, the code should be palindromic, which
> reads the same forward as it does backward. Shorter code is better.
> Lots of programming languages are available including OCaml, of course.
>
> Please submit your palindromic Quine to the above contest if you find it.
> The deadline is Thursday, 7 February 2008, 16:46:39, GMT.
> All submitted programs will be revealed after the deadline.
> At present the shortest code in OCaml has 205 bytes.

Here's a new non-palindromic OCaml quine:

http://martin.jambon.free.fr/q.ml

Maybe not completely legal and works only "ocaml q.ml"...

but feel free to make it palindromic :-)


Martin

--
http://wink.com/profile/mjambon
http://martin.jambon.free.fr

Fabrice Marchant

unread,
Jan 29, 2008, 3:55:36 PM1/29/08
to caml...@yquem.inria.fr
> Here's a new non-palindromic OCaml quine:
>
> http://martin.jambon.free.fr/q.ml
>
> Maybe not completely legal and works only "ocaml q.ml"...
>
> but feel free to make it palindromic :-)

Absolutely cool, lol !

Regards,

Fabrice

Bünzli Daniel

unread,
Jan 29, 2008, 4:03:02 PM1/29/08
to caml-list caml-list

Le 29 janv. 08 à 20:58, Fabrice Marchant a écrit :

>> Here's a new non-palindromic OCaml quine:
>>
>> http://martin.jambon.free.fr/q.ml
>>
>> Maybe not completely legal and works only "ocaml q.ml"...
>>
>> but feel free to make it palindromic :-)
>
> Absolutely cool, lol !

But it's not a program.

Daniel

Paolo Donadeo

unread,
Jan 29, 2008, 4:43:49 PM1/29/08
to caml-list caml-list
> But it's not a program.

Yes it is!

Not a correct one, of course :)


--
Paolo


Paolo Donadeo, Senior Software Engineer
Studio Associato 4Sigma
Email: p.do...@4sigma.it
~
~
:wq

Bünzli Daniel

unread,
Jan 29, 2008, 5:59:12 PM1/29/08
to caml-list List
So your email below is a program ? You can define any string to be a
program but it won't be that useful.

Daniel

Le 29 janv. 08 à 22:42, Paolo Donadeo a écrit :

>> But it's not a program.
>

> Yes it is!
>
> Not a correct one, of course :)
>
>
> --
> Paolo
>
>
> Paolo Donadeo, Senior Software Engineer
> Studio Associato 4Sigma
> Email: p.do...@4sigma.it
> ~
> ~
> :wq

_______________________________________________

Julien Moutinho

unread,
Jan 29, 2008, 11:04:18 PM1/29/08
to caml...@inria.fr
On Tue, Jan 29, 2008 at 12:23:45AM +0900, Keisuke Nakano wrote:
> A 'Palindromic Quine' code is now wanted by a shortest-code contest at:
>
> http://golf.shinh.org/p.rb?Palindromic+Quine
>
> The code should be a Quine, which prints its own code without reading
> its source file. Additionally, the code should be palindromic, which
> reads the same forward as it does backward. Shorter code is better.
> Lots of programming languages are available including OCaml, of course.
>
> Please submit your palindromic Quine to the above contest if you find it.
> The deadline is Thursday, 7 February 2008, 16:46:39, GMT.
> All submitted programs will be revealed after the deadline.
> At present the shortest code in OCaml has 205 bytes.

Quite a cheating palindromic Quine, but that's enough for my being satisfied.

% cat t.ml
(*/*)()=()open Sys let tel()=();;let fer=print_string executable_name in tel
let ni eman_elbatucexe gnirts_tnirp=ref tel;;()=()let tel syS nepo()=()(*\*)
% O=`cat t.ml`; mkdir -p "(*"; ocamlc -w a t.ml -o "$O"; "$O"
(*/*)()=()open Sys let tel()=();;let fer=print_string executable_name in tel
let ni eman_elbatucexe gnirts_tnirp=ref tel;;()=()let tel syS nepo()=()(*\*)
% wc t.ml
2 16 154 t.ml

Explanation:
It just calls [print_string Sys.executable_name]
with an ad-hoc executable name.
Also, I've considered that ")(" and "/\" are palindromic.

Cheers,

Julien Moutinho.

Kuba Ober

unread,
Jan 30, 2008, 7:57:21 AM1/30/08
to caml...@yquem.inria.fr
On Tuesday 29 January 2008, Bünzli Daniel wrote:
> So your email below is a program ? You can define any string to be a
> program but it won't be that useful.

Yeah, but I guess the constraint is that you have to run/process it in some
sort of what would normally be considered programming environment ;)

So, the error message approach, being a non-palindromic quine, will work with
many compilers in fact.

I guess the contest designers have to decide one way or the other on the "it
must be a correct program" constraint.

Cheers, Kuba

Keisuke Nakano

unread,
Jan 30, 2008, 9:16:41 AM1/30/08
to caml...@yquem.inria.fr
On 2008/01/30, at 21:57, Kuba Ober wrote:
> I guess the contest designers have to decide one way or the other
> on the "it
> must be a correct program" constraint.

The only constraint for correctness is 'to be accepted by the server'.
The contest server automatically and immediately judges submitted
programs
whether it is correct or not. If the submission is correct, the
server will
add the author's name to the ranking.

The error message approach, even if it is palindromic, will be rejected
because the server does not observe the standard error.

Cheers,
Keisuke.

Kuba Ober

unread,
Jan 30, 2008, 11:28:47 AM1/30/08
to caml...@yquem.inria.fr
On Wednesday 30 January 2008, Keisuke Nakano wrote:
> On 2008/01/30, at 21:57, Kuba Ober wrote:
> > I guess the contest designers have to decide one way or the other
> > on the "it
> > must be a correct program" constraint.
>
> The only constraint for correctness is 'to be accepted by the server'.
> The contest server automatically and immediately judges submitted
> programs
> whether it is correct or not. If the submission is correct, the
> server will
> add the author's name to the ranking.
>
> The error message approach, even if it is palindromic, will be rejected
> because the server does not observe the standard error.

I guess that settles it, then. The approach was nifty, though ;)

Cheers, Kuba

Cristian Baboi

unread,
Jan 31, 2008, 2:00:36 AM1/31/08
to Kuba Ober, caml...@yquem.inria.fr
Which language the Quine was written in ? :-)

On Wed, 30 Jan 2008 14:57:06 +0200, Kuba Ober <obe...@osu.edu> wrote:

> On Tuesday 29 January 2008, Bünzli Daniel wrote:
>> So your email below is a program ? You can define any string to be a
>> program but it won't be that useful.

> Yeah, but I guess the constraint is that you have to run/process it in
> some
> sort of what would normally be considered programming environment ;)

> So, the error message approach, being a non-palindromic quine, will work
> with
> many compilers in fact.

> I guess the contest designers have to decide one way or the other on the
> "it
> must be a correct program" constraint.
>
> Cheers, Kuba


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
part000.txt - is OK
http://www.eset.com

willia...@gmail.com

unread,
Feb 6, 2008, 4:17:04 AM2/6/08
to
I have managed to produce the following 300 bytes quine in OCaml which
is *almost* a palindrome. It would be a palindrome if the trailing "
was not there...

open String;;(fun q s->let rec a s=let l=length s-1in if l>=0then(a
(sub s 1 l);print_char s.[0])in a s;print_string(q^s^q)) (make
1(char_of_int 34))"))43 tni_fo_rahc(1 ekam( ))q^s^q(gnirts_tnirp;s a
ni)]0[.s rahc_tnirp;)l 1 s bus( a(neht0=>l fi ni1-s htgnel=l tel=s a
cer tel>-s q nuf(;;gnirtS nepo"

Can anyone help to turn this into a proper palindrome?
Is it even possible to write a valid palindromic program in Ocaml, let
alone a palindromic quine?

William Blum

willia...@gmail.com

unread,
Feb 6, 2008, 4:32:06 AM2/6/08
to
In fact there exist trivial palindromic programs in Ocaml, for
instance a program consisting of just a constant number. So I need to
reformulate my question in the last post as: Is there a valid *non
trivial* palindromic program in OCaml, i.e. that prints something on
the screen?

William Blum

Keisuke Nakano

unread,
Feb 8, 2008, 8:40:34 AM2/8/08
to caml...@inria.fr
The shortest code contest 'Palindromic Quine' is over.
The result is found at:
http://golf.shinh.org/p.rb?Palindromic+Quine#OCaml

Finally I could find the shortest code with 199 bytes:

"k\"",let rec(!)n?(q=String.make 1(Char.chr 34))s k=print_char
(q^s^q^q^k^q).[abs n];!(n-1)s k in!99"99!ni k s)1-n(!;]n sba[.)
q^k^q^q^s^q(rahc_tnirp=k s))43 rhc.rahC(1 ekam.gnirtS=q(?n)!(cer
tel,""\k"

It is an acceptable solution for the contest though the code
execution ends with an exception 'index out of bounds'.

There may exist a palindromic Quine code shorter than this code.
Please try to find it if you're interested in.

Cheers,

Keisuke Nakano <ksk _at_ mist.i.u-tokyo.ac.jp>

On 2008/01/29, at 0:23, Keisuke Nakano wrote:
> A 'Palindromic Quine' code is now wanted by a shortest-code contest
> at:
>
> http://golf.shinh.org/p.rb?Palindromic+Quine
>
> The code should be a Quine, which prints its own code without reading
> its source file. Additionally, the code should be palindromic, which
> reads the same forward as it does backward. Shorter code is better.
> Lots of programming languages are available including OCaml, of
> course.
>
> Please submit your palindromic Quine to the above contest if you
> find it.
> The deadline is Thursday, 7 February 2008, 16:46:39, GMT.
> All submitted programs will be revealed after the deadline.
> At present the shortest code in OCaml has 205 bytes.

_______________________________________________

Reply all
Reply to author
Forward
0 new messages