Essays/Self

From J Wiki
Jump to: navigation, search

"Write the program that prints its own source code"

See the catalog at Puzzles/Quine

In J that would be "write an expression which results in a string that is composed of same characters in same sequence as original expression.

Another way to say it is to define string s such that (-: ".)s

It can be debated whether empty string counts as J expression and therefore is allowable entry, so to reduce on trivial discussion let's assume non-empty s.

Here is a solutions

(,~,{:,{:)'(,~,{:,{:)'''

And another one:

(,{:)^:2,~'(,{:)^:2,~'''

And this one has same length (24 characters) now but may be reduced to 22 in (future) J6

(,2:#{:),~'(,2:#{:),~'''

Can there be shorter expressions with this property?

Is it possible to construct expression with this property that has odd number of characters?