# What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?

I think the question as above is clear, but just in case:

• Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline.

• Qualifying programs will be those whose output is longer (in bytes) than the source code of the program, measured in bytes (assuming ASCII or UTF-8 encoding for the program source code).

I.e. the code must be shorter than the number of digits in the resulting number.

• Leading zeros are disallowed under all circumstances. Counting leading zeroes trivialises the problem; ignoring leading zeros unnecessarily complicates the question.

• The winning program will be the qualifying program which prints the integer with the smallest magnitude.

var QUESTION_ID = 67921;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*)(?:,|[-\u2013] ).*?([\d,^!e+]+)(?=\:?[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
function getAuthorName(a) { return a.owner.display_name; }
function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.replace(/<sup>([^\n<]*)<\/sup>/g, "^$1").replace(/$$\d+(?:\^\d+,)? [\w\s]+$$/g, "").replace(/floor$$10\^(\d+)\/9$$/g, "$1 ones").replace(/(\d+) ones/g, function (_, x) { return Array(+x + 1).join(1); }).match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2].replace(/,/g, "").replace(/(\d+)\s*\^\s*(\d+)/, function (_, a, b) { return Math.pow(a, b); }).replace(/(\d+)!/, function (_, n) { for (var i = 1, j = 1; i <= n; i++) j *= i; return j; }), language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style>
<div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table>

• Number 1 on the Hot Network Questions. Not bad for a first question... – trichoplax Dec 28 '15 at 15:15
• @Kslkgh Strictly less than, otherwise the question is trivial for programs which implicitly print their last value. – Arandur Dec 28 '15 at 15:57
• Is 1.0 an integer? – histocrat Dec 28 '15 at 20:05
• The restriction to UTF-8 is ridiculous and detrimental. Bytes are bytes, no matter the encoding. I strongly recommend that you change the rules, as as they currently are they disallow languages that are not character-based (e.g. Minecraft, Piet, Folders) or have longer UTF-8 byte counts than their "real" (valid according to this question) byte counts (e.g. APL, TI-BASIC, Seriously, Jelly). – lirtosiast Dec 29 '15 at 3:35
• @ZachGates that's not how the HNQ list works. ;) – Martin Ender Dec 29 '15 at 8:38

## Python 2, 1000000000

A simple program in a simple language. I have two answers depending on wether the python shell is permitted or not.

If it isn't, then:

print 1e9


Which is 9 bytes and outputs 1000000000, 10 bytes.

If it is, then:

1e3


Which is 3 bytes and outputs 1000, 4 bytes.

These ignore the .0 printed on the end of these numbers since the method returns a float and the question asks for an int.

## PHP, 9223372036854775807

I know they're not the shortest for PHP but..

### 9223372036854775807

<?=PHP_INT_MAX;


### 10000000000000000000

<?=str_pad(1,20,0);


# Python 3, 100000000000

One digit shorter than the current python 3

print(1e11)


prints 1*(10^11)

# C, 1844674407370955161518446744073709551615 (40 digits)

main(){printf("%lu%1$lu",-1ul);}  Certainly not winning, but it's a fun challenge and this is a fun answer. How it works: • The printf format specifier %lu prints a long unsigned integer. • The printf format specifier %1$lu prints the first long unsigned integer in printf's argument list.
• -1ul in printf's argument list is -1 cast to an unsigned long. Since the value is negative and the integer is unsigned, it turns into the maximum value an unsigned long can hold.
• Actually, -1ul is an unsigned long value 1, negated. (unsigned long)-1 would be -1 cast to an unsigned long. BTW, you could reduce the score a little by using -9ul. – Toby Speight Mar 12 '18 at 10:59

## Whitespace, 11111111111111111111111111111111111111 (38 ones)

Visible representation:

SSTTSSTTSNNSSNSSSTNSNSTNSTTSSSSNSNTTN


What it does:

     push -38
loop:
push 1
dup
pnum
dup
jn loop


Surprisingly short for a whitespace program. Other considered approaches were pushing a big integer followed by a sequence of duplicate-multiply but this proved to be less efficient.

# Brain-Flak, 106735757048926755512911448358783973263883108352

48 digits, 46 bytes.

(((()()()){})){({}[()]<(({({}[()])}{}){})>)}{}


Try it online! (but not really because it will error with a segment fault).

This uses the common triangular method, ({{}[()]}), but applies it recursively on the previous result. It starts with 6 as both the counter and the total and starts the loop, first decrementing the counter, then replacing the total with 2*triangle(total). Repeat a few times and it gets exponential, with each repetition roughly doubling the amount of digits.

Python code used to calculate the total:

def tri(t):
return (t)*(t-1)/2

def f(n,t):
for _ in range(n):
t = tri(t)*2
return t

print(len(str(int(f(6,6)))))


Try it online!

# PHP, 10000000

10 million (8 digits) printed in 7 bytes:

<?=1e7;


Almost 2.5 years and I am the first to think of that? Amazing.

# Perl 6, 10000000

1e7.say


Try it online!

I can't see any Perl6 solutions, so for completeness...

# Attache, 8 bytes

8^9|Echo


Try it online!

Outputs 134217728.

# ForceLang, 1013

io.write 1e13


## Keg-hr, 10





Try it online!

## Explanation

\n  # Push the newline character onto the stack (Ord code 10)

-hr # Print the item raw (i.e. as a number)


## Keg, 100

d.


Pushes d and prints as integer. Fortunately 100 is a letter in the Keg code page.

Output is 100.

Other solution just for fun and has a larger amplitude(also 2 bytes):

ā


Output is 257 TIO

# naz, 100,000,000 11,111

1a5o


Explanation

1a5o # Output "1" five times


I slightly misunderstood the question at first — here's my original 8-byte solution:

1a1o1s8o


# Burlesque, 1000 or 1111111

1e3
1cy7.+


Try it online!

First the boring method just printing 1000, or making an infinite number of 1s and clipping it to the length of the code+1.

# Python - 52^7, 12 bytes

print(52**7)


Edit 1: (Rip 11-ception)

After (embarrassingly) miscounting bytes, I'm back with the smaller version that turned out to be necessary. 52^7 is 1,028,071,702,528, which (at my count) is 13 bytes, and 13>12. Of course, if you could write things straight to STDOUT, you could get away with 5**6 or 15,625.

• Isn't it 13 bytes? – l4m2 Mar 22 at 11:41
• Oops - gotta go fix that. – StackMeter Mar 22 at 11:44

# Vyxal, 1 byte

₀


Try it Online!

literal 10.

• Score 0, 0 bytes – lyxal Jun 14 at 0:10
• @lyxal I asked in TNB, and apparently 0 isn't positive. – A username Jun 14 at 3:59

# Mumps, score 100000

W 1e5


Writes 10^5, or 100000. Had the newline not been optional, that would have added 2 more characters to the program:

W 1e7,!  ; this would output 10000000


Now that I mention it... it would be interesting to see how much would change on some of the winning answers if an explicit newline was required - especially the 0 or 1 byte answers. :-)

