Skip to main content
8 of 8
added 27 characters in body
user202729
  • 17.6k
  • 2
  • 39
  • 71

dc (GNU), 2 distinct characters (z, P), 134660653084537 bytes

The behavior of P on number is a GNU extension.

(can't post code)

Anyway, this is the generator program: Try it online!

You can verify manually that for some smaller text (such as abca) it produces the correct output. It will only actually try to construct the program if the resulting program size does not exceed \$2^{16}\$ (configurable in the program)

Assuming that the actual dc implementation doesn't have any problem with having about that many numbers on the stack.

I came up with the idea when someone mentioned in chat that it's possible to solve the challenge with 2 distinct bytes.


Explanation:

To print out the string in dc, obviously a character printing command is required (I use P), and something to push to the stack is required.

As far as I can see, the only commands that push something to the stack while the stack is empty are 0-9A-F (pushes the corresponding digit/sequence of number interpreted in base 10), . (pushes 0.0 = 0), _ (pushes -0 = 0) I/ll/O/K (pushes 0/0/10/10 by default), z (push the number of values currently in the stack). Of those only z have the potential to produce any values.

Therefore, with only z and P, at any time the stack is [0, 1, 2, ..., n], and P will print the value corresponding to n and pop n.

the integer portion of its absolute value is printed out as a "base (UCHAR_MAX+1)" byte stream

So the program \$\text{‘z'}^{a_1} + \text{‘P'} + \text{‘z'}^{a_2} + \text{‘P'} + \text{‘z'}^{a_3} + \ldots + \text{‘P'} + \text{‘z'}^{a_n} + \text{‘P'}\$ will call P on \$a_1-1, a_1+a_2-2, \ldots, (a_1+\ldots+a_n-n)\$.

user202729
  • 17.6k
  • 2
  • 39
  • 71