Défi
Votre tâche consiste à écrire un morceau de code qui en génère un autre. Ce code doit à son tour générer un autre code jusqu'à ce que le code final fournisse le nombre entier 1 . La chaîne se termine la première fois que 1 est sorti.
Aucun de vos programmes ne peut partager des caractères (il y a une exception dans la section Rules).
La soumission gagnante sera la soumission avec la plus longue chaîne. Le départage sera le code-longueur total le plus court.
Règles:
- Vous pouvez utiliser les deux fonctions, programmes et extraits. Vous pouvez supposer un environnement REPL.
- Toutes les fonctions doivent être écrites dans la même langue
- Les langues indépendantes des symboles sont interdites. Ceci inclut des langages partiellement indépendants des symboles, tels que Headsecks.
- Le formatage de sortie par défaut peut éventuellement être ignoré dans la sortie d'une fonction. Cela inclut les retours à la ligne,
ans =
etc. - Vous pouvez réutiliser le caractère espace (code de code ASCII 32), mais notez les points suivants:
- Vous pouvez utiliser autant de caractères d'espacement que vous le souhaitez dans l'une des fonctions, mais limitez-le à un maximum de 5 dans toutes les autres fonctions.
- Vous ne pouvez réutiliser aucun caractère si le code 32 n'est pas un espace dans votre langue.
Aucun des programmes ne peut prendre d’entrée
La chaîne doit avoir au moins deux programmes.
Exemple:
Votre code initial est abc+cab+bac
. Cette sortie:, foofoo*123
qui à son tour disp(~0)
, sortie 1
. Ceci est une chaîne de 3 programmes, avec une longueur combinée de 29 (tie breaker).
code-challenge
code-generation
Stewie Griffin
la source
la source
2^3
, qui vient d' évaluer à1
, ou at - il par exemple êtrelambda:2^3
,print(2^3)
etc.?1
être à la fois un programme et le résultat de ce programme ou la chaîne se termine-t-elle quand1
le résultat est-il?Réponses:
05AB1E , 5 chaînes: 236 + 29 + 13 + 3 + 1 = 282 octets
Essayez-le en ligne!
qui imprime le programme
Essayez-le en ligne!
qui imprime le programme
Essayez-le en ligne!
qui imprime le programme
Essayez-le en ligne!
qui imprime le programme
Essayez-le en ligne!
qui imprime
1
la source
8784>žxB
et je suis probablement KO'd. Le manque de nombres pour la conversion de base est un craps total, sauf si vous le calculez. Si vous voulez battre emigna, l’objectif est d’utiliser le moins de nombres uniques par itération. Sa réponse règne en maître à cause des 88 dans l'avant-dernière itération. Vraiment une bonne réponse.10
et créer quelque chose en binaire. Mais je ne sais pas si nous pouvons générer le premier programme à partir de binaire sansB
.Java 8, chain of 2 functions,
90+1037+428+4 = 32 bytesWhich is equivalent to:
-57 bytes thanks to @OlivierGrégoire.
Try it online.
Which returns the String:
Try it online.
Which returns the integer:
la source
\u0076\u002D\u003E\u0022\u0076\u002D\u003E\u0022+(3\u002D2)
(59 bytes+4 bytes). The rules says "None of your programs may share any characters", sov->1
is valid because the final1
isn't a program.v->1
returning 1 is valid, but in my original answer\u0031
would contain a 1, andv->1
would then contain a 1 as well. Nice combination of both unicode Java and regular Java, though. And I golfed 2 more by changing(2/2)
to2/2
. (PS: There is also already a chain-3 Java answer by Jakob.)"\44\55\76"
instead of"\u0076\u002D\u003E"
R, 3-chain 198 + 44 + 3 bytes
Try it online!
Returns :
Try it online!
Returns :
Try it online!
Returns
1
Explanation :
The first program is almost totally written in octal representation, where each character is written as
\xxx
wherexxx
is the ASCII code in octal mode. In human readable form would be :Here, to avoid the use of round brackets we redefine the prefix operator
+
equal tocat
function, then we use that to print the next string. Even after assigningcat
to+
, the latter still keeps its prefix operator "status" and will just take whatever follows it as its first parameter.The second program, simply prints the characters
F^F
obtaining them from decimal ASCII :70,94,70
Since in the first program we used the octal representation, only numbers
8
and9
are free to be used; hence, we obtain70
and94
with some differences between numbers with only8's
and9's
.Finally, the last program,
F^F
, exploits the^
function (power of) which coercesFALSE
to0
and computes0^0
returning1
Credits to :
+
in order to avoid bracketsPrevious version :
R, 2-chain
27+324 + 2 bytesTry it online!
Returns:
Try it online!
Returns
1
.la source
cat
mandatory?"wri\164e"(function args)
to avoid at
or other similar encodingscat(intToUtf8(c(49,76)))
would work and is a bit shorter. Doesn't expand the chain though.Python 2, 2-Chain, 7+44 = 51 bytes
and
Try it online!
The base 16 code translates to
print 1
, which is returned by the anonymous function.la source
Perl 5, 3-chain,
151139 chars (114 + 20 + 5)The ugliness inside the
&{ }
evaluates toCORE::syswrite
, and so the hex-escaped string is printed to standard output as:Please note that the ^C and ^R in the above represent literal control characters. (And not to be confused with the literal
^
caret that occurs between the two strings.)This program in turn outputs:
la source
Octave, 3 programs, Length 42 bytes
Outputs:
[[63 24]*2 '']
. Try it online!Outputs:
~0
. Try it online!Outputs:
1
. Try it online!la source
Cjam, 4-chain, 28+20+3+1=52 bytes
Snippet 1:
Snippet 2:
Snippet 3:
Snippet 4:
Which then prints 1.
Try it online!
Note:
Since Cjam does not have interpretation for escape characters, the ones in snippet 1 are only there for better web view. You need to use the corresponding actual characters to run the snippet.
If I cannot shave off more characters, then good job to @Emigna for the
05AB1E
answer!la source
1
used in snippet 1Excel, Chain 2, 27+3 bytes
Not sure if this is OK...
la source
CHAR(61)&
in the beginning as well for there to be a chain of 2?CHAR
becomeCAR
, 3 bytes saved), not sure if another language reduce it more--1
in a cell and hit enter, it would just show1
on the screen...=
implicitly if you type--1
.=
mark for+1
(but it does for--1
), so I won't consider it as an expression. And I'm not sure if simply writing an1
in the cell and call it "output 1" is valid. That's why--1
is used.x86 bytecode, Chain 2, 10+4 bytes
(Assembled with FASM, format PE)
ÇA.Ï?¿<÷Y.
produces1À@Ã
in the address next to it and executes it, which returns1
in eax (as per fastcall). In both cases the.
actually representsA
or LF.In hex:
C7 41 0A CF 3F BF 3C F7 59 0A
and31 C0 40 C3
.Disassembled:
produces
This (ab?)uses the fact that the entrypoint of the program is stored in ecx, and then writes the inverse of the to be executed code to the address 10 bytes over and negates it.
May or may not break if assembled with anything but fasm, to anything but a PE or with a different entrypoint.
la source
JavaScript REPL, lots of bytes, 4 iterate
Too lazy to optimize the JSFUCK code
JavaScript REPL, 164 bytes, 3 iterate
may be able to expand
Try it online!
la source
1
in other pros, so the first1
is program and the 2nd one is result{}
s?CJam, 7-chain, 92365+1819+79+14+9+3+1 bytes
This 92365-byte program prints
which prints
which prints
which prints
which prints
which prints
which prints
1
.la source
MATL, 5 programs, 404+159+35+4+1 = 603 bytes
Getting to 4 programs was hard. 5 programs was very hard!
Try it online!
Try it online!
This might be my favorite program I've written on PPCG:
Try it online!
Try it online!
Try it online!
Explanation:
Having used hours on this program, I won't write the entire explanation now! I'll write it later!
Short summary:
In order to convert this to a string instead of character codes, we need to concatenate it with a string using
h
. To get a string, without using quotes, or the XY modifiers, we do base conversion and convert an integer to whitespace.la source
CJam, 10 programs, 5,751,122,990 bytes
I was too lazy to golf it... But apparently I don't need to golf it to be competitive. But without golfing it is a bit difficult to post the solution in an answer.
It should work in the JavaScript interpreter in theory, but the program is too long to be tested in a browser. It should output the same in the Java interpreter except for the last program. But it may also run out of memory in the Java interpreter for the first few programs.
Statistics
First bytes
\n
is newline in the second program.Generator
la source
APL (Dyalog), 2 chain, 15+2 = 17 bytes
Try it online!
Outputs the program
That outputs
la source
JavaScript (ES6), 2 functions, 31+4 = 35 bytes
returns
_=>1
, which returns1
Show code snippet
la source
Jelly,
38 37 3635 bytes, Chain of 4Try it online! (18 bytes)
Try it online! (13 bytes)
Try it online! (3 bytes)
Try it online! (1 byte)
18+13+3+1=35 bytes
How?
la source
Python 2, 3 snippets, 68 + 12 + 3 = 83 bytes
which produces the string of octal literals:
which produces:
Which finally produces
1
.Try it online!
la source
Java 8, 3 programs, 431 bytes
Program 1, 332 bytes
A lambda from one (empty) parameter of any type to
String
.This is just a lambda with the arrow characters Unicode-escaped returning the text of the second program encoded with octal escape sequences.
Try It Online
Program 2, 93 bytes
Snippet producing a
String
.Try It Online (with return added)
Program 3, 6 bytes
A lambda from one (empty) parameter of any type to
int
.Try It Online
la source
\166
to\44
for -1 byte, since$
is also a valid variable name. Try it online, resulting in$->9-8
(Try it online.)\uXXXX
in the first code to avoid->
. Then you need eitherreturn
(function) orSystem.out
(snippet or function), both contain au
which you already used in\uXXXX
. So I personally think this entry is invalid and I downvoted it accordingly.System.console().printf
could be used to prevent the use ofu
. Something similar is done in this answer and I've also used it in these two answers of mine.x->"\146\157\162\50\143\150\141\162\40\44\72\156\145\167\40\143\150\141\162\133\135\173\47\171\47\54\47\54\47\54\47\75\47\54\47\70\47\54\47\56\47\54\47\70\47\175\51\123\171\163\164\145\155\56\143\157\156\163\157\154\145\50\51\56\160\162\151\156\164\146\50\53\53\44\53\156\145\167\40\123\164\162\151\156\147\50\51\51\73"
(319 bytes) turns intofor(char $:new char[]{'y',',','=','8','.','8'})System.out.printf(++$+new String());
(89 bytes) turns intoz->9/9
(6 bytes). Total: 404 bytes.System.console()
for the 2nd program, which is correctly 89 bytes (while theSystem.out
makes it 83 bytes).SmileBASIC, chain 3, 375 bytes
Outputs:
Outputs:
Outputs:
la source
PHP 7.0, 2-chain, 35 + 8 = 43 bytes
While writing my initial answer I realized I could just use base64 encode the second echo. It shaved off 11 bytes, so here it is. You can find my original idea below, too.
Run using php -r:
This outputs:
Which then obviously prints:
Output:
My code when run in a terminal. The appended && echo is for readability only.
Comments:
There's not much to it really. Very simple once you know about "?>" implicitly acting as ";". The "tricky" part was to figure out what to encode:
Alternatively we can use "echO" and "ECHo", too (36 + 7 = 43 bytes).
We can also switch the ; and ?> around using that. It works equally well and it all scores the same in length.
My initial solution:
PHP 7.0, 2-chain, 44 + 10 = 54 bytes
This is the best I could come up with at first. I understood that "unique characters" meant "echo" is not equal to "ECHO". Hope I got that right!
Run using php -r:
This outputs:
Which in turn gives us our number:
Output:
My code when run in a terminal. The appended && echo is for readability only.
Some comments:
Thanks for the challenge, I learned something today!
la source
Lua, 2 chain, 83+8=91 bytes
Outputs
Which outputs
la source
Charcoal, 2 programs, 10 + 2 = 12 bytes
Try it online! Outputs
Try it online! Which outputs 1.
la source
Braingolf, 2 chain, 9 + 2 = 11 bytes
Try it online!
This outputs
Try it online!
(Plus some default output which can be ignored per OP's rules)
This in turn outputs
la source
Röda, 2 chain, 31 + 3 = 34 bytes
Snippet 1:
Try it online!
Snippet 2:
Try it online!
They are snippets, because every valid Röda program must include
main{...}
bloat. They are also valid Röda REPL programs.la source
dc, 3 programs, 48 bytes
First:
Yields the second:
Yields the third:
Yields
1
.Try it online! (has some stack-clearing and newline-printing code thrown in to make all three bits run in one go).
Perhaps best to start at program three,
KZn
. There are only a few ways to print things indc
, and I realized at this stage I would probably be stuck with eitherp
orn
, both of which are in the 100s in decimal ASCII. This means that I was almost certainly going to have to generate 1 instead of just using the program1n
.K
pushes the current (default: 0) precision to the stack, andZ
pushes the number of digits of top-of-stack, which gives us the 1 to print.The second program is pretty straightforward.
P
prints the character with the given ASCII value, so we print75
(K
)90
(Z
) and finally110
(n
), which works wonderfully. It also means that, aside from the aforementioned 1, I can't use the digits 5, 7, 9, or 0 elsewhere. I also need a method other thanP
for turning numbers into characters.The first program, then, has to make four numbers without using the digits 1, 5, 7, 9, or 0. It needs to make
80
(ASCII value ofP
):82 2-
;75
:AA
(110)I-
(subtract the default input radix, 10)I2/
(so, 5)2^
(so, 5^2, 25)-
(75);90
:AA
(110)I2*
(twice the default input radix of 10, so 20)-
(90); and110
: well, it's justAA
. After making80
, we usea
to convert a number to a string. There are somer
everse andd
uplicate commands in there to put theP
s in the right spots, and then finally we print the whole stack withf
.I'm pretty sure I didn't screw this up, but I did have my head spinning a little bit...
la source
05AB1E, 5 + 3 = 8 bytes
Try it online!
which right off the bat returns
I am taking the output 1.0 as not equalling 1, so I run that code:
Try it online!
which returns
And there you go!
Number of programs =
2
la source
h
(convert to hexadecimal). Theg
(get length, default 0) witht
(square-root) already gives a decimal0.0
. With<
(decrease by 1) it becomes-1.0
and thenn
(square) changes this into1.0
. You could also replace the<n
with>
(increase by 1). ;) So in total it's 3 bytes (gt>
). Alternatively you could useXt
(1
and square-root). PS: I'm not sure if1.0
to1
is a valid part of the chain. I've asked OP to verify. Welcome to PPCG and enjoy your stay.Ruby, 2-chain, 24+3 = 27 bytes
Output is
la source