# Program compressor

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

• Please make the objective and rules of the challenge clearer. Jan 19, 2022 at 16:56
– l4m2
Jan 19, 2022 at 17:01
• Well, what is the program intended to do exactly, and how does the scoring system work? Jan 19, 2022 at 17:04
• @Binary198 To compress all programs but finite ones. Some users would make four questions for four scoring way but it likely make a mess
– l4m2
Jan 19, 2022 at 17:07
• 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. Jan 19, 2022 at 17:10

# 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,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.

• Do you save one byte iff length>1500?
– l4m2
Jan 19, 2022 at 17:21
• @l4m2 Yes, exactly Jan 19, 2022 at 17:22
• 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). Jan 19, 2022 at 19:02
• 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,l+(l!=1500))or s.to_bytes(l,"big") for $L=78$ TIO Jan 19, 2022 at 19:09
• Hmm, maybe not - I don't understand this error Jan 19, 2022 at 19:26