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 2 3 4 5
6
0
\$\begingroup\$

S.I.L.O.S, 28 byte, 111111111111111111111111111111 (29 ones)

x=29
lbla
print 1
x-1
if x a

Ugh! Looping is expensive!

Try it online!

\$\endgroup\$
0
\$\begingroup\$

PHP, 100 ones, 23 chars

<?=str_repeat("1",1E2);
\$\endgroup\$
4
  • \$\begingroup\$ @MorganThrapp Thanks, fixed it. \$\endgroup\$
    – Sainan
    Feb 24, 2016 at 19:33
  • \$\begingroup\$ @MorganThrapp bytes.... ok, now. \$\endgroup\$
    – Sainan
    Feb 24, 2016 at 19:36
  • 1
    \$\begingroup\$ <?=str_repeat("1",23); works for score 11111111111111111111111. \$\endgroup\$ May 30, 2017 at 3:41
  • \$\begingroup\$ <?=str_repeat(1,21); 21 ones, 20 bytes - <?=str_pad(1,20,0); - a one plus 19 zeroes, 19 bytes \$\endgroup\$
    – Titus
    Apr 20, 2018 at 1:29
0
\$\begingroup\$

Röda, score 10,000,000,000,000 (1013)

main{[10^13]}

Try it online!

Röda statement, score 1,000,000 (106)

[10^6]

The program is executed using this command (the flags are required to execute the program, so they are free):

röda -e "[10^6]" -n
\$\endgroup\$
0
\$\begingroup\$

Prolog(SWI), 1e+15

?-write(1e15).

Outputs (surprise surprise) 1.0e+15

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Braingolf, 20

Oh hey look I can golf it now thanks to niladic stuff

+

Niladic + (ie run when the stack is empty) pushes 20 to the stack, implicit output.

Braingolf, 100

Just throwing in my 2 cents (or 2 bytes, as it were)

#d

Pushes the charcode of the character 'd' to the stack, which is 100. Braingolf will automatically print the last element of the stack when the code terminates if there is no semicolon present in the code.

Note:

As with every Braingolf submission thus-far on PPCG, this is non-competing, as the language was created on 3rd May 2017.

\$\endgroup\$
0
\$\begingroup\$

Underload, score 100000100000

(100000):*S
\$\endgroup\$
0
\$\begingroup\$

Implicit, score 65

A

Pushes the ASCII value for A (65). Implicit output.

\$\endgroup\$
0
\$\begingroup\$

Commodore 64/VIC 20 BASIC, 5 PETSCII characters (excluding the carriage return)

 0?1E5

Some caveats here; firstly, Commodore BASIC adds in a white space before printing any number or numeric variable; secondly, there is no concept of true integer types in Commodore BASIC (I think that applies to all variants through to BASIC 7 on the Commodore 128); and finally LISTing the program will show its un-obfuscate form, and add in a white space after each line number, so the above symbolic listing becomes:

0 PRINT1E5

So, on that basis, it could be that this is automatically disqualified if these caveats are taken into account. Does my initial golfed version count as a valid entry?

\$\endgroup\$
0
\$\begingroup\$

Momema, score 10000000001000000000

01000000000-8*0-8*0

Explanation:

0  1000000000  #  [0] = 1000000000
-8 *0          #  print num [0]
-8 *0          #  print num [0]
\$\endgroup\$
0
\$\begingroup\$

Canvas, 10

Try it here!

pushes 10 to the stack, then Canvas inplicitly prints the item at the top of the stack.

\$\endgroup\$
0
\$\begingroup\$

Yabasic/QBasic/VBA, 10000 4 bytes

Takes no input and outputs 10000to the console.

?1E4

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Java, 1e66

Shortest full program I could make:

interface A{static void main(String[]a){System.out.print(1e66);}}

With 65 bytes, this program outputs:

1e66

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pascal (FPC), 10^52 1111111111111111111111111111111111111111111111 (~1.1e46)

var i:word;begin for i:=1to 46do write(1)end.

Try it online!

Obvious one, I missed it somehow at first, thinking it would be bigger number.


Previous approach - 10^52 (10000000000000000000000000000000000000000000000000000)

uses sysutils;begin write(1,Format('%.52D',[0]))end.

Try it online!

Format is a function in sysutils which gives a string from specified formatting string and array of arguments. Formatting string works pretty much like in C: % starts the part which will be replaced, D means integer in decimal format, .52 for D means the number will be written with at least 52 digits; since 0 has less than 52 digits, it is left-padded with zeroes. 1 is written before it to make a valid integer.

\$\endgroup\$
0
\$\begingroup\$

Rust, 10²⁸ 10000000000000000000000000000 (28 bytes)

fn main(){print!("{}",1e28)}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Runic Enchantments, 1000

aC@

Try it online!

Huh, another classic I apparently never answered.

Because the number must be strictly longer than the program (so a 3 byte program requires a 4 digit number), this is as small as we can go (but there are two ways to do it).

\$\endgroup\$
0
\$\begingroup\$

Wren, 1e+24

Verbosity killed the wren. Calulates 10^24.

System.write(10.pow(24))

Try it online!

\$\endgroup\$
0
\$\begingroup\$

T-SQL, 100,000,000,000

SELECT 1e11

Note that the shorter PRINT 1e10 doesn't seem to work in this case; in the SQL versions I tested (2012 to 2017) it keeps the output in the exponential format (1e+010), which I assume isn't allowed.

\$\endgroup\$
0
\$\begingroup\$

W, 100

2^

Explanation

 ^ % 10 to the power of ...
2  % ... 2
\$\endgroup\$
0
\$\begingroup\$

Python 2, 137438953472 (2^37)

print 2**37

Code is 11 bytes long, output is 12 bytes long.

\$\endgroup\$
0
\$\begingroup\$

x86-16, IBM PC DOS, 111,111,111

B8 0A31     MOV  AX, 0A31H  ; AH = 0AH (write chars * CL), AL = '1' 
B1 09       MOV  CL, 9      ; display 9 times  
CD 10       INT  10H        ; call BIOS 
C3          RET             ; return to DOS

This is based on @krubo's answer above, but 3 bytes shorter. This uses the PC BIOS's INT 10,0AH function for output since it will repeat the same char CL number of times, saving the need for a LOOP (-2 bytes). Also, AL and AH can be initialized at the same time (-1 byte).

\$\endgroup\$
0
\$\begingroup\$

Fortran (GFortran), 24 ones

print*,("1",i=1,23)
end

Try it online!

Better Fortran score by avoiding formats entirely.

\$\endgroup\$
0
\$\begingroup\$

cQuents, 362880 161280 100100

#2;J4

Try it online!

J4 defults to base 2, and evaluates to 100 as a string. '100'+'100' = '100100'.

\$\endgroup\$
0
\$\begingroup\$

MAWP 1.0, 76543210

8[1A!:].

As suggested by Jo King.

Try it!

MAWP 1.0, 152587890625

5!W!W!W!W:.

Try it!

\$\endgroup\$
1
  • \$\begingroup\$ Wow, never thought of that. \$\endgroup\$
    – Razetime
    Aug 8, 2020 at 13:00
0
\$\begingroup\$

RGBDS macros, 11,111,111,111,111,111,111,111

REPT 23
 PRINTI 1
ENDR
\$\endgroup\$
0
\$\begingroup\$

BitCycle, 100000000100000000 100000000000000

A\10v
~000~!

Try it online!

This program is 12 bytes long and outputs a 15 byte number. It starts with 5 bits, discarding one and printing a copy of the bits each iteration.

BitCycle actually outputs in bits (ones and zeroes), which can be interpreted as a decimal number as above. It is normally interpreted in unary with the -u flag.

BitCycle -u, 60328467484514692442875165185

AB/00v  ~DDDDD@
~111 ~CD^
!

Try it online!

Honestly, not that much longer, but this takes a huge amount of time to execute. The code at 27 bytes, with the number at 29 digits long, which was the shortest of this format that I could find. Essentially, this repeatedly does the sum of 1 to n (as in the triangular numbers) on the same value, starting at 5, which increases exponentially. Then it outputs the sum of all these numbers

\$\endgroup\$
0
\$\begingroup\$

Rec, 111111111111

The space before 49 is required, otherwise the character will not display properly. Well, it seems like it's a Python formatting issue.

12[0:^\49p]

Try it online!

\$\endgroup\$
0
\$\begingroup\$

ForWhile, score 1111111

7[49#)

prints 1 7 times

online interpeter

ForWhile, score 76543210

8(47+#)

online interpreter

For loop printing decreasing characters for 8+47 (ascii '7') downwards to 1+47 (ascii `'0')

\$\endgroup\$
0
\$\begingroup\$

Kotlin, score 123456789101112131415161718192021222324

fun main()=(1..24).forEach{print(it)}

probably could be improved but not sure how

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 10000000

say 1e7

Try it online!

\$\endgroup\$
0
\$\begingroup\$

HP‑41C series, 1

This submissions presumes there are no other programs in program memory. We merely need to increase the number of displayed digits before placing the number on top of the stack. The default setting is to display and round to (up to) 4 places after the radix mark (FIX 4).

01♦LBL⸆T           5 Bytes    global label requires 4 + (length of string) Bytes
02 FIX 9           2 Bytes    display 9 digits after radix point
   NULL            1 Byte     invisible Null byte before numbers
02 1               1 Byte     push 1 on top of the stack (X ≔ 1)

shows, if flag 29 is set (the default),

 1.000000000

or, if flag 29 is cleared,

 1,000000000

If you want to print the number with an HP 82143A Printer, append a VIEW X command (2 Bytes) or shift the printer’s mode switch to the TRACE position (which will, however, print all the other commands, too).

\$\endgroup\$
1 2 3 4 5
6

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.