95
\$\begingroup\$

The Challenge

Write a complete program that writes twice as many bytes to standard output as the length of the program.

Rules

  • The program must write ASCII characters to the standard output.

  • The contents of the output doesn't matter.

  • The output, measured in bytes, must be exactly twice the length of the program, also measured in bytes, unless you fulfill the bonus.

  • Any trailing newline is included in the output's byte count.

Bonus

Your program can optionally take a number, n, as input. If so, the output must be exactly n * program length bytes. You can assume that n will always be a positive integer. If no input is provided, n must default to 2.

If you do this, you can subtract 25 bytes from your score.

Shortest program wins.

Restrictions

  • No standard loopholes.

  • The program must be at least 1 byte long.

  • No adding unnecessary whitespace to the source code to change its length. Similarly, comments don't count.

  • Unless you fulfill the bonus, the program must accept no input. If you do fulfill the bonus, the integer must be the only input.

Lowest score (program length in bytes - bonus) wins.

The shortest answer for each language wins for that language.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=59436,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\-?\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <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><div id="language-list"> <h2>Winners 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><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\$
23
  • 1
    \$\begingroup\$ For the bonus, does the output have to be exactly n * program length bytes, or is that a minimum? \$\endgroup\$ – xnor Oct 2 '15 at 23:19
  • 2
    \$\begingroup\$ It has to be exact \$\endgroup\$ – Daniel M. Oct 2 '15 at 23:20
  • 3
    \$\begingroup\$ Looks like the code snippet has to be modified to handle negative scores. \$\endgroup\$ – El'endia Starman Oct 2 '15 at 23:49
  • 43
    \$\begingroup\$ A bonus of -25 is basically mandatory for some languages, since it lets them achieve a negative score. In the future, I'd suggest using a percent bonus, or just making the bonus the question if you really want answers to go for it. Or, just don't have a bonus. \$\endgroup\$ – xnor Oct 2 '15 at 23:58
  • 4
    \$\begingroup\$ For "no input is provided", do we assume the empty string is passed in? I can't see how one would deal with the user never typing in an input and the program just waiting. \$\endgroup\$ – xnor Oct 2 '15 at 23:59

278 Answers 278

1 2 3
4
5
10
2
\$\begingroup\$

Boolfuck, 21 bytes

+[[>+>+[<;;;]<]>+>>]>

This program outputs 330 bits (41.25 bytes) which get buffered to 42 bytes. I found it by systematically (but not quite exhaustively) searching through several million possible candidates.

Here is a hexdump of the output:

00000000: fc0f ffe3 ffc7 ffff ff1f fe3f ffff f8ff  ...........?....
00000010: ffff ffff c0ff fe3f ffff ff1f ffff ffff  .......?........
00000020: ff1f ffff ffff ffff fe00                 ..........

Try it online!

I also recommend taking a look at this in fatiherikli's Brainfuck visulizer (optimized and with minimal delay of course).

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

Guile (5)

"oof" outputs $1 = "oof"

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Hello, welcome to PPCG! \$\endgroup\$ – James Apr 9 '19 at 17:28
2
\$\begingroup\$

Bash, 10 bytes

yes|head -

outputs 10 lines of ys for 20 total bytes output.

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

MathGolf, 2 bytes

7!

Outputs 5040, which is 4 bytes.

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Congratulations on your first MathGolf answer! There are also quite a few 1-byte answers, as the bytes A to Z hold values between 11 and 38. Other approaches are Hf (19th fibonacci number) or (push 7 and quadruplicate to 7777). \$\endgroup\$ – maxb Aug 6 '19 at 5:26
2
\$\begingroup\$

MathGolf, 5 - 25 = -20 bytes

╜2╩[*

Try it online!

Explanation

╜2      If not implicit input, push 2
  ╩[    Push dictionary word "great"
    *   Repeat string

To make it work, I just had to find a word within the top 256 lines of the dictionary which had the same length as the code.

Almost working 3-byter with 25 byte bonus

╜2r

Try it online!

Basically the same as Stan Strum's Pyth answer. If (implicit) input is equal to 0, push 2. Then create a range using either the 2, or the implicit input. The length of the output is the length of the string representation of the array, which is 3 times the length of the array. This only works for input \$\leq 10\$.

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

Triangular, 10 8 7 bytes

tdC%.`y

Try it online!

Prints odd numbers from 11 to 1 descending, twice each.

Triangular executes as if written in the shape of a triangle. For example, if your program was 123456, the triangle representing your program would be drawn like this:

  1
 2 3
4 5 6

The program executes starting from 1, and has a Southeast direction (I.e., the above would run as 1, 3, 6). This explanation is for its actual execution order, which is why it doesn't visually look the same as the submission.

Ungolfed/Directional

   t
  d C
 % . `
y

-------------------------------------------------------------------

t             - If ToS != 0, set direction to SouthEast
 C            - Push 12
  `           - Set direction to NorthWest (This means we hit "t" with ToS > 0)
   d          - Decrement the top value of the stack
    %y        - Print the top value of the stack, then change direction to NorthEast if ToS != 0

Previous Version (8 bytes):

Dn,%d./<
\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog Classic), 5 bytes

⎕←1e9

Try it online!

Explanation

Not very interesting... but I hope this hasn't been posted before.

   1e9 ⍝ This returns the constant 1000000000
⎕←    ⍝ Move this to the output buffer
\$\endgroup\$
2
\$\begingroup\$

W, -22 bytes

The program is 3 bytes long and qualifies for the -25 byte bonus. (Okay. One-digit problem fixed!)

 0M

Explanation

   % Filler space
 M % Map: (implicitly) generate a list from 1 to the input
   % There is an implicit 0, so the 0-input
   % will produce the output [0, 1], which is
   % 6 bytes by default.
 M % Map every item in that list ...
0  % .. with the numeric constant 0
\$\endgroup\$
2
\$\begingroup\$

Flurry, 28 bytes, no bonus

({<(({})){}{}>})({}){({})}{}

Verification

$ echo -n "({<(({})){}{}>})({}){({})}{}" | wc -c
28
$ ./flurry -iin -c "({<(({})){}{}>})({}){({})}{}"
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3
$ ./flurry -iin -c "({<(({})){}{}>})({}){({})}{}"  | wc -c
56

Uses 3 ** 3 = 27, and enables both stack output and return value output so that 3 is printed 27 + 1 times.

(
 {<(({})){}{}>}  Literal 3
)              Push and return 3
({})           Pop, push and return 3; 3 3 -> 27
{({})}         Push&return function
{}             Pop 3; 27 push&return 3 -> push 27 copies of 3 and return 3

Flurry, 32 bytes, no bonus

<(({<({}){}>})({})){}{}>{({})}{}

Verification

$ echo -n "<(({<({}){}>})({})){}{}>{({})}{}" | wc -c
32
$ ./flurry -inn -c "<(({<({}){}>})({})){}{}>{({})}{}"
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
$ ./flurry -inn -c "<(({<({}){}>})({})){}{}>{({})}{}" | wc -c
64

How it works

In order to increase the output size, it is easiest to push numbers to stack and print them in integer mode. Basically the program follows the structure of n push&return m, where n is the repeat count, push&return is a function that, given an argument, pushes it and returns it unchanged, and m is the number to push. Then the stack contains n copies of m at the end, giving the output size of (length of m + 1) * n.

The second part of the challenge is to generate high enough numbers. Flurry uses Church numerals to represent natural numbers, so multiplication (<abc...> evaluates to a * b * c * ...) and exponentiation (ab evaluates to b**a) is much golfier than number literals (except 1), successor <><<>()>, and addition (which is defined via successor). So I tried various powers and products until I got the solution, where 32 is 4 * 4 * 2.

<
 (
  ({<({}){}>})  Push and return 2
  ({})          Pop 2, push back and return 2
 )            Push and return 2 ** 2 = 4
 {}{}         Pop 4 and Pop 2
>           Product; return 4 * 4 * 2 = 32
{({})}      Function: push&return
{}          Pop from empty stack, which gives I = 1
32 push&return 1 -> Push 1 to stack 32 times and return 1
\$\endgroup\$
2
\$\begingroup\$

Factor, 7 bytes

42 2^ .

Try it online!

2^42 is a 13-digit number. . outputs this number plus a newline.

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

><>, 29 + 2 (-v flag) - 25 = 6

l0=?21-:0(?;fe+1-ao:0=f*e+0.~

Takes input on the stack, which I believe is populated through -v on the official interpreter. Prints newlines only.

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

Microscript, 1

0

Prints the digit 0, followed by a newline.

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

q (bonus), 27 bytes

1#[;"x"]27*2^first"J"$.z.x;
\$\endgroup\$
1
\$\begingroup\$

C#, 104 bytes (79 point with bonus)

class a{static void Main(string[] p){System.Console.Write(new System.String('1',104*int.Parse(p[0])));}}

you can run the program by using an argument for example test.exe 2 prints 208 character '1'

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think there's one rule missing: If no input is provided, n must default to 2 \$\endgroup\$ – Thomas Weller Oct 7 '15 at 20:30
1
\$\begingroup\$

awk, 29 - 25 = 4 bytes

{printf"%0"($0?$0:2)*29"d",0}

Prints the wanted number of zeros.

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

Befunge-98, 26-25=1

&:#v_v>1.1-v
*d2<2<^_@#:<*

Run it in this interpreter. Apparently, it can't take input.

Befunge-93, 30 - 25 = 5 27-25=2

&:#v_v>1.1-v 
*93<2<^_@#:<*

There is a trailing space on the first line, and this is done because it's shorter to make 27 than it is to make 26 with Befunge-93. This outputs 27*n 1s in a row.

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

Perl, 10 9 bytes

Uses @primo's suggestion of $=.

print$=x9

$= is a shortcut for $FORMAT_LINES_PER_PAGE, which defaults to 60.

Example:

$ cat doubler.pl
print$=x9
$ perl doubler.pl
606060606060606060
\$\endgroup\$
2
  • 1
    \$\begingroup\$ print$=x9 for one byte. \$\endgroup\$ – primo Oct 3 '15 at 8:35
  • 1
    \$\begingroup\$ I think print$~x3 also works for the same score. On my system, it outputs STDOUTSTDOUTSTDOUT. \$\endgroup\$ – PhiNotPi Oct 3 '15 at 19:55
1
\$\begingroup\$

Stuck, -13 Bytes

i_0>;2?12*N*

This prints a bunch of newlines (N). Empty input is considered to be 0 (or anything less than 0). So, if 4 was given, it will print 48 newlines.

Old Answer - 3 Bytes

6Rj

will output

123456

Will be giving the bonus a shot.

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

C, 25

main(){printf("%*p",50);}

This makes use of UB, but it should work. At least it works with gcc 5.2.0

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

MSM, 12 bytes

'...;.;.;...

Outputs ........................

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

R, 3 bytes

10;

will print

[1] 10
\$\endgroup\$
1
\$\begingroup\$

QBasic, 2 bytes

?1

Nonnegative numbers in QBasic are output with both a leading and a trailing space. The PRINT command (for which ? is a shortcut) outputs a newline by default. Thus, I count 4 bytes of output: space 1 space newline.

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

Julia, 9

warn(⊆)

prints

"WARNING: issubset\n"
\$\endgroup\$
1
  • \$\begingroup\$ Might want to format your header differently so your score doesn't look like -8 instead of 9 \$\endgroup\$ – Patrick Roberts Oct 5 '15 at 4:05
1
\$\begingroup\$

Insomnia, 1

7

Output:

00

8, A, B are 3 other programs that satisfy the requirement. Their output contains NUL characters, though.

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

MUMPS, 4 bytes

w ?8

Well, I'm not sure if this really counts. What this program does is advance the output cursor 8 characters to the right. On every terminal I've used, this is indistinguishable from outputting 8 spaces, but is it really the same thing? I dunno.

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

C, 82 bytes (with bonus)

main(int a,char**b){b&&b[1]&&(a=atoi(b[1])-1);a&&main(a-1,0),printf("%.80f",.0);}

Usage:

$ wc main.c
       1       2      82
$ ./a.out | wc
       0       1     164
$ ./a.out 4 | wc
       0       1     138
$ ./a.out 133475 | wc
       0       1 10944950
\$\endgroup\$
2
  • \$\begingroup\$ I think you can shave some off by modifying b as you go: b&&*++b&&(a=atoi(*b)-1) \$\endgroup\$ – Toby Speight Oct 6 '15 at 10:31
  • \$\begingroup\$ Yes comrade! It does work. \$\endgroup\$ – wefwefa3 Oct 6 '15 at 17:43
1
\$\begingroup\$

DOS, 7 bytes

date /t

outputs di 06-10-2015 (and a newline) on my system, but I'll admit it's locale dependent. So my second best is:

echo %PATH:~0,33%

which outputs C:\WINDOWS\system32;C:\WINDOWS;C: (and a newline).

\$\endgroup\$
5
  • \$\begingroup\$ With my system settings it prints 2015.10.07\n \$\endgroup\$ – SuperJedi224 Oct 7 '15 at 10:12
  • \$\begingroup\$ Got 6.2 bytes using "type %0". \$\endgroup\$ – Star OS Dec 16 '15 at 12:03
  • \$\begingroup\$ @StarOS That gives me The system cannot find the specified file (roughly translated) \$\endgroup\$ – Berend Dec 17 '15 at 7:45
  • \$\begingroup\$ Berend, it only works in a Batch file. +1 beacuse all of the other things don't use a shell, it uses a file \$\endgroup\$ – Star OS Dec 17 '15 at 11:25
  • \$\begingroup\$ @Berend Note, you are using Windows Batch, not DOS Batch. The string manipulation function is added in Windows, not DOS. \$\endgroup\$ – stevefestl Sep 22 '17 at 23:52
1
\$\begingroup\$

Bash + GNU coreutils, -1 byte

printf %24s `seq ${1-2}`

Score is 24-25

A non-bonus version for +5:

seq 5

which produces 1 nl 2 nl 3 nl 4 nl 5 nl.

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

Bash + GNU coreutils, 26 24 - 25 = 1 -1 byte

The x file:

yes|head -c$[24*${1:-2}]

(no trailing newline)

Running:

$ bash x 1 | wc -c
24
$ bash x | wc -c
48
$ bash x 3 | wc -c
72

Old version with 26 bytes:

The x file:

yes|head -c$((26*${1:-2}))

(no trailing newline)

\$\endgroup\$
1
  • \$\begingroup\$ @Unihedron I don't see how this violates that rule. \$\endgroup\$ – Doorknob Oct 4 '15 at 14:30
1
\$\begingroup\$

POSIX bc, 4 bytes

10^7

This creates the output 10000000.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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