Contents
Create J program script that prints itself, so that
- it is not empty
the locked (3!:6) script file, after the original is deleted, will restore the original
Discussion
Suppose, the script is called q.ijs, in bash shell:
$ ./jconsole -js fc=:\!: "exit'q.ijl'fwrite~3 fc 6(ferase]fread)'q.ijs'[load'files'" $ ls q.* q.ijl $ ./jconsole q.ijl > q.ijs $ ./jconsole q.ijs > q.out $ ./jconsole -js "exit echo-:/fread&.>'q.ijs';'q.out'[load'files'" 1
in NT console
>jconsole -js "exit'q.ijl'fwrite~3!:6(ferase]fread)'q.ijs'[load'files'" >dir /b q.* q.ijl >jconsole q.ijl > q.ijs >jconsole q.ijs > q.out >jconsole -js "exit echo-:/fread&.>'q.ijs';'q.out'[load'files'" 1
History
Original quine problem appeared 1 May, 2002 in JForum by DanBron.
The purpose of this puzzle is to stimulate more complex solutions.
Spoiler Alert!
Solutions
Please submit your solutions here.
No. |
Scheme |
Author |
Date |
Source |
Quine/Notes |
0 |
2005-Nov-07 |
#N/A# |
0 |
||
Technically, the shortest J program that prints itself. |
|||||
1 |
2005-Nov-07 |
#N/A# |
hello world |
||
This assumes that J has been reconfigured to use linear display form. |
|||||
2 |
Josh ? <josh at cs.rutgers.edu> |
1999-Oct-02 (mod. date of url) |
".a=.'''".a=.'',q,q,~a#~1+a=q=.39{a.' |
||
This is the earliest example of a J quine I could find. |
|||||
3 |
2001-Feb-02 |
(],((39{a.)"_),],((39{a.)"_))'(],((39{a.)"_),],((39{a.)"_))' |
|||
4 |
2004-Jan-14 |
#N/A# |
(,(39{a.)&(,,[))'(,(39{a.)&(,,[))' |
||
5 |
2005-Nov-07 |
this page |
(,],{:,{:)'(,],{:,{:)''' |
||
6 |
2002-May-01 |
#N/A# |
(".'1!:1 <''foofile''') 1!:2 (2) |
||
This particular quine only works when it is stored in a script called 'foofile' (and executed therefrom). |
|||||
7 |
2004-Jan-14 |
#N/A# |
2 (1!:2)~ 1!:1 (3 : '(4!:3''''){~4!:4<''y.''' '') |
||
8 |
2002-11-26 |
#N/A# |
(,{:)^:2,~'(,{:)^:2,~''' |
||
9 |
2002-11-26 |
#N/A# |
(,{:,{:),~'(,{:,{:),~''' |
||
10 |
2002-11-26 |
#N/A# |
(,,~@{:),~'(,,~@{:),~''' |
||
11 |
2002-11-26 |
#N/A# |
(,~,{:,{:)'(,~,{:,{:)''' |
||
12 |
2006-05-09 |
#N/A# |
(a,5!:5<'a')[a=:'(a,5!:5<''a'')[a=:' |
||
13 |
BJonas |
2006-05-09 |
#N/A# |
(a=:'(a=:'"_ , 5!:5@<@('a'"_) , ')0'"_)0 |
|
14 |
BJonas |
2006-05-09 |
#N/A# |
(a=:3 : '''(a=:'',(5!:5<''a''),'')0''')0 |
|
15 |
BJonas |
2006-05-09 |
#N/A# |
(,,&')')0 :0 |
|
16 |
BJonas |
2006-05-09 |
#N/A# |
exit stdout(,,&')')0 :0 |
|
17 |
BJonas |
2006-05-09 |
#N/A# |
exit stdout(,,&(41 10{a.))0 :0 |
|
18 |
BJonas |
2006-05-09 |
#N/A# |
".a=:'''".a=:'',5!:5<''a''' |
|
19 |
BJonas |
2006-05-09 |
#N/A# |
".a=:'''".a=:'''''','''''''',~(#~>:@=&'''''''')a' |
|
20 |
BJonas |
2006-05-09 |
#N/A# |
3 :'3 :y.y.' '''3 :''''3 :y.y.'''' '''''','''''''',~(#~>:@=&'''''''')y.' |
|
21 |
BJonas |
2006-05-09 |
#N/A# |
3 : '''3 :'',,~'' '''''','''''''',~(#~>:@=&'''''''')y.' '''3 :'',,~'' '''''','''''''',~(#~>:@=&'''''''')y.' |
|
22 |
BJonas |
2006-05-09 |
#N/A# |
(,''''&,@:,&''''@:(#~>:@=&''''))'(,''''''''&,@:,&''''''''@:(#~>:@=&''''''''))' |
|
23 |
BJonas |
2006-05-09 |
#N/A# |
exit stdout(,''''&,@:,&''''@:(#~>:@=&''''))'exit stdout(,''''''''&,@:,&''''''''@:(#~>:@=&''''''''))' (remove trailing newline) |
|
24 |
BJonas |
2006-05-09 |
#N/A# |
exit stdout 3 :'3 :y.y.' '''exit stdout 3 :''''3 :y.y.'''' '''''','''''''',~(#~>:@=&'''''''')y.' (remove trailing newline) |
|
25 |
BJonas |
2006-05-09 |
#N/A# |
exit stdout".a=:'''exit stdout".a=:'',5!:5<''a''' (remove trailing newline) |
|
26 |
2007-05-25 |
(,~,2#{:)'(,~,2#{:)''' |
|||
27 |
2007-06-01 |
this page |
(,2#{:),~'(,2#{:),~''' |
||
28 |
2007-05-28 |
({&a.,":)40 123 38 97 46 44 34 58 41 |
|||
29 |
2007-06-01 |
this page |
(1!:2)&2@({&a.,":)40 49 33 58 50 41 38 50 64 40 123 38 97 46 44 34 58 41 |
||
30 |
2007-06-01 |
this page |
38 40 40 34 58 44 123 38 97 46 41 64 91 44 34 58 64 93 41&((":,{&a.)@[,":@])0j1 |
||
31 |
2007-06-01 |
this page |
'''&((2#{.@[),[,[,":@])'&((2#{.@[),[,[,":@])1.41421 |
||
32 |
2007-06-03 |
this page |
".'((34 46 39{]),{,":@[,39{])&a.40 40 51 52 32 52 54 32 51 57 123 93 41 44 123 44 34 58 64 91 44 51 57 123 93 41 38 97 46' |
||
33 |
2007-08-27 |
this page |
(128!:2)~'a.&((40 49 50 56 33 58 50 41 126 39{[),],39{[)' |
||
34 |
BJonas |
2008-09-25 |
|
;@(2 0 0 0 0 1 0 1 0 1 0 2 0&{)'''';';';';@(2 0 0 0 0 1 0 1 0 1 0 2 0&{)' |
|
35 |
2009-05-07 |
this page |
'1 : (44 126 40 51 57 123 97 46 41 44 120{ a.)'1 : (44 126 40 51 57 123 97 46 41 44 120{ a.) |
||
36 |
2009-05-07 |
this page |
((([<@](<<'+');~':';[<@]((,'0');1);[<@](,'0');<)@])'a.&((40 40 40 91 60 64 93 40 60 60 39 43 39 41 59 126 39 58 39 59 91 60 64 93 40 40 44 39 48 39 41 59 49 41 59 91 60 64 93 40 44 39 48 39 41 59 60 41 64 93 41 39{[),{~,":@],39 41 53 33 58 48{[)97 46 38 40 40 52 48 32 52 48 32 52 48 32 57 49 32 54 48 32 54 52 32 57 51 32 52 48 32 54 48 32 54 48 32 51 57 32 52 51 32 51 57 32 52 49 32 53 57 32 49 50 54 32 51 57 32 53 56 32 51 57 32 53 57 32 57 49 32 54 48 32 54 52 32 57 51 32 52 48 32 52 48 32 52 52 32 51 57 32 52 56 32 51 57 32 52 49 32 53 57 32 52 57 32 52 49 32 53 57 32 57 49 32 54 48 32 54 52 32 57 51 32 52 48 32 52 52 32 51 57 32 52 56 32 51 57 32 52 49 32 53 57 32 54 48 32 52 49 32 54 52 32 57 51 32 52 49 32 51 57 123 91 41 44 123 126 44 34 58 64 93 44 51 57 32 52 49 32 53 51 32 51 51 32 53 56 32 52 56 123 91 41')5!:0 |
||
37 |
BJonas |
2009-05-12 |
|
;2 0 0 0 0 1 0 1 0 1 0 2 0{'''';';';';2 0 0 0 0 1 0 1 0 1 0 2 0{' |
|
38 |
BJonas |
2009-05-12 |
|
;(1065345#:~13$3){'''';';';';(1065345#:~13$3){' |
|
39 |
2009-09-09 |
(],(''''"_ , (>:@:(''''"_ e.~ ]) # ]) , ''''"_) [ ('Whatever...'"_))'(],(''''''''"_ , (>:@:(''''''''"_ e.~ ]) # ]) , ''''''''"_) [ (''Whatever...''"_))' |
|||
40 |
2009-09-09 |
this page |
'''((("_)((<@:((,48{a.) ,&< ])) `(`((<@:((,48{a.) ,&< ])) 0)))) ((`:6) (((2#{.),,~)`) (`:6)))'((("_)((<@:((,48{a.) ,&< ])) `(`((<@:((,48{a.) ,&< ])) 0)))) ((`:6) (((2#{.),,~)`) (`:6))) |
Scheme legend
Scheme |
Nick |
Subclass |
Description |
|
Display matches specification |
DMS |
The idea for this quine is to create a line of input whose display, when executed, matches itself. |
||
Numeric |
N |
Most numeric constants in J display the same way they are specified |
||
Verb train |
V |
A analogous statement is true for verb trains. This fact, taken in conjunction with with the fact that an unassigned name is treated as a verb, allows lists of unassigned names (of certain lengths) to be DMS. |
||
Verb cat verb in quotes |
VCV |
The idea for this quine is to create a function that produces its input concatenated with its input in single quotes. Since literal constants in J are specified by enclosing them in single quotes, the quine is effected by passing the function to itself as literal input. |
||
Tacit |
T |
The verb must be tacit |
||
Explicit |
X |
Same scheme, using immediate execution mode |
||
Print my file |
PMF |
The idea for this quine is to create an script file that prints its own contents when loaded. |
||
Fixed filename |
F |
The script must be stored with a specific filename, which filename is mentioned in the script. |
||
Arbitrary filename |
A |
The script can be stored with any filename, which it will discover for itself. |
||
Script that Prints Itself |
SPI |
True solutions to this puzzle as stated. The constraint of locked files is only one way to require using itself and not the disk representation. Equivalent requirement would be to load into a noun, delete the file and execute the noun. |
||
These are all good solutions, but to other great puzzles different from this one. E.g. puzzle for solutions using the DMS and VCV schemes could be formulated as "Find a J phrase for which (-: ".^:_) is true". -- OlegKobchenko 2005-11-07 19:12:08
Very good clasification by DanBron. PMF is also a different puzzle. The original problem still being sought is categorized as SPI -- OlegKobchenko 2005-11-08 20:54:41
Then again, SPI solutions can be derived from self-reproducing expressions (satisfying (-: ".)) as illustrated by the solution 29 -- PepeQuintana 2012-05-25 00:19:34
References
Ken Thompson, Reflections on Trusting Trust. Communication of the ACM, Vol. 27, No. 8, August 1984, pp. 761-763.
