-2
\$\begingroup\$

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

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Please make the objective and rules of the challenge clearer. \$\endgroup\$
    – Binary198
    Jan 19, 2022 at 16:56
  • 1
    \$\begingroup\$ @Binary198 Please make your request clearer :) \$\endgroup\$
    – l4m2
    Jan 19, 2022 at 17:01
  • \$\begingroup\$ Well, what is the program intended to do exactly, and how does the scoring system work? \$\endgroup\$
    – Binary198
    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
    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\$
    – Binary198
    Jan 19, 2022 at 17:10

1 Answer 1

3
\$\begingroup\$

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")

Try it online!

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.

\$\endgroup\$
7
  • \$\begingroup\$ Do you save one byte iff length>1500? \$\endgroup\$
    – l4m2
    Jan 19, 2022 at 17:21
  • \$\begingroup\$ @l4m2 Yes, exactly \$\endgroup\$
    – AnttiP
    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\$ 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\$ Jan 19, 2022 at 19:09
  • \$\begingroup\$ Hmm, maybe not - I don't understand this error \$\endgroup\$ Jan 19, 2022 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.