177
\$\begingroup\$

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.

Leaderboard snippet

var QUESTION_ID = 67921;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; }
function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; }
function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); }
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*)(?:,|[-\u2013] ).*?([\d,^!e+]+)(?=\:?[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
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>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> 
<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>

\$\endgroup\$
  • 63
    \$\begingroup\$ Number 1 on the Hot Network Questions. Not bad for a first question... \$\endgroup\$ – trichoplax Dec 28 '15 at 15:15
  • 6
    \$\begingroup\$ @Kslkgh Strictly less than, otherwise the question is trivial for programs which implicitly print their last value. \$\endgroup\$ – Arandur Dec 28 '15 at 15:57
  • 6
    \$\begingroup\$ Is 1.0 an integer? \$\endgroup\$ – histocrat Dec 28 '15 at 20:05
  • 22
    \$\begingroup\$ 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). \$\endgroup\$ – lirtosiast Dec 29 '15 at 3:35
  • 7
    \$\begingroup\$ @ZachGates that's not how the HNQ list works. ;) \$\endgroup\$ – Martin Ender Dec 29 '15 at 8:38

138 Answers 138

5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

Mathematica, score 87,178,291,200

Print[14!]

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

\$\endgroup\$
  • \$\begingroup\$ Why do you want to use Print though? Raw operations are valid programs in Mathematica (answer) \$\endgroup\$ – March Ho Dec 28 '15 at 22:22
  • 3
    \$\begingroup\$ @MarchHo the fact that you got away with it in the past does not mean it's generally legitimate to assume a REPL environment. ;) \$\endgroup\$ – Martin Ender Dec 28 '15 at 23:01
  • \$\begingroup\$ @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. \$\endgroup\$ – March Ho Dec 28 '15 at 23:10
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Martin Ender Dec 28 '15 at 23:11
  • 1
    \$\begingroup\$ @MartinBüttner I was about to post in Meta, but someone beat me to it \$\endgroup\$ – March Ho Dec 29 '15 at 0:00
5
\$\begingroup\$

Ruby, 1679616

p 6**8

Computes 68.

\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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... \$\endgroup\$ – CJ Dennis Dec 29 '15 at 9:44
  • 1
    \$\begingroup\$ @CJDennis If I save this in a .BAS file and ask QBasic.exe to /run that, it runs. \$\endgroup\$ – steenbergh Dec 29 '15 at 12:01
5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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));}}
\$\endgroup\$
5
\$\begingroup\$

TeaScript, 10 points

e

The e variable is preinitialized to 10

Try it online

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

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
\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
4
\$\begingroup\$

Jelly, score 120

5!

Calculates the factorial of 5. Try it online!

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

Windows PowerShell, 1000

1e3

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

1KB   # 1024
\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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
\$\endgroup\$
  • 1
    \$\begingroup\$ 'Lowest integer' - the .0 at the end stops this from being valid. \$\endgroup\$ – Blue Dec 28 '15 at 23:47
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Peter Cordes Dec 29 '15 at 5:03
  • 1
    \$\begingroup\$ I have to agree that although it does not look like an integer, it still satisfies all the mathematical properties of an integer. \$\endgroup\$ – Willem Dec 29 '15 at 8:42
4
+150
\$\begingroup\$

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.

Additional solution

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.

\$\endgroup\$
  • \$\begingroup\$ Wow, I like the alternative solution. Fantastic! \$\endgroup\$ – Conor O'Brien Oct 24 '16 at 11:17
3
\$\begingroup\$

Microscript/Microscript II, 100

2E
\$\endgroup\$
3
\$\begingroup\$

GolfScript, 3125

5.?

Computes 55.

\$\endgroup\$
3
\$\begingroup\$

Excel & LibreOffice Calc – 10000

=1e4

Save as challenge.csv, then open in Excel or Calc. Usually just double-clicking will do.

\$\endgroup\$
  • \$\begingroup\$ "I.e. the code must be shorter than the number of digits in the resulting number" \$\endgroup\$ – nicael Dec 29 '15 at 22:17
  • \$\begingroup\$ =1e4 would do for 10000. \$\endgroup\$ – Tom Carpenter Dec 30 '15 at 13:17
3
\$\begingroup\$

Java, 10^72

interface A{static void main(String[]a){System.out.printf("1%072d",0);}}
\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – nimi Dec 28 '15 at 19:58
  • \$\begingroup\$ Actually 75^8 is only 1001129150390625. \$\endgroup\$ – Neil Jan 1 '16 at 22:11
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

Vim, 11111

5i1␛

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

\$\endgroup\$
2
\$\begingroup\$

gs2, 10

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

\$\endgroup\$
  • 3
    \$\begingroup\$ OP said UTF-8 (I disagree with the rules, but OP might not change them.) \$\endgroup\$ – lirtosiast Dec 29 '15 at 3:39
  • \$\begingroup\$ This answer is invalid because this is 2 bytes in UTF-8, which is the encoding specified in the challenge. \$\endgroup\$ – Mego Apr 6 '16 at 18:57
  • \$\begingroup\$ @Mego CP437 and UTF-8 are compatible in the first 128 bytes. This is just a dingbat that represents the actual control character. \$\endgroup\$ – Dennis Apr 6 '16 at 20:31
  • \$\begingroup\$ 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... \$\endgroup\$ – Mego Apr 6 '16 at 20:38
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

C++, 111111111111111111111111111111111111111111111111111111111111 (60 ones)

#include<cstdio>
int main(int c){while(c++<61)putchar(49);}

Translation of my C answer.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Commodore Basic, 1000000

1?1E6
\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

PowerShell, 111111

"1"*6

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

\$\endgroup\$
2
\$\begingroup\$

AppleScript, 10^3

1e3

Implicit output? :o

\$\endgroup\$

protected by Addison Crump Dec 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).

Would you like to answer one of these unanswered questions instead?

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