We've had a lot of quine challenges, but a lot of the quine formats are similar, lets create some variance in our quines.
Your task is to create a selection of programs in the same language (at least 2), all of which output their own source code, however, none of these programs can share any characters.
For example, if you create a program using:
printf+qw(printf+qw(%s)x2)x2
Your next program cannot include any of:
%()+2finpqrstwx
and so on.
Rules
- You may use unicode characters, but you must still score in bytes.
- All programs must meet the community definition of a proper quine. This means that the empty string does not count as a valid quine, among other things.
- Standard loopholes are forbidden.
- Functions or full programs are allowed as long as they meet the above definition.
- Symbol independent languages (including Lenguage and Headsecks) are disallowed.
- Most programs wins, with shortest total code as a tie breaker.
-
\$\begingroup\$ Since there are close votes I'll undelete the sandbox post for discussion: codegolf.meta.stackexchange.com/a/16053/9365 \$\endgroup\$Dom Hastings– Dom Hastings2018年04月27日 19:58:56 +00:00Commented Apr 27, 2018 at 19:58
-
\$\begingroup\$ I notice that the sandbox comments mention that function submissions are allowed, but the challenge says nothing about it - I was assuming the opposite as the default for quines. \$\endgroup\$Ørjan Johansen– Ørjan Johansen2018年04月27日 20:01:07 +00:00Commented Apr 27, 2018 at 20:01
-
2\$\begingroup\$ Related (Kind of the converse challenge - your quines have to output each other instead of themselves) \$\endgroup\$N. Virgo– N. Virgo2018年04月29日 10:34:28 +00:00Commented Apr 29, 2018 at 10:34
-
1\$\begingroup\$ What about trailing newlines? If one of my quines prints one, does the other have to avoid doing so? (I suspect that most answers don't do this.) \$\endgroup\$N. Virgo– N. Virgo2018年04月30日 11:23:29 +00:00Commented Apr 30, 2018 at 11:23
-
2\$\begingroup\$ @DomHastings I couldn't find a meta question, so I asked one. \$\endgroup\$N. Virgo– N. Virgo2018年05月01日 12:16:10 +00:00Commented May 1, 2018 at 12:16
12 Answers 12
V, (削除) 3 (削除ここまで), 5 quines, 46 bytes
2A2A
Hexdump:
00000000: 3241 3241 2A2A
Explanation:
2 " 2 times...
A " (A)ppend the following text...
2A " '2A'
5a5a
Hexdump:
00000000: 35ad adad 6135 adad ad61 5...a5...a
Explanation:
5--- " 5 - 3 times...
a " (a)ppend the following text...
5---a " '5---a'
1«I1«I
Hexdump:
00000000: 31ab 4931 ab49 1.I1.I
Explanation:
1« " 1 + 1 times...
I " (I)nsert the following text...
1«I " '1«I'
Here's where they start to get funky...
ñi34x@-qPÉÑ~ÿ
Hexdump:
00000000: f169 1633 341b 7840 2d71 50c9 d17e ff .i.34.x@-qP..~.
Explanation:
ñ " Wrap all the following in macro '"q':
i<C-v>34 " Insert character code 34 `"`
<esc> " Return to normal mode
x " Delete the character we just inserted. Now, running `@-` will be equal to running `"`
P " Paste...
@- " From Register...
q " "q
ÉÑ " Insert 'Ñ' at the beginning of this line
~ " Toggle the case of the character we just inserted
ÿ " Black magic
:norm é:":p
Hexdump:
00000000: 3a6e 6f72 6d20 e93a 223a 70 :norm .:":p
Explanation:
:norm " Run the following commands as if typed:
é: " insert ':'. Somehow also does black magic and resets the value of '":`
":p " Paste the last ex command to be run ('norm é:":p')
This answer is filled with black magic. Quines 1 and 4 are not new, but the other 3 all have never been found before, so more than half of these quines were just discovered today.
-
8\$\begingroup\$ The third program is trolling. "You're a
normie :p" \$\endgroup\$mbomb007– mbomb0072018年04月27日 18:27:47 +00:00Commented Apr 27, 2018 at 18:27 -
4\$\begingroup\$ @mbomb007 Obligatory
REEEEEE--\$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2018年04月27日 20:34:17 +00:00Commented Apr 27, 2018 at 20:34
Jelly, (削除) 2 3 4 (削除ここまで) 5 quines, (削除) 14 18 81 65 59 56 326 265 247 229 (削除ここまで) 216 bytes
3 bytes
"ṘṘ
Standard quine. "Ṙ is the one character literal for Ṙ. Ṙ prints the string representation of this then the string Ṙ implicitly gets printed.
4 bytes
))ḤḤ
) begins a two character string literal and Ḥ doubles it's argument. With a string input, Ḥ gets mapped onto each character. Thus Ḥ acting on the string )Ḥ yields ))ḤḤ, the source code.
11 bytes
ȮṾṖƊ}"ȮṾṖƊ}
On the right hand side, "ȮṾṖƊ} is the string literal for ȮṾṖƊ}. The string closing character is tacitly added at EOF.
To the left of the string literal, Ɗ wraps ȮṾṖ into a single monad and } turns it into a dyad which uses it's right argument, the string literal. Ȯ prints the string (ȮṾṖƊ}), Ṿ creates a string representation of the string ("ȮṾṖƊ}") and Ṗ removes the " character. The string "ȮṾṖƊ} is left after the monad and is implicitly printed.
(削除) 38 49 (削除ここまで) 36 bytes
32,52,52,7884,106,64,44,7884 44Ọj@,Ọ
First time I've ever used a space in Jelly golfing.
The list of numbers at the beginning holds the ord of the rest of the characters in code. After that:
jṛ44Ọ,ドルỌ
j Join this list with...
ṛ right argument. Avoiding using ¤ so I can use it in the next program.
44Ọ chr(44)==',': [106, ',', ...]
$ Causes Ọ to act on 44 before j acts on it.
, Pair this list with...
Ọ chr of each number in the list. Yields jṛ44Ọ,ドルỌ
(削除) 270 198 180 (削除ここまで) 162 bytes
(¢_;((¤;(¡_;((¡;(¡¤;($+;((y;(Ẹ$;(+$;(AƑ;(?€;(b(;(¢¡;(_(;(¡¡;(¤ị;(ØJ;(μṭ;(€(;(¡S;(;(;(¡ʠ;(¤ị;(ØJ;(¤F;(ḊṄ;(ȧF
¢_(¤¡_(¡¡¤$+(yẸ$+$AƑ?€b(¢¡_(¡¡¤ịØJμṭ€(¡S;(¡ʠ¤ịØJ¤FḊṄȧF
Uses base 250 numbers and indexes into Jelly code page. Saved 72 bytes by changing the algorithm. Was using each number to index in to Jelly's code page but am now converting the integer back to base 250 then indexing into Jelly's code page, basically halving the number of literals I need in the first line. This also reduces the number of unique characters needed, but I can't think of a way to make any more quines.
I've used up )"" which create string literals and Ọ and ØJ which create strings from numbers. I can't think of any other ways of making strings. I still have the digit 9 and ‘’ available, so if there is a another way of making strings from numbers it may be possible to make another quine.
Haskell, 3 quines, 1119 bytes
Quine 1, 51 bytes
An anonymous IO action printing directly to stdout.
putStr`mappend`print`id`"putStr`mappend`print`id`"
Quine 2, 265 bytes
The function f takes a dummy argument and returns a string.
f c=[b=<<g]!!0++show g;b c=[[[show 9!!0,show 1!!0..]!!6..]!!c];g=[93,0,90,52,82,89,52,51,51,94,84,24,24,39,34,34,106,95,102,110,0,94,50,89,0,90,52,82,82,82,106,95,102,110,0,48,24,24,39,35,106,95,102,110,0,40,24,24,39,37,37,84,24,24,45,37,37,84,24,24,90,84,50,94,52]
Quine 3, 803 bytes
Everything after the LANGUAGE pragma is an anymous function taking a dummy argument and returning a string.
{-#LANGUAGE CPP#-}(\q(_:_:_:_:_:_:_:_:z)y(#)_->(y(\k x->'&':q:k:q:x)#y(\k x->'%':q:'\\':k:q:x)$y(:)#y(:)$ \x->x)z)'\''__TIME__(\(?)v k x->v$k?x)$ \(&)(%)v->v&'{'&'-'&'#'&'L'&'A'&'N'&'G'&'U'&'A'&'G'&'E'&' '&'C'&'P'&'P'&'#'&'-'&'}'&'('%'\\'&'q'&'('&'_'&':'&'_'&':'&'_'&':'&'_'&':'&'_'&':'&'_'&':'&'_'&':'&'_'&':'&'z'&')'&'y'&'('&'#'&')'&'_'&'-'&'>'&'('&'y'&'('%'\\'&'k'&' '&'x'&'-'&'>'%'\''&'&'%'\''&':'&'q'&':'&'k'&':'&'q'&':'&'x'&')'&'#'&'y'&'('%'\\'&'k'&' '&'x'&'-'&'>'%'\''&'%'%'\''&':'&'q'&':'%'\''%'\\'%'\\'%'\''&':'&'k'&':'&'q'&':'&'x'&')'&'$'&'y'&'('&':'&')'&'#'&'y'&'('&':'&')'&'$'&' '%'\\'&'x'&'-'&'>'&'x'&')'&'z'&')'%'\''%'\\'%'\''%'\''&'_'&'_'&'T'&'I'&'M'&'E'&'_'&'_'&'('%'\\'&'('&'?'&')'&'v'&' '&'k'&' '&'x'&'-'&'>'&'v'&'$'&'k'&'?'&'x'&')'&'$'&' '%'\\'&'('&'&'&')'&'('&'%'&')'&'v'&'-'&'>'&'v'
Characters
Quine 1:
"S`adeimnprtu
Quine 2:
!+,.0123456789;<=[]bcfghosw
Quine 3:
#$%&'()-:>?ACEGILMNPTU\_kqvxyz{}
How it works
Quine 1
putStr`mappend`print`id`"putStr`mappend`print`id`"
Quine 1 is a modified version of my recent Golf you a quine answer (with improvements by H.PWiz):
- Since full programs are not needed,
main=has been removed. <>and$have been replaced by their near-synonymsmappendandid.
This frees up the vital characters =<> and the helpful operator $ for the other quines.
Quine 2
f c=[b=<<g]!!0++show g;b c=[[[show 9!!0,show 1!!0..]!!6..]!!c];g=[93,0,......]
Quine 2 uses somewhat similar methods to program 2 of my recent Mutually Exclusive Quines answer, but adapted to quine itself directly and especially to avoid using character literals, which are needed for quine 3. Both of these are achieved with the help of the show function, which by sheer luck hasn't had any of its characters used yet.
This quine uses tabs instead of spaces, but I've used spaces below for readability.
gis the quine data, as a list of integers at the end of the code. Each number represents a character from the rest of the code.- The numbers are shifted by
9, so that tab is0. This makes the encoding a bit shorter by allowing the lowercase letters for the function and variable names to fit in 2 digits.
- The numbers are shifted by
b c=[[[show 9!!0,show 1!!0..]!!6..]!!c]is a function to convert a number to a character (actually a one-character string).[[show 9!!0,show 1!!0..]!!6..]is a character range starting with a tab character, which is indexed into with!!c.- The tab character itself is produced by indexing into another range
[show 9!!0,show 1!!0..], starting with the digit characters'9'and'1'and jumping down in steps of 8. - The digit characters are produced by indexing into the
showstring of the corresponding digit.
f c=[b=<<g]!!0++show gis the main function.cis a dummy argument.b=<<guses=<<to convert each number ingto its character. (The use of=<<rather than e.g.mapis whybneeds to wrap its returned character in a list.)show ggives the string representation ofg's list, and++concatenates the strings.- Because
=<<has lower precedence than++, some bracketing is needed. To avoid using()(reserved for quine 3),[...]!!0indexes into a list with one element.
Quine 3
By design of the other quines, quine 3 still has access to parentheses, lambda expressions, character literals, and the string/list constructor :. This will be enough to construct a function that prepends the quine's code to a string.
Unfortunately, all lower case vowels (except sometimes y) have been used, leaving no useful alphanumeric builtin functions. Also []"" are gone. This leaves no normal way to construct an empty string to start pretending the code to.
However, nearly all uppercase letters are still available, so a LANGUAGE pragma to get a language extension is possible. Again by sheer luck, CPP (enable C preprocessor) is the only language extension named with only uppercase letters. And CPP macros often have uppercase names.
So to get the essential empty string, the quine enables CPP, uses the __TIME__ macro to get a string constant of the form "??:??:??" (conveniently guaranteed to always have the same length), and pattern matches on it.
{-#LANGUAGE CPP#-}(\q(_:_:_:_:_:_:_:_:z)y(#)_->(y(\k x->'&':q:k:q:x)#y(\k x->'%':q:'\\':k:q:x)$y(:)#y(:)$ \x->x)z)'\''__TIME__(\(?)v k x->v$k?x)$ \(&)(%)v->v&'{'&'-'&......
After the language pragma, the quine consists of a lambda expression binding its parameters to these four arguments (leaving a final dummy parameter _ to be applied later):
qbound to'\'', giving a single quote character;_:_:_:_:_:_:_:_:zbound to__TIME__, aka a string like"??:??:??", thus makingzan empty string;ybound to(\(?)v k x->v$k?x), a lambda combinator used to help convert the quine data from left associated ("foldl") to right associated ("foldr") form;- The operator
(#)bound to\(&)(%)v->v&'{'&'-'&..., the quine data itself.
The quine data is given in a form of Church encoding, a lambda expression with parameters (&)(%)v.
- By applying the expression to particular values to instantiate
(&),(%)andv, this encoding can be used either to build the core code of the quine or to rebuild the quine data representation itself. - By Haskell's default fixity rule,
&and%become left associative operators inside the lambda. Thus the character parameters become combined with the initialvstarting from the left. - For most characters
k, there is a corresponding&'k'. - When
kis'or\, which need to be escaped inside character literals, the encoding is instead%'\k'.
Since the data encoding is left associative, but strings are built in a right associative manner, the combinator y = (\(?)v k x->v$k?x) is introduced to bridge the mismatch.
y(...)is intended to build suitable functions for using as the quine data's(&)and(%)operators.vis a function from strings to strings (the quine data's intendedvs being examples).kis a character,xa string, and?an operator that combines them into a new string. (For the core code,(?)=(:). For actually reconstructing the quine data representation, it's more complicated.)- Thus
y(?)v k = \x->v$k?xis another function from strings to strings. As an example of how this changes associativity, if
(&)=y(:):(v&k1&k2&k3) x = (((v&k1)&k2)&k3) x = y(:)(y(:)(y(:)v k1)k2)k3 x = y(:)(y(:)v k1)k2 (k3:x) = y(:)v k1 (k2:(k3:x)) = v (k1:(k2:(k3:x))) = v (k1:k2:k3:x)
More generally, when (#) is the quine data function and f1,f2 are functions combining characters with strings:
(y(f1)#y(f2)$v) x
= (...(y(f1)(y(f1)v '{') '-')...) x
= v(f1 '{' (f1 '-' (... x)))
applying the quine data function with (&)=y(f1) and (%)=y(f2), and this uses the prescribed f1 and f2 to combine the quine data's characters with x, and then passes the resulting string to v.
The body of the main lambda expression puts this all together:
(y(\k x->'&':q:k:q:x)#y(\k x->'%':q:'\\':k:q:x)$y(:)#y(:)$ \x->x)z
'&':q:k:q:xfor a characterkprepends&'k'to the stringx, while'%':q:'\\':k:q:xprepends%'\k', which are their original quine data forms.- Thus
y(\k x->'&':q:k:q:x)#y(\k x->'%':q:'\\':k:q:xare the right parameters for rebuilding the quine data representation, prepended to the finalz(the empty string), and then passed on to the following function. y(:)#y(:)are the right parameters to prepend the quine's core code to a string, without other modification.- Finally the
\x->xgets to do nothing with the constructed quine, which is returned.
MathGolf, (削除) 4 5 (削除ここまで) 6 quines, 193,535 bytes
9 bytes
ÿ'ÿ⌐_'ÿ⌐_
45 bytes
û]∙ûxôû¬ûûûûû╡¬ûô╡û╡xûxxû¬ô]∙xô¬ûûû╡¬ô╡╡xxx¬ô
49 bytes
ùa6æù\a\ù+6┼ù\ùùùùù\ù§\+ùΣ\Σa6æ\a\+6┼\ùùùù\§\+Σ\Σ
99 bytes
"""▐ ⌠▌ ⌠▌ ⌠▌ ⌠ ⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠ ⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠"`~
4488 bytes
♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((♠((((((((((((((((((((((((((((((((((((((((((((DÄß─·ö♠,♦M-$*DÄß─ö7($$$qq$Äq╘
188,845 bytes
I'm can't really link to this one, so here's a Perl 6 program that generates the actual quine
(削除) I can most definitely squeeze another quine out of this, though I think I've run out of ways to push strings straight to the stack, so I'll have to resort to stranger methods. Even stranger methods incoming as I try for a sixth quine. In some cases the quines could be shorter, but I'm reducing used bytes in preparation. (削除ここまで)
Okay, I might technically be able to do one more quine, since I still have a few operators that I need (push string, increment string, duplication, mapping, popping), it's the looping that constricts us. The {} are the only operators that can can indicate a code block of arbitrary length, and I really need them in the 6th quine. I could use some of the other code blocks, but they're limited, and I doubt the looping sections are going to be that short, since we're running out of easy operators.
Okay, some belated explanations:
All the quines have almost the same structure:
- Push a string, or list of strings, or list of characters to the stack.
- Combine it all into one list
- Duplicate the list
- Map over the copy, printing/pushing the characters used to get the original characters
- Print the original list of characters as a string
Quine 1:
This is basically the same as the one I posted in the normal quine question.
ÿ'ÿ⌐_'ÿ⌐_
ÿ Push the next 4 bytes as a string
'ÿ⌐_ Stack ["'ÿ⌐_"]
'ÿ Push the byte ÿ (I realise I could have used this in a later quine)
⌐ Rotate the ÿ to the bottom of the stack : ["ÿ", "'ÿ⌐_"]
_ Duplicate top of stack: ["ÿ", "'ÿ⌐_", "'ÿ⌐_"]
Implicitly print stack joined together : ÿ'ÿ⌐_'ÿ⌐_
Quine 2
û Push the next 2 bytes as a string
]∙ Stack: ["]∙û"]
û û... Repeat this for the rest of the code
] Wrap the stack in an array : [["]∙","xô"...]]
∙ Triplicate : [[..],[..],[..]]
x Reverse the top array
ô Loop over the array, executing the next 6 instructions
Stack: [[..],[..],str]
¬ Rotate the stack : [str,[..],[..]]
ûûû╡ Push the string "ûû" and discard the left character
¬ Rotate the "û" to the bottom : ["û",str,[..],[..]]
This produces the initialisation part
ô Loop over the array with the next 6 characters again
╡╡xxx¬ Basically discard the string
ô Flatten the last copy of the array onto the stack
Implicitly output the code
Quine 3:
ùa6æù\a\ù+6┼ù\ùùùùù\ù§\+ùΣ\Σa6æ\a\+6┼\ùùùù\§\+Σ\Σ
ù... Push the next 3 bytes as a string
You know how this goes
a Wrap the top element in an array
6æ Repeat the next 4 instructions 6 times
\ Swap the two top items
a Wrap the top item in an array
\ Swap back
+ Combine the two arrays
This puts all the strings into a single array
6 Push a 6
┼ Push the element two items down (the array)
\ Swap with the 6 (this basically duplicates the array)
ùùùù Push "ùùù"
\§ Swap and get the 6th character (wrapping)
\ Swap with array : ["ù", [..]]
+ Prepend to array (implicitly mapping)
Σ\Σ Join both the lists to strings and output
Quine 4:
"""▐ ⌠▌ ⌠▌ ⌠▌ ⌠ ⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠ ⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠⌠"`~
"" Push the empty string
"..." Push some code : ['','...']
` Copy the top two elements of the stack : ['','...','','...']
~ Evaluate the top element as code : ['','...','']
▐ Prepend the empty string to the code
⌠ Push a space and increment by 2 to get a quote
▌ Prepend to the array
⌠▌ ⌠▌ ⌠ Repeat three more times, leaving the last on top : ['', '""...','"']
⌠⌠... Push a space and increment until it reaches a '`'
⌠⌠... Repeat for the '~' : ['','"""...','"','`','~']
Implicitly output
Quine 5:
♠ Push 256
((... Decrement until it reaches the correct byte representing the code
Repeat for each character of the code
DÄ Repeat the next instruction 14 times
ß Wrap the top 4 elements in an array
─ Flatten the resulting monstrosity
· Triplicate the array
ö Map the next 7 instructions over the array
Stack : [[..],[..],num]
♠ Push 128
, Reverse subtraction : [[..],[..],128-num
♦M-$ Push the ( character
* Repeat it 128-num times
DÄß─ Gather that up in an array and flatten again
ö Map the next 6 instructions
7($$$qq
7($$$q Print a ♠, without newline
q Print the brackets without newline
Stack : [[..],[..]]
$ Map the number to their values in the code page
Äq Map print over each element
╘ Discard the last element of the stack
Quine 6:
The reason this quine is so much longer than the others is that incrementing strings uses unicode representations, which really sucks for the some of the characters in the code, especially when we're trying to create the character ⌂ in the code, which inflates the code by over 8000 characters, which then inflates the representation part by a very large amount.
⌂ Push an * character
))... Increment until we reach the right character + 8
♫{ } Repeat 10000 times
α Wrap the top two elements in an array
♫{ } Then repeat 10000 times
m{{}} Shallowly flatten the array
h∞< Double the array
m{ Map the doubled array to
ïí1⁄2<¿{ If it is the first half of the array
⌂⌂ Push two asterisks
)))... Increment into a '⌂' (there are something like 8000 )s here, with a couple of ! to help
@ Rotate the top three elements
Stack : ["⌂",char,"*"]
0{ α4<{}=}← Repeat while the asterisk is not the char
⌂⌡) Push a )
@ Rotate it under the char
) Increment the asterisk
;; Pop the extra copies of the character
}{ Else
⌡⌡⌡⌡} Subtract 8 from the character
}{} End map and flatten array
Print implicitly
This last quine would be reduced significantly if MathGolf was consistent on whether strings used the native code page or not.
-
\$\begingroup\$ I'm amazed by your ingenuity, I'd love some explanations on how you managed to come up with these. The first one I recognize from the original quine challenge, but the rest look like they took forever to come up with. \$\endgroup\$maxb– maxb2019年03月27日 12:14:46 +00:00Commented Mar 27, 2019 at 12:14
-
\$\begingroup\$ @maxb I'm working on a sixth quine, and I'll post explanations once I either post that or give up on it. btw, the chr/ord and incrementing characters commands seem inconsistent. The first uses the code page, where the second uses typical unicode (which is what is making the 6th quine so long) \$\endgroup\$Jo King– Jo King2019年03月28日 03:45:43 +00:00Commented Mar 28, 2019 at 3:45
-
\$\begingroup\$ I realized that some time after implementing it, I just used
chr/ordfor one of them, I should make both use the code page instead I think. \$\endgroup\$maxb– maxb2019年03月28日 07:42:48 +00:00Commented Mar 28, 2019 at 7:42
Perl 6, 3 quines, 274 bytes
Quine 1, 52 bytes
my&d={S{\d}=$_};say
d
Q{my&d={S{\d}=$_};say
d
Q{4}}
Quine 2, 102 bytes
printf |(q[printf |(q[@]xx 2 Z~|(q[printf |(q[!3]]Xx qw[1 0]))]xx 2 Z~|(q[printf |(q[!3]]Xx qw[1 0]))
Quine 3, 120 bytes
<'.EVAL'.UC,' GIVEN ',「「PRINT "<'.EVAL'.UC,' GIVEN ',「「".UC,.UC,"」」>.LC",".EVAL.EVAL".UC」」>.lc.EVAL.EVAL
Verification of distinct sets of bytes
There was a lot of maneuvering in getting that third quine. Perl 6 has 4 methods of output (that I'm aware of), say, put, print and printf. Both say and put output newlines, as I can't use both. put, print, printf all contain p and t. We can get around this partially by using EVAL to use the uppercase PRINT. From there, I don't think it's possible to get 4 quines... (though perhaps something like shell "echo 'quine'" might work)
We can then get around spacing issues by using different type of whitespace to separate operators, spaces, tabs and newlines.
Explanations:
Quine 1:
my&d={ }; # Declare a function d which
S{\d}=$_ # Which substitutes a digit with the string again
say # Print with a newline
d # The function
Q{my&d={S{\d}=$_};say # Applied to the string with the program
d
Q{4}} # With a digit where the it should be inserted again
Quine 2:
This is a quine in the format printf |(q[printf q[%s]]xx 2), i.e. it formats a copy of the string into itself. However we can't use s since that's used in the previous quine's say. So we use the string OR operator (~|) on @ and !3, to produce the %s part, but we can't do that to both the format string and the string to be inserted, so we have to do Z~ with the extra string and an empty string, though we then can't use , to separate the two, so we then do Xx qw[1 0] to string multiply by 1 and 0.
printf |( ) # Print with formatting
q[...] # The string of the program
xx 2 # Duplicated
Z~| ( ) # String or'd with
q[...] # A copy to insert the %s
Xx # String multiplied to
qw[1 0] # itself and an empty string
Quine 3:
This is an EVAL quine that tries its best to make everything uppercase to avoid conflict with the other quines. This involves a lot of EVALs as well as quite a few lc and uc to convert between cases.
<...>.lc.EVAL # Evaluate the lowercase version of the string which results in
.EVAL given 「print "<'.eval'.uc,' given ',「「".uc,.uc,"」」>.lc",".eval.eval".uc」
.EVAL # Evaluate again
.EVAL given 「...」 # Set the string to $_ and pass it to .EVAL
print "<'.eval'.uc,' given ',「「".uc # Print the first half of the quine uppercased
,.uc # Print the string uppercased
,"」」>.lc" # Print the .lc part lowercased
,".eval.eval".uc # Print the EVAL part uppercased
Python 2, 2 quines, (削除) 434 (削除ここまで) (削除) 353 (削除ここまで) (削除) 349 (削除ここまで) 446 bytes
This was mostly just to see if I could do it in Python.
30 bytes (including a trailing newline):
z='z=%r;print z%%z';print z%z
and 416 bytes, with no trailing newline:
exec"696d706f7274207379730a793d222222696d706f7274207379730a793d7b7d0a7379732e7374646f75742e777269746528276578656322272b792e666f726d6174282722272a332b792b2722272a33292e656e636f6465282268657822292b27222e6465636f64652822686578222927292222220a7379732e7374646f75742e777269746528276578656322272b792e666f726d6174282722272a332b792b2722272a33292e656e636f6465282268657822292b27222e6465636f6465282268657822292729".decode("hex")
(Golfed 81 bytes thanks to Lynn but added a load due to caring about the newline.)
Explanation
The first one is just the standard short Python quine, but modified not to use _. Since this is Python 2 it also doesn't use ( or ).
The second one took some thought. The long string is encoded using the hex codec (thus guaranteeing that it will only contain 0-9 and a-f) and decodes as
import sys
y="""import sys
y={}
sys.stdout.write('exec"'+y.format('"'*3+y+'"'*3).encode("hex")+'".decode("hex")')"""
sys.stdout.write('exec"'+y.format('"'*3+y+'"'*3).encode("hex")+'".decode("hex")')
This uses quine trickery to get its own source code, then encodes it using hex_codec, and then prints it surrounded by exec"".decode("hex"), using sys.stdout.write to avoid printing a newline. Running this code outputs the second quine, which is how I generated it.
I suspect that more than two is impossible in Python, though I would like to see it if I'm wrong!
If you don't mind eval quines
Ørjan Johansen suggested the following for the pre-encoded second quine
y="""import sys
sys.stdout.write('exec"'+('y='+'"'*3+y+'"'*3+';exec y').encode("hex")+'".decode("hex")')""";exec y
which would score 30+248=278 bytes for the following output:
exec"793d222222696d706f7274207379730a7379732e7374646f75742e777269746528276578656322272b2827793d272b2722272a332b792b2722272a332b273b65786563207927292e656e636f6465282268657822292b27222e6465636f64652822686578222927292222223b657865632079".decode("hex")
The use of exec in this way is not cheating according to the PPCG proper quine rules but it feels somewhat cheaty to me (elegant and clever, but still cheaty), because some characters are being used as both code and data. (Although my version does use exec, the code and the data are separate.) So I will keep my score at 446.
-
1\$\begingroup\$
"hex"works instead of"hex_codec", which should save you a few bytes! \$\endgroup\$lynn– lynn2018年04月30日 12:07:31 +00:00Commented Apr 30, 2018 at 12:07 -
1\$\begingroup\$ Why don't you just add a blank line at the end of the first quine if trailing newlines matter...? \$\endgroup\$mbomb007– mbomb0072018年04月30日 15:17:28 +00:00Commented Apr 30, 2018 at 15:17
-
1\$\begingroup\$ Like this. I understand this is a pretty standard quine trick in languages with exec/eval. \$\endgroup\$Ørjan Johansen– Ørjan Johansen2018年04月30日 23:44:42 +00:00Commented Apr 30, 2018 at 23:44
-
1
-
2
Japt, (削除) 2 (削除ここまで) 3 quines, (削除) 106 (削除ここまで) 172 bytes
The first one is a pretty verbose version of my N char quine answer.
[91,57,49,100,185,44,85,44,186,57,51,100,185,44,186,49,48,100,185,44,186,85,109,100,185,172,93,172]
[91d1,U,o93d1,o10d1,oUmd1¬]¬
The second quine is ETHProduction's greater good quine, which is a good standard quine for Japt.
"iQ 2"iQ 2
The third one uses `` and char-code XORing to store the data.
T=`f=fR;Zff-R-ReX%`;`T=\``+T+Tc^#
Since ()' are still available, it might be possible to squeeze out one more quine.
-
1\$\begingroup\$ I really, really want to try to golf the first one but I know that, with a few beers on board, as soon as I try to change a single character, my brain will explode! Damned quines! \$\endgroup\$Shaggy– Shaggy2018年04月27日 21:51:32 +00:00Commented Apr 27, 2018 at 21:51
-
\$\begingroup\$ @Shaggy Taking the bottom line and running it through
"'[+U+']+R+(Umd)¬"q mcgives you the first line for quick updates, if that's any help. \$\endgroup\$Etheryte– Etheryte2018年04月28日 10:03:51 +00:00Commented Apr 28, 2018 at 10:03 -
\$\begingroup\$ I've also refactored the first solution to have more core symbols available, it might be practically possible to add one more quine now. \$\endgroup\$Etheryte– Etheryte2018年04月28日 11:16:22 +00:00Commented Apr 28, 2018 at 11:16
-
\$\begingroup\$ Wait, now your score is higher! \$\endgroup\$Shaggy– Shaggy2018年04月28日 23:06:02 +00:00Commented Apr 28, 2018 at 23:06
-
\$\begingroup\$ @Shaggy Intentionally so, I'm trying to make room for another quine, not make it shorter. \$\endgroup\$Etheryte– Etheryte2018年04月29日 07:30:37 +00:00Commented Apr 29, 2018 at 7:30
Javascript ES6, 2 quines, 43 + 22 = 65 bytes
Quine 1:
(function f(){return[,f,'))'].join('(')}())
Quine 2:
g=z=>"g="+g+";g``";g``
-
\$\begingroup\$ You could save a few bytes by not invoking the functions and then by using a template literal in the second one. \$\endgroup\$Shaggy– Shaggy2018年04月28日 09:49:12 +00:00Commented Apr 28, 2018 at 9:49
-
2\$\begingroup\$ So JavaScript outgolfs japt \$\endgroup\$dylnan– dylnan2018年04月28日 19:28:59 +00:00Commented Apr 28, 2018 at 19:28
-
\$\begingroup\$ @dylnan Not until it adds a third quine. \$\endgroup\$Etheryte– Etheryte2018年04月29日 12:23:22 +00:00Commented Apr 29, 2018 at 12:23
-
\$\begingroup\$ @Shaggy hey, thanks for your input, but I'm confused - shouldn't a quine be a full program? If it can be a function, must it print only itself? So would
g=z=>"g="+gbe a valid JS quine? \$\endgroup\$Pedro A– Pedro A2018年04月30日 12:15:58 +00:00Commented Apr 30, 2018 at 12:15 -
1\$\begingroup\$ @Nit I'll see what I can do :P when dylnan commented, japt had only 2 quines as well \$\endgroup\$Pedro A– Pedro A2018年04月30日 12:16:43 +00:00Commented Apr 30, 2018 at 12:16
Gol><>, (削除) 2 (削除ここまで) 3 quines, (削除) 17 28 27 (削除ここまで) 26 bytes
6 bytes
"r2ssH
(削除) 11 10 (削除ここまで) 9 bytes
'3d*Wo{|;
11 bytes
Eh`#Ma0piS0
Gol><> has three ways to print any char:
oPop one value and print as charHPop everything, print as char, and haltS"..."Print string literal without affecting the stack at all
But I couldn't find a way to write a quine using S"..." as the only output method, so I came up with the above two, utilizing the two kinds of string literals.
The third one (by Jo King) uses the p command to create the " in S" on the fly, which in turn prints everything except the zero at the end. Then Eh prints the zero and exits.
Now that we used up all the output commands AND the p command, I believe it's impossible to create another quine (unless someone comes up with the S" quine without p).
Ruby, 2 quines, 27 + 44 = 71 bytes
$><<<<2*2<<2
$><<<<2*2<<2
2
s=%q{s=%q{S};s[?S]=s;puts s};s[?S]=s;puts s
I'm mainly limited by methods of output, here. There are quite a few ways of manipulating strings, but aside from $><< all the usable output methods seem to intersect too much. I think there might be a way out with eval but it's tricky having to nest multiple string manipulations of different kinds.
><>, 2 quines, 8 + 16 = 24 bytes
8 bytes
#o<}-1:"
Taken from this answer.
16 bytes
'r3d*d8*7+e0p>>|
This is based on the 'r3d*>o< quine, except o and < cannot be used, so I replaced < with | and dynamically created o (111 = 8*13 + 7) and placed it where the 2nd > is.
2 quines is the limit
Unfortunately, we're limited by the number of output commands. n is not useful because it only outputs numbers, so o must be executed in any quine. The only way to dynamically create o is with p. So one quine can use o, and another can create it with p, but there can be no 3rd quine.
It might be possible to have a third quine leave the source code on the stack if that counts.
Java 10, 2 quines, (削除) 1448 (削除ここまで) 1248 bytes
(削除) 1350 (削除ここまで) 1122 bytes
\u0076\u002D\u003E\u007B\u0076\u0061\u0072\u0020\u0072\u003D\u0022\u0076\u002D\u003E\u007B\u0076\u0061\u0072\u0020\u0072\u003D\u0025\u0063\u0025\u0073\u0025\u0031\u0024\u0063\u003B\u0072\u002E\u0066\u006F\u0072\u006D\u0061\u0074\u0028\u0072\u002C\u0033\u0034\u002C\u0072\u002C\u0039\u0032\u0029\u002E\u0063\u0068\u0061\u0072\u0073\u0028\u0029\u002E\u0066\u006F\u0072\u0045\u0061\u0063\u0068\u0028\u0063\u002D\u003E\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u0066\u0028\u0025\u0031\u0024\u0063\u0025\u0063\u0025\u0033\u0024\u0063\u0075\u0025\u0025\u0030\u0034\u0058\u0025\u0031\u0024\u0063\u002C\u0063\u0029\u0029\u003B\u007D\u0022\u003B\u0072\u002E\u0066\u006F\u0072\u006D\u0061\u0074\u0028\u0072\u002C\u0033\u0034\u002C\u0072\u002C\u0039\u0032\u0029\u002E\u0063\u0068\u0061\u0072\u0073\u0028\u0029\u002E\u0066\u006F\u0072\u0045\u0061\u0063\u0068\u0028\u0063\u002D\u003E\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u0066\u0028\u0022\u005C\u005C\u0075\u0025\u0030\u0034\u0058\u0022\u002C\u0063\u0029\u0029\u003B\u007D
Equivalent to:
v->{var r="v->{var r=%c%s%1$c;r.format(r,34,r,92).chars().forEach(c->System.out.printf(%1$c%c%3$cu%%04X%1$c,c));}";r.format(r,34,r,92).chars().forEach(c->System.out.printf("\\u%04X",c));}
Explanation:
v->{ // Method with empty unused parameter and no return-type
var r="v->{var r=%c%s%1$c;r.format(r,34,r,92).chars().forEach(c->System.out.printf(%1$c%c%3$cu%%04X%1$c,c));}";
// Unformatted source code
r.format(r,34,r,92) // Formatted quine
.chars() // Loop over the characters as integers
.forEach(c->System.out.printf("\\u%04X",c));}
// Print "\u" with hexadecimal value of these characters
126 bytes
v->{int i='}'-'[';var s="v->{int i='}'-'[';var s=%c%s%c;System.console().printf(s,i,s,i);}";System.console().printf(s,i,s,i);}
System.console() will return null when none is provided, so TIO returns a NullPointerException in this case.
To prove it's a working quine, replace System.console() with System.out: Try it online.
Explanation:
v->{ // Method with empty unused parameter and no return-type
int i='}'-'['; // Integer `i` = 34 (unicode value for double-quote)
var s="v->{int i='}'-'[';var s=%c%s%c;System.console().printf(s,i,s,i);}";
// Unformatted source code
System.console().printf(s,i,s,i);}
// Print formatted quine
General explanation:
In Java a quine is usually done like this:
- The
String scontains the unformatted source code. %sis used to input this String into itself with thes.format(...).%c,%1$cand the34are used to format the double-quotes.s.format(s,34,s)puts it all together.
In which case the shortest quine lambda-function in Java 10 would be this (82 bytes):
v->{var s="v->{var s=%c%s%1$c;return s.format(s,34,s);}";return s.format(s,34,s);}
Since the only way to have two quines in Java is using the unicode version with \uHEXA, which is converted to characters during compilation, I'm unable to use the characters 0123456789ABCDEF\u in the non-unicode version. So, the smaller non-unicode version will use System.console() instead of return or System.out (both containing a 'u'), and will use '}'-'[' and two times %c instead of 34 and %1$c.
Some things to note about the unicode version:
- I'm on purpose using
%04Xinstead of%04x(for uppercase Hexadecimal instead of lowercase). - I'm using
92,%cand%3$cto format the slashes. - Using a capital
\Uinstead of lowercase\uisn't allowed apparently, otherwise I would have just usedreturnin the shorter non-unicode version.
Explore related questions
See similar questions with these tags.