# 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

## Brian & Chuck, 11,111,111,111,111 (≈ 1.1e13)

?1<SO>{?
#{>.>-?


Here, <SO> stands for the "shift out" control character with character code 0x0E.

Try it online.

That's all my language covered then. :)

### Explanation

The 1 in Brian's code (first line) is used for printing. Then <SO> is used as a counter variable. The rest is just a simple loop setup which prints that 1 while decrementing the <SO> down to zero.

## Mathematica, score 87,178,291,200

Print[14!]


This solution is not helped by the fact that it takes 6 characters to print anything.

• Why do you want to use Print though? Raw operations are valid programs in Mathematica (answer) – March Ho Dec 28 '15 at 22:22
• @MarchHo the fact that you got away with it in the past does not mean it's generally legitimate to assume a REPL environment. ;) – Martin Ender Dec 28 '15 at 23:01
• @MartinBüttner I don't get your point. It manifestly does not "take 6 characters to print anything" for this question in Mathematica. I don't see where REPL environments come into play here. – March Ho Dec 28 '15 at 23:10
• @MarchHo if you run 14! from a script file, it will not print anything. It only prints something when typed into a notebook, which is a REPL environment. – Martin Ender Dec 28 '15 at 23:11
• @MartinBüttner I was about to post in Meta, but someone beat me to it – March Ho Dec 29 '15 at 0:00

# Ruby, 1679616

p 6**8


Computes 68.

## QBasic, 15625

?5^6


? auto-magically gets converted to PRINT, 5 to the power of 6 yields the most convenient number of more than 4 bytes.

• QBasic automagically converts your code to PRINT 5 ^ 6 (which is 11 bytes) before it is run. I'm not counting the 2 bytes for the newline because that would be mean but strictly speaking even the empty QBasic program has two bytes... – CJ Dennis Dec 29 '15 at 9:44
• @CJDennis If I save this in a .BAS file and ask QBasic.exe to /run that, it runs. – steenbergh Dec 29 '15 at 12:01

# Marbelous, 100000000000000000000000 (24 digits)

Previously 28, 26 digits

@1
-- 10 '0
=0 @1
!! \\ /\ '1


All the spaces are superfluous. Outputs 1 then 0 repeatedly while counting down in parallel. Layout and counter tweaked to produce the desired amount of output for a 23-byte program.

# Java, 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 (~1082)

Curent version:

interface N{static void main(String[]a){for(int i=0;i<46;)System.out.print(++i);}}


Previous version [score floor(1084/9)=111111111111111111111111111111111111111111111111111111111111111111111111111111111111]:

interface N{static void main(String[]a){for(int i=0;i<84;i++)System.out.print(1);}}


Original version (score 1093):

interface N{static void main(String[]a){System.out.print(java.math.BigInteger.TEN.pow(93));}}


# TeaScript, 10 points

e


The e variable is preinitialized to 10

Try it online

• Isn't that confusing, given that e is another number? – Cyoce Dec 30 '15 at 8:37
• @Cyoce true but variable Me is e so both are usable – Downgoat Dec 31 '15 at 17:42

## Labyrinth, 1001101

>1!:
@


As Martin predicted, one order of magnitude lower is possible! Try it online!

I'm not going to go into full details as to how Labyrinth works, but this trace should give a rough idea as to what's going on anyway:

Inst   Detail                                    Stack            Output
---------------------------------------------------------------------------------
>      Rotate row 0 right                        []

[Board update]
:>1!
@

1      * 10 + 1                                  [1]
!      Output                                    []               1
1      * 10 + 1                                  [1]
>      Rotate row 1 right                        []

[Board update]
:>1!
@

:      Dup                                       [0 0]
>      Rotate row 0 right                        [0]

[Board update]
!:>1
@

1      * 10 + 1                                  [1]
>      Rotate row 1 right                        []

[Board update]
!:>1
@

:      Dup                                       [0 0]
!      Output                                    [0]              0
:      Dup                                       [0 0]
>      Rotate row 0 right                        [0]

[Board update]
1!:>
@

:      Dup                                       [0 0]
!      Output                                    [0]              0
1      * 10 + 1                                  [1]
!      Output                                    []               1
:      Dup                                       [0 0]
>      Rotate row 0 right                        [0]

[Board update]
>1!:
@

1      * 10 + 1                                  [1]
!      Output                                    []               1
:      Dup                                       [0 0]
!      Output                                    [0]              0
1      * 10 + 1                                  [1]
>      Rotate row 1 right                        []

[Board update]
>1!:
@

1      * 10 + 1                                  [1]
!      Output                                    []               1
:      Dup                                       [0 0]
@      Halt


# Come Here, floor(1042/9)

0CALL42cCOME FROM SGNcCALLc-1c1TELL49NEXT


Ungolfed:

0 NOTE It is illegal to "COME FROM" a nonexistant label.
CALL 42 c NOTE c=42
COME FROM SGN c NOTE If c>0, come back here after next reaching label 1
CALL c-1 c NOTE decrement c
1 TELL 49 NEXT NOTE I really don't understand why the parser requires NEXT here, but it does


# Jelly, score 120

5!


Calculates the factorial of 5. Try it online!

• It specifies that the text encoding should be UTF-8 - is that followed here? – Addison Crump Dec 28 '15 at 14:58
• I was going to say -- this might be the first esolang that actually can't trivially answer this question. – Arandur Dec 28 '15 at 14:59
• @FlagAsSpam I missed that unusual rule. It's fixed now. – Dennis Dec 28 '15 at 15:27

### Windows PowerShell, 1000

1e3


Another methods to achieve something similar, though not as small, may be

1KB   # 1024


# C, 327228837632722883924195568 (28 digits)

main(){printf("%u%u%u");}


Undefined behavior is awesome!!! This solution probably doesn't count due to UB, but I just wanted to put the idea out there.

Using Coliru, I get that output every time.

# Python 2, 1,000,000,000

Even lower than my other answer (but includes a trailing zero, which I did not count towards the score). Similar to the Matlab/Octave solution.

print 1e9

• 'Lowest integer' - the .0 at the end stops this from being valid. – Blue Dec 28 '15 at 23:47
• @muddyfish: The integers are members of the set of all real numbers. Representing an integer as a decimal string doesn't stop it from being an exact integer. I won't fully parse with a function that only parses C integral types (like strtol), but the question asked for an integer, not an int. – Peter Cordes Dec 29 '15 at 5:03
• I have to agree that although it does not look like an integer, it still satisfies all the mathematical properties of an integer. – Willem Dec 29 '15 at 8:42

# NTFJ, 111111111111111111111111111111 (30 ones)

Code:

#(#~~~#@::::::)$::::*****(~#^  ## Explanation One the first run through we push six 49s (ASCII value for one) to set up for the loop this only runs the first time because # is used to enter the loop. On all subsequent runs the # is skipped and thus the loop is skipped as well. After that as well as with all future runs we pop a value $ which for the first run is a 49 but for all subsequent runs is the zero used to skip the loop. We then duplicate the TOS four times and output five times decreasing the total by one. If the TOS is zero (i.e. not 49) we end the program otherwise we jump back to the first instruction immediately skipping to back to four duplications.

This outputs 30 ones and has a length of 29.

I thought since Conor O'Brien forgot about the : operator I'd do a solution without it to be fair to him.

#(##################~)~##~~~#@*~~##~~~~@*~~##~~~~@*$(~#^  This prints 100100100100100100100100100100100100100100100100100100100  I was going to make an explanation for this but I forgot how it works. • Wow, I like the alternative solution. Fantastic! – Conor O'Brien Oct 24 '16 at 11:17 # Microscript/Microscript II, 100 2E  # C++, 111111111111111111111111111111111111111111111111111111111111 (60 ones) #include<cstdio> int main(int c){while(c++<61)putchar(49);}  Translation of my C answer. • You could get 59 nines with int main(int c){while(c-->-putchar(57);)} for the second line. The same result could be get with a for instead and adding 2 ;. – Phil1970 Sep 15 at 1:05 • You should post that yourself, it's quite clever! – Lynn Sep 16 at 18:34 # GolfScript, 3125 5.?  Computes 55. # Excel & LibreOffice Calc – 10000 =1e4  Save as challenge.csv, then open in Excel or Calc. Usually just double-clicking will do. • "I.e. the code must be shorter than the number of digits in the resulting number" – nicael Dec 29 '15 at 22:17 • =1e4 would do for 10000. – Tom Carpenter Dec 30 '15 at 13:17 ## Java, 10^72 interface A{static void main(String[]a){System.out.printf("1%072d",0);}}  ## ><>, 10560 '*n  Try it online! '*n' Push chars to stack, giving [42 110 96] * Multiply, giving [42 10560] n Output 10560 as number  Unrecognised char, so the program outputs with an error  Unfortunately, out of all chars smaller than  which give a 5-digit output, none of [\]^_ work since they are valid instructions which don't cause the termination we require. # Haskell, 1001129150390625 main=print$75^8


Probably minimal. I can't think of a shorter way to make a large integer and print it than exponentiation (^); you need at least main=print\$. Of all choices for base and exponent, 75^8 was the lowest number longer than the code.

EDIT: Thanks, Neil!

• We still have no topic on meta that defines the minimum requirements for a full program. Maybe we can use the -e option of ghc and go with ghc -e "4^5" for a 3 byte program with a score of 1024. – nimi Dec 28 '15 at 19:58
• Actually 75^8 is only 1001129150390625. – Neil Jan 1 '16 at 22:11

# Befunge (quirkster implementation), 123648

"**.@


Pushes the string **.@ onto the stack, wraps around, exits string mode, and executes it, multiplying the ASCII values of the last three characters and outputting the result as an integer.

Edit: Only works if the playfield width is considered to be implicitly set to the maximum line width, not right-padded to a default size. Thanks to James Holderness for the catch.

# Vim, 11111

5i1␛


Works by inserting the character 1 five times. Try it online!

# gs2, 10

→


A single byte of CP437. Prints 10. Try it here!

• OP said UTF-8 (I disagree with the rules, but OP might not change them.) – lirtosiast Dec 29 '15 at 3:39
• This answer is invalid because this is 2 bytes in UTF-8, which is the encoding specified in the challenge. – Mego Apr 6 '16 at 18:57
• @Mego CP437 and UTF-8 are compatible in the first 128 bytes. This is just a dingbat that represents the actual control character. – Dennis Apr 6 '16 at 20:31
• Oh, whoops, I missed the fact that it was in the lower half. I should know better, considering how much I've worked with CP437 for Seriously... – Mego Apr 6 '16 at 20:38

# Mouse-2002, 10101010

k is 10, but ! printing costs a byte, so this is the only way.

kkkk(!)


Exits with an error, if run interactively.

# Befunge-93, 101010101010

6<_@#:-1.+4


I can't immediately think of anything shorter, but I think this is pretty good.

EDIT: got it from 161616161616 to 101010101010.

# Commodore Basic, 1000000

1?1E6


## Self-modifying Brainf***, 111,000,000,000,000 (1.11e14)

_ represents a null byte \x00. Prints each digit 3 times. I'm also fairly certain this is minimal. Interleaving digits with code is longer. There are several shorter solutions where the number is of equal length, but not longer.

<[...<]_00001


# PowerShell, 111111

"1"*6


If the newline counts, then "1"*5 prints 11111\n.

# AppleScript, 10^3

1e3

Implicit output? :o

## protected by Addison CrumpDec 29 '15 at 21:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).