Choose a language and write a program in the language that:
- Take a valid program of the language as input,
- Output a string(bytearray, etc.). It needn't be a valid program.
- Only finite valid inputs result in longer/same-length(in bytes) output.
- Different valid input, even if behave same, lead to different output.
Let length of your code as \$L\$ and number of inputs with longer/equal-length output as \$n\$. To win, you should be lowest on at least one of:
- \$L\$,
- \$N\$,
- \$L+N\$,
- \$L+\log_2(N+1)\$.
Notes
- Solution exist so long as illegal substring exist.
-
1\$\begingroup\$ Please make the objective and rules of the challenge clearer. \$\endgroup\$Caelus– Caelus2022年01月19日 16:56:52 +00:00Commented Jan 19, 2022 at 16:56
-
1\$\begingroup\$ @Binary198 Please make your request clearer :) \$\endgroup\$l4m2– l4m22022年01月19日 17:01:31 +00:00Commented Jan 19, 2022 at 17:01
-
\$\begingroup\$ Well, what is the program intended to do exactly, and how does the scoring system work? \$\endgroup\$Caelus– Caelus2022年01月19日 17:04:22 +00:00Commented Jan 19, 2022 at 17:04
-
\$\begingroup\$ @Binary198 To compress all programs but finite ones. Some users would make four questions for four scoring way but it likely make a mess \$\endgroup\$l4m2– l4m22022年01月19日 17:07:02 +00:00Commented Jan 19, 2022 at 17:07
-
\$\begingroup\$ So, you need to take a program as input and output a unique string that will be longer than or equal to in length than the input? Still, the scoring system is weird. What is \$N\,ドル and why are there multiple scoring ways? I would usually just go with one. \$\endgroup\$Caelus– Caelus2022年01月19日 17:10:59 +00:00Commented Jan 19, 2022 at 17:10
1 Answer 1
Python 3.8 (pre-release), \$L=79\$, \$N\approx255^{1500}\$
-3 bytes thanks to @Jonathan Allan
f=lambda b,s=0,l=0:b and f(b[1:],255*s+b[0],l+1)or s.to_bytes(l-(l>1500),"big")
Python source code can't contain null bytes. This converts the input (bytestring) to base 255 and then back to bytes. After 1500 removes a redundant byte.
-
\$\begingroup\$ Do you save one byte iff length>1500? \$\endgroup\$l4m2– l4m22022年01月19日 17:21:39 +00:00Commented Jan 19, 2022 at 17:21
-
\$\begingroup\$ @l4m2 Yes, exactly \$\endgroup\$AnttiP– AnttiP2022年01月19日 17:22:52 +00:00Commented Jan 19, 2022 at 17:22
-
\$\begingroup\$ You don't need the
f=
(I guess you were going to go with a recursive function which would need it, and left it in). \$\endgroup\$Jonathan Allan– Jonathan Allan2022年01月19日 19:02:55 +00:00Commented Jan 19, 2022 at 19:02 -
1\$\begingroup\$ Using recursion (which I think we may assume to have no limit set for code-golf purposes), you could do
f=lambda b,s=0,l=0:b and f(b[1:],255*s+b[0],l+(l!=1500))or s.to_bytes(l,"big")
for \$L=78\$ TIO \$\endgroup\$Jonathan Allan– Jonathan Allan2022年01月19日 19:09:38 +00:00Commented Jan 19, 2022 at 19:09 -
\$\begingroup\$ Hmm, maybe not - I don't understand this error \$\endgroup\$Jonathan Allan– Jonathan Allan2022年01月19日 19:26:30 +00:00Commented Jan 19, 2022 at 19:26
Explore related questions
See similar questions with these tags.