## MSM, 10101010

.;.;.01


7 byes for an 8 byte output. Repeatedly duplicates and concatenenates starting with 10.

# Visual Basic .NET, 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111 (86 ones)

Module A
Sub Main
System.Console.Write(New System.String("1"C,86))
End Sub
End Module


Oh dear. (This is shorter than using a loop, unless there's some fast way to do that that I don't know about.)

• You don't need to write System.. – Qwertiy Mar 16 '16 at 17:37

## k4, 10000

$cat a.k; echo _1e4$ wc -c a.k
4 a.k
$q a.k </dev/null 10000$


The input file is missing its trailing newline, but that doesn't matter to the interpreter. The language's default behavior on reading code files is to print the output of any statement which is not explicitly suppressed, so all I have to do is create the number. Exponential notation creates floats though, so I have to floor it to create an integer, otherwise the output would be 10000f (the default representation of a float that has no fractional part).

## dc, 117649

$cat a.dc; echo 7 6^p$ wc -c a.dc
5 a.dc
$dc -f a.dc 117649$


Inspired by WGroleau's comment on the question.

• Six to the power of something? Three bytes code. What happens with five instead of six? – WGroleau Dec 29 '15 at 5:01
• Never mind—I didn't see the seven space – WGroleau Dec 29 '15 at 5:07

# Insomnia, 129

i


Apart from i (105), r (115) or } (125) outputs the same result, since the position of the bit pointer doesn't matter when it's the last state-changing operation.

# Python 3, 1028071702528

print(52**7)


One byte longer than Python 2, but the same approach.

EDIT: turns out my search wasn't exhaustive enough -- thanks, Neil.

• 52**7 is only 1028071702528. – Neil Dec 29 '15 at 23:12

## Ceylon, 111111111111111111111111111111111111111111 (42 digits)

This was my second try:

shared void run(){print("1".repeat(42));}


A program with length 41, prints a string of 42 ones.

My first, more complicated try printed 112589990684262411529215046068469761152921504606846976 (54 digits):

shared void run(){print("2^502^602^60");}


This program has a length of 53 bytes.

Ceylon integers go just up to right under 2^63, which gives us only 19 digits. Due to the boilerplate here we need to concatenate three of them, which is done by the use of string templates (the contents of  ...  inside a string literal are evaluated as an expression and then converted into a string). Then it was simply a point of looking up the powers of two with (relatively) smallest first digits (2^50 starts with 1125, 2^60 with 1152), such that the length of them sums to 54. I guess combining other powers might make the program slightly shorter, but this still will not beat the simple one above.

# PHP, score 10,000,000,000

echo 1e10;


Assuming the opening/closing tags don't count, otherwise it's

<?=echo 1e13;


And if we allow non-PHP, we have <?=1e7 and 1e3 as options. Taking the first answer as the "most correct" of the four.

# Pylons, 10

B


How it works:

B # Push B to the stack. (pre-initialized to 10)
# The stack is implicitly printed at the end of the program.


# Oracle SQL 11.2, 30903154382632612361920641803529

SELECT''||POWER(9,33)FROM DUAL;


# Mathcad, 3 "bytes", 4 digits, 5040

Updated version. See text of Original version for suppression of decimal places discussion. As the original version, used one integer raised to power of another, I've also included what I think is the smallest number that meets the criterion.

Original (and wrong!) Version ...

Here's two Mathcad expressions (you may regard the "3" version as even more cheaty than the 8 version, hence my providing the two versions ...)

Mathcad doesn't have a "text" file as such. It operates more as a 2D whiteboard, where you can either type characters and operators onto a "worksheet", or enter them via a single-click toolbar. Mathcad stores the worksheet as an xml file. From a user perspective, however, typing "cat" counts as 3 distinct characters, which I'm taking to be the equivalent of "bytes" for the purposes of golfing; pi is single character as well. An operator, such as "=" (evaluate), "+" (add) or ":=" (define), also counts as a "byte".

There are also a number of settings, such as the number of decimal places shown displaying a real number, which are available from a dialog box. If, for example, setting the number of decimals to zero counts as a 0 "byte" operation, then π= is the shortest one I can think of. If this is regarded as cheating from a golfing perspective, then the exponent version should meet the spirit of the competition.

• Nice answer, but the goal of this challenge is to print an integer that has more digits than the program has bytes, e.g. print a 3-digit number with a 2 byte program. Could you please fix this? – ETHproductions Mar 16 '16 at 15:44
• Doh! yabinm (Yet Another Brain In Neutral Moment). – Stuart Bruff Mar 16 '16 at 17:13

## AWK, 1e21

I didn't see an AWK answer, so here's mine.

Since a 'full program' was requested, this is the best I could come up with (full program is a bit fuzzy in AWK).

awk '{$0=1e21}1'<<<1  If we don't consider how the program is called as part of the program, then the score could be dropped to about 1e13 using:  '{$0=1e13}1'


# Desmos, 6561

9^4


equals 6561

2^{20}


equals 1048576

# Forth, 1073741824 (2^30)

1 30 << .


Try it online

If the result could be left on the stack:

### 100663296

96 20 <<