Whilst trying to golf several of my answers, I've needed to write large integers in as few characters as possible.

Now I know the best way to do that: I'll be getting you to be writing this program.

The challenge

  • Write a program that when given a positive integer, outputs a program that prints it to stdout or equivalent.
  • The output programs don't have to be in the same language as the creator.
  • The output must be at most 128 bytes.
  • You may accept input from stdin or equivalent (not function input)
  • You may output the resulting program to stdout or equivalent.
  • The number output must be in decimal (base 10)


Your score is equal to the smallest positive integer your program can not encode.

The entry with the largest score wins.

  • \$\begingroup\$ I added the tag metagolf, since we're golfing the output program. \$\endgroup\$
    – orlp
    Sep 14, 2015 at 9:13
  • 1
    \$\begingroup\$ @orlp I actually omitted it on purpose, because metagolf is a scoring criterion tag which says "the score is the length of your output". I'm considering adding a meta post about that though to allow sort of inverse scoring as well (which is the case for fastest-code for instance). \$\endgroup\$ Sep 14, 2015 at 9:14
  • 2
    \$\begingroup\$ @MartinBüttner I guess we need meta-restricted-source :) \$\endgroup\$
    – orlp
    Sep 14, 2015 at 9:16
  • 2
    \$\begingroup\$ How is the challenge different from "which language has the biggest integer range"? \$\endgroup\$
    – nwp
    Sep 14, 2015 at 14:29
  • 5
    \$\begingroup\$ @nwp I think you misunderstand the question. The question is about compression. It would be useful, but not necessary to use a language with a big integer range. \$\endgroup\$
    – potato
    Sep 14, 2015 at 20:18

7 Answers 7


Pyth, 252111 ≈ 3.593 × 10266

"252")$import sys$$sys.stdout.buffer.write(J.encode('iso-8859-1'))$

Had to use a little bit of Python syntax, because Pyth's print can't print in iso-8859-1.

The number gets encoded in base 252 and represent each digit in that base as an iso-8859-1 char. The chars \ and " would need escaping, and therefore are not used. The char ` isn't used because golfing... And additionally the null-byte is also not used, the Pyth compiler forbids it.

The output is a program with an overhead of 17 bytes:


Here's an example usage with the biggest number possible:



of the output program.

    rC1`H          create the range of chars: ['\x01', '\x02', ..., '{}']
         ``N       creates a string containing the 3 chars " ' \
   -               remove strings which consists of these 3 chars
 xL         ""     determine the index of each char in "" (encoded number)
i             252  convert from base 253 to base 10
  • 1
    \$\begingroup\$ This program fails to encode 12, because Pyth unfortunately reads CR as LF. \$\endgroup\$ Jul 13, 2016 at 22:29

CJam, 254109 ≈ 1.34 x 10262


I'm encoding the number in base 254 and represent each digit in that base as an ISO 8859-1 character, skipping " and \. The output has an overhead of 19 bytes, ""{_'[>-_'!>-}%254b, so I can represent everything less than 254128-19, or explicitly


As an example, 6153501 would be encoded as


Here is a test program which prints the encoded integer, and then prints its length, and then executes it right away to show its validity (this avoids the trouble of having to copy the unprintable characters into a new program, which doesn't always work with the online interpreter).


Perl, 10216

print"print unpack'h*',q{",(pack'h*',<>),"}"

Also base 100 encoding, slightly more elegant. Output for 12345678 would be:

print unpack'h*',q{!Ce‡}

The delimeters { and } correspond to hex values b7 and d7 respectively, which cannot appear in the input, and therefore do not need to be escaped.

There are 20 bytes of overhead, leaving 108 for encoding, reaching a maximum value of 10216-1.

Perl, 10206

print"ord=~print\$' for'",(map chr"1$_",<>=~/.{1,2}/g),"'=~/.|/g"

Simple base 100 encoding. Output for 12345678 would look like this:

ord=~print$' for'p†œ²'=~/.|/g

There are 25 bytes of overhead, leaving 103 for encoding, reaching a maximum value of 10206-1.


Common Lisp, 36114 - 1 ~ 2.62 × 10117

(lambda(x)(format t"(lambda()#36r~36r)"x))

The largest number is:


Simply use base 36. For the largest input, the 128-bytes long output is:


Vyxal, 3 bytes ~\$10^{305}\$


Try it Online!

Thanks to emanresu A for 2 more orders of magnitude

Simple number compression builtin, then chop off the last char. Generates a Vyxal compressed number in base 255. Exceeds the 128 byte output limit at \$10^{305}\$, but can go up to \$10^{308}\$ if the ceiling is raised to 130 bytes.

  • 1
    \$\begingroup\$ Append a for a little more compression \$\endgroup\$
    – emanresu A
    Jun 20, 2022 at 21:06

Python 3 → CJam, (163122 − 1)·255/162 + 1 ≈ 1.213·10270

import sys
n = int(input())
for b in range(163, 1, -1):
    s = []
    m = n
    while m:
        m, r = divmod(m - 93, b)
        if m < 0:
        s.append(r + 93)
        sys.stdout.buffer.write(b'"%s"%db' % (bytes(s[::-1]), b))
    sys.stdout.buffer.write(b'%d' % n)

It turns out that every integer from 1023 through (163122 − 1)·255/162 can be represented in at least one way by a base b ≤ 163 conversion from a string of at most 122 characters with codes 93 through b + 92, rather than the usual 0 through b − 1. This avoids the troublesome characters 34 (double quote) and 92 (backslash) without any extra output code.


CJam, 233114 ≈ 7.561⋅10269


The output program "…"{iKms*}%233b decodes the 8-bit characters of a string to base 233 digits with n ↦ ⌊n ⋅ sin 20⌋ = ⌊n ⋅ 0.913⌋. This transformation happens to be surjective without requiring the critical codepoints 34 (double quote) and 92 (backslash) as input.


Your Answer

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

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