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

180 Answers 180

1
\$\begingroup\$

Binary-Encoded Golfical, floor(1014/9)

Hexdump of binary encoding:

00 90 01 00 31 18 18 18 18 18 18 18 1D

Original image:

enter image description here

Magnified 80x, with color labels:

enter image description here

Explanation: Stores 49 (the code point of the digit 1), prints it as a character 7 times, then turns around and prints it seven more times before terminating.

\$\endgroup\$
1
\$\begingroup\$

Cy, score 134217728

8 9 ^ :<

8 9 pushes a 9 and an 8 to the stack (duh), ^ computes 8 ^ 9 (exponent, not xor), :< prints it.

This was not intended to be a golfing language, but this answer ended up pretty short compared to "real" languages. I didn't even need exponential notation!

\$\endgroup\$
1
\$\begingroup\$

beeswax, 909090 823543

The new solution just computes 7^7, which is 85547 smaller than the old solution.

_7FB{

Explanation:

_       [0,0,0]•       create bee
 7      [0,0,7]•       push 7 on lstack
  F     [7,7,7]•       set all stack values to 1st value
   B    [7,7,823573]•  1st=1st^2nd
    {                  output lstack 1st to STDOUT
\$\endgroup\$
1
\$\begingroup\$

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

Reng v.3.3, score 104976

Try it here!

I²²n~

Prints

104976

This squares I (18) twice, yielding 104976. n prints this, and ~ terminates.

Reng v.2.2, score 101010101010

{An}``````~

Previously, score 96549157373046880

Z{ZZ**}#xxxxxxn~

Prints 96549157373046880.

\$\endgroup\$
1
1
\$\begingroup\$

Jelly, score 100

³

Prints 100 when counting as 2 bytes in UTF-8.

Try it Online!

\$\endgroup\$
1
\$\begingroup\$

Carrot, 11111

1^*4

1     //"1" is pushed into the stack
 ^    //The stack is finished
  *   //Multiply or duplicate string operator (in this case it is the latter)
   4  //Duplicate the string 5 times (4+1)

"1" is pushed into the stack. Then the * operator duplicates the string 5 times, not 4 times because the * operator on strings always duplicates the strings 1 time more than what is stated, because duplicating it once is meaningless and hence it is removed. So the program outputs 11111.

\$\endgroup\$
1
\$\begingroup\$

7, 16031, language postdates challenge

1603

Try it online!

It's unclear what "must be encoded in ASCII or UTF-8" means in 7. The most obvious meaning is that I have to write each command as a single character, and encode its name in ASCII (this is particularly suitable here, because that's an input encoding that the 7 interpreter understands). In this case, the best I can do is 16031 (the first character here is a literal that's never executed, thus could be any octal digit; 0603 outputs 06031, but leading zeroes are disallowed, so the best digit we can use here is 1).

Explanation

A 7 program is basically a sequence of literals that are pushed to the stack, unescaping them in the process; thus the "initial run" of the program is always fairly boring and just puts things on the stack. Then the rightmost stack element is executed (while leaving it on the stack), repeatedly until the program exits.

Although all the commands that can occur in literals have names, some of the commands that can appear as the result of unescaping don't. The usual convention I use for this on PPCG is to bold "active" commands (which do something interesting when executed), and leave "passive" commands (which just push an active command) unboldened. The four active commands that don't have names are then given the same name as the corresponding passive command, and thus I rely on the font to distinguish. 7's "stack" is a little strange, relying on separators | between elements (which are manipulated as though they were a character in the language).

||           1603    Initial stack and program; 6 is active, 103 are passive
|103                 Result after the program's initial run
|103         103     (implicit) Top stack element is copied to the program
|1031        03      1 appends 1 to the stack
716031       3       0 escapes the top stack element and removes the | before it
                     3 prints output, and exits if the stack is low

The output in this case is 716031. The first step in producing output is to check to see if it needs escaping (the algorithm for this is fairly complex, but typically boils down to making active commands passive, and enclosing passive sections in 76). In most of my 7 programs, it does (due to containing anonymous commands), but all the commands seen there have names (unsurprisingly, because we escaped it manually on the previous line), so no escaping is necessary. Next, the first character output in the entire program (here, 7) specifies the output format (7 means "the same as the input", so the output will be printed as a sequence of octal digits in ASCII). Finally, the remaining characters, 16031, will be printed directly (shown here without the bold because one they're printed, they aren't commands any more, just characters).

Interestingly, the victory condition is different from a , and that actually mattered. It's possible to write a smaller program that produces numerical output longer than itself: 163 outputs 71631 (basically because it doesn't escape explicitly, and implicit escaping by the 3 command always prepends a 7 to the output). However, in this case, although the program is shorter, the output is larger, so using a longer program gave a smaller score.

\$\endgroup\$
1
\$\begingroup\$

Common Lisp (GCL), 1586013445029888

(princ(exp 35))
\$\endgroup\$
1
\$\begingroup\$

Brachylog (2), 11111, language postdates challenge

1j₅w

Try it online!

Just makes five copies of 1 and prints them.

\$\endgroup\$
1
\$\begingroup\$

PHP, 9223372036854775807

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

9223372036854775807

<?=PHP_INT_MAX;

10000000000000000000

<?=str_pad(1,20,0);
\$\endgroup\$
1
\$\begingroup\$

Python 3, 100000000000

One digit shorter than the current python 3

print(1e11)

prints 1*(10^11)

\$\endgroup\$
1
\$\begingroup\$

Pyke, 1 byte

T

Try it here!

In Pyke, as well as in Pyth, T is a constant pre-initialised to 10.

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Perl 6, 10000000

1e7.say

Try it online!

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

\$\endgroup\$
1
\$\begingroup\$

Attache, 8 bytes

8^9|Echo

Try it online!

Outputs 134217728.

\$\endgroup\$
1
\$\begingroup\$

ForceLang, 1013

io.write 1e13
\$\endgroup\$
1
\$\begingroup\$

Shakespeare Programming Language, ~1.23e186

Prints 1234…95969798, the concatenation of all integers from 1 to 98.

,.Ajax,.Page,.Act I:.Scene I:.[Exeunt][Enter Ajax and Page]Page:You is the sum ofyou a cat.Open heart.Is you worse twice the square ofthe sum ofa big big big cat a pig?If soLet usAct I.

Try it online!

After many iterations, here is a version without any spare characters. The code is 186 characters, and the output is 187 characters.

\$\endgroup\$
1
1
\$\begingroup\$

Intcode, 100000000000000000000000000000000

2,7,7,7,4,7,99,10000000000000000

This is almost certainly sub-optimal, given all it does is square the number given at the end.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ @FlipTack Thank you. Remember to also remind this answer. \$\endgroup\$
    – user85052
    Dec 14, 2019 at 9:42
  • \$\begingroup\$ 10, using -hd and a newline \$\endgroup\$
    – lyxal
    Dec 24, 2019 at 4:32
1
\$\begingroup\$

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

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Isn't it 13 bytes? \$\endgroup\$
    – l4m2
    Mar 22, 2021 at 11:41
  • \$\begingroup\$ Oops - gotta go fix that. \$\endgroup\$ Mar 22, 2021 at 11:44
1
\$\begingroup\$

Pxem, 1000010000.

  • Filename: 10000.e.p (9 bytes)
  • Content: empty (0 bytes)
    • Total: 9 bytes

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Check, score 1000010000

>10000pp
\$\endgroup\$
1
\$\begingroup\$

Bitcoin Cash Script (BitAuth IDE), 18 bytes

// Golfed
0x0340420f76769595
// The number 1000000000000000000 will be on top of stack

// Ungolfed
OP_DROP // clean up
<1000000> OP_DUP OP_DUP OP_MUL OP_MUL
// The number 1000000000000000000 will be on top of stack

Opcodes reference

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Knight (v2), score 117649

O^7 6

Outputs \${7}^{6}=117649\$

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Go, 111111111111111111111111111111111111111111111111111111, 53 bytes

package main
func main(){for i:=1;i<55;i++{print(1)}}

Attempt This Online!

Prints to STDERR.

\$\endgroup\$
1
\$\begingroup\$

GolfScript, 1010

10.

Try it online!

Same length as Lynn's but gives a smaller number by pushing two copies of 10 and (implicitly) printing them side-by-side.

Some fun alternatives include n). and n(., which extract the charcode of newline from the string "\n" to get 10 (leaving an empty string at the bottom)

\$\endgroup\$

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.