103
\$\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\$
25
  • 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, 2015 at 23:19
  • 2
    \$\begingroup\$ It has to be exact \$\endgroup\$
    – Daniel M.
    Oct 2, 2015 at 23:20
  • 3
    \$\begingroup\$ Looks like the code snippet has to be modified to handle negative scores. \$\endgroup\$ Oct 2, 2015 at 23:49
  • 44
    \$\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, 2015 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, 2015 at 23:59

300 Answers 300

1
6 7 8 9
10
0
\$\begingroup\$

Python3 Shell version

'2'*10

outputs:'2222222222'

\$\endgroup\$
1
  • 4
    \$\begingroup\$ I think the language name you're looking for is Python 3 REPL. Also, your output is only 10 bytes long while the program is 6 bytes \$\endgroup\$
    – Jo King
    Dec 9, 2018 at 1:26
0
\$\begingroup\$

Ahead, 4 bytes

8kO@

Prints 00000000.

8k    8 times...
  O   ..pop and print number
   @  end

Try it online!

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

Ahead, 6 - 25 = -19 bytes

Here it is with the bonus.

I6*kO@

I       Read number from stdin
 6*      multiply by 6
   k    I*6 times...
    O   ...pop and print number
     @  end

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ This doesn't print 2*bytes for no input \$\endgroup\$
    – Jo King
    Dec 9, 2018 at 9:36
0
\$\begingroup\$

Java, 234 - 25 = 209 bytes

import java.io.*;interface A{static void main(String a[])throws Exception{InputStream i=new FileInputStream("A.java");byte[]b=new byte[1];for(int l;(l=i.read(b))!=-1;)for(int n=0;n<Integer.parseInt(a[0]);n++)System.out.write(b,0,l);}}

Formatted :

import java.io.*;
interface A {
    static void main(String a[]) throws Exception {
        InputStream i = new FileInputStream("A.java");
        byte[] b = new byte[1];
        for (int l; (l = i.read(b)) != -1; )
            for (int n = 0; n < Integer.parseInt(a[0]); n++)
                System.out.write(b, 0, l);
    }
}
\$\endgroup\$
4
  • \$\begingroup\$ Is it really worth it to have all the input stuff for a mere -25 bytes? \$\endgroup\$
    – Jo King
    Dec 9, 2018 at 9:01
  • \$\begingroup\$ @JoKing No, not really. There are shorter answers, but this shows a different point of view. Also, this has no hard-coded program length. \$\endgroup\$
    – Amir M
    Dec 9, 2018 at 9:15
  • \$\begingroup\$ @AmirM Isn't reading the source code a standard loophole? \$\endgroup\$
    – Maya
    Dec 9, 2018 at 9:34
  • \$\begingroup\$ @NieDzejkob This isn't a quine question \$\endgroup\$
    – Jo King
    Dec 9, 2018 at 9:38
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 58 bytes - 25 = 33

	N =INPUT
O	OUTPUT =1
	X =LT(X,N * 29 - 1) X + 1	:S(O)
END

Try it online!

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

MIPS, 58 bytes

main:li $v0,1
li $a0,63
l:sub $a0,$a0,1
syscall
bnez $a0,l

Try it online!

A counter loop that prints the count on each pass without spaces or a trailing newline.

\$\endgroup\$
1
  • \$\begingroup\$ 50 \$\endgroup\$
    – ASCII-only
    Mar 13, 2019 at 4:31
0
\$\begingroup\$

C# (Visual C# Interactive Compiler), 17 16 bytes

Write($"{0,32}")

Thanks to Jo King for saving one byte!

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ @JoKing Thanks, I keep forgetting that the interactive compiler doesn't need semicolons at the last statement \$\endgroup\$
    – Gymhgy
    Mar 6, 2019 at 15:49
0
\$\begingroup\$

Perl 6 (8 bytes)

say 1e14

Perl 6 (with challenge, 27 bytes - 25 = 2)

print "a"x(@*ARGS[0]//2)*27
\$\endgroup\$
0
\$\begingroup\$

Tamsin, 40 bytes

main='aaaaaaaaaaaaaaaa'->T&''+T+T+T+T+T.

Try it online!

Outputs 80 of the character a.

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

Java, 86 bytes

Prints 172 (86*2 = 172) null bytes to STDOUT

interface A{static void main(String[]a){System.out.print(new String(new char[172]));}}

Try it online!

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

ink, 1 byte

s

Try it online!

Outputs s and a newline for a total of two characters.

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

Brainfuck, -5 bytes

,[>++++<-]>[.....-]>

Input is provided in binary.

Similar to anatolyg's solution, this program corresponds to the minimal solution of a*b=10+a+b+c.

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

C++ (gcc)

without bonus: 57 bytes

#include<cstdio>
int main(){for(int i=57;i--;)puts("x");}

Try it online!

with bonus: 77 bytes (= Score 52)

#include<cstdio>
int main(){int i;scanf("%i",&i);for(i*=77;i--;)putchar(46);}

Try it online!

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

Clam, 4 bytes

p^97

Try it online!

Not very interesting.

Outputs 4782969 followed by a newline

Explanation:

p      - Print next token's value
 ^     - Exponent operator on next 2 tokens
  9    - Literal 9
   7   - Literal 7

9^7 = 4782969

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

Python 3, 37 14 bytes

print('a'*27)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You should consider adding an explanation or link to an online interpreter to your answer. See other answers for examples. If you answer only with code, it will automatically be flagged as low-quality. \$\endgroup\$
    – mbomb007
    Jun 6, 2019 at 19:13
0
\$\begingroup\$

Python 2, 12 Bytes

print 18**19

Outputs 708235345355337676357632 which is 24 characters.

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

33, 8 bytes

13c1[mo]

Prints 1211109876543210, which is 16 bytes long

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

Stax, 16 bytes - 25 = -9

|?xx{{dqF}{dqq}?

Run and debug it

Uses Stax's sneaky |? command, which means that the output is also 2 quines (or any other input number)

However, one downside is the fact that I can't use packed stax, as the |? operation prints out unpacked source code, even if the source is packed

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

MATLAB, 40 - 25 = 15 Bytes

I like using matlab, and I am slightly disappointed that what is probably the optimal answer for it has already been written. But here's a shot at achieving the bonus, which doesn't help ultimately but was fun regardless.

f=@(n)disp(char(linspace(1,2,2*2*10*n)))

Define an anonymous function that is 40 characters long. User calls the function as f(n) and it will output 40*n characters. (I think this complies with code golf rules but feel free to call me out if it doesn't)

with no output, the error message returned is

Not enough input arguments.

Error in @(n)disp(char(linspace(1,2,2*2*10*n)))
 
K

which comes out to 80 bytes, or 2x the length of my function. It's hacky but any other way would take more I'm fairly certain.

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

Braingolf, (9 - 25) = -16 bytes

91+<9*1-^

Takes n input and outputs a 1 followed by x zeroes where x = (n * 9) - 1

Braingolf, 5 bytes

91+9^

Outputs 1000000000 (10**9)

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

Vyxal, -18 bytes

2∨6*¤꘍₴

Try it Online!

2∨      # n || 2
  6*    # times 6
    ¤꘍  # spaces
      ₴ # Without a trailing newline

Polyglot, 1 byte

0

In Vyxal, 05AB1E, K, (edit in more), prints 0 with a trailing newline.

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

JavaScript, 21 16 13 bytes

alert("A"*26)
\$\endgroup\$
1
  • \$\begingroup\$ Not quite as clever as my last one, alert(9E16+this) \$\endgroup\$
    – user92753
    Jan 28, 2022 at 21:06
0
\$\begingroup\$

Turtlèd, 8 bytes

15:[*,l]

explanation:

[implicit] initial cell is *, initial char var is *
15       put 15 in register
  :      move right by as many cells as the amount in register
   [*  ] while cell not *
     ,l  write char var, move left 1 cell
\$\endgroup\$
0
\$\begingroup\$

Thunno d, 7 - 25 = -18 bytes

2~zd*ZL

Attempt This Online!

Explanation

2~       # Logical OR with 2
  zd     # Read the source code
    *    # Repeat it that many times
     ZL  # Print without a trailing newline
         # Implicit output

Thunno, 1 byte

1

Attempt This Online!

Prints 1 with a trailing newline. Any digit will work here.

\$\endgroup\$
2
  • \$\begingroup\$ I notice that in other answers 'Thunno' code-length has been scored in units of log256(96). If that were consistently applied, I suspect that it will be difficult to 'create output twice the length of the code' at all. But if it's not consistently applied, how does one decide which scoring to use? Selectively choosing a scoring system to suit the challenge seems a little cheaty... \$\endgroup\$ Mar 15, 2023 at 13:54
  • \$\begingroup\$ @DominicvanEssen it's just because of the rule "The program must be at least 1 byte long". I wrote the bottom answer before I wrote the top answer, and decided that since I used UTF-8 in the bottom answer, I would also use UTF-8 in the top answer. Also, there are answers which use UTF-16 rather than UTF-8, so I felt that it was fair to use UTF-8 instead of the Thunno encoding (log_256). \$\endgroup\$
    – The Thonnu
    Mar 15, 2023 at 13:58
0
\$\begingroup\$

Thunno 2, 8 - 25 = -17 bytes

2|8×⁻'x×

Attempt This Online!

Explanation

2|8×⁻'x×  # Implicit input (or not)
2|        # Logical OR with 2
          # (if there was no input, push 2)
  8×      # Multiply it by 8
    ⁻     # Decrement to account for
          # the trailing newline
     'x×  # Repeat the character "x"
          # that many times
          # Implicit output with newline
\$\endgroup\$
0
\$\begingroup\$

!@#$%^&*()_+, 2 bytes

^?

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ this outputs 5 bytes to stdout, not 4 \$\endgroup\$
    – Jo King
    Jun 15, 2023 at 5:51
0
\$\begingroup\$

Kib, 1 byte (noncompeting)

0

Any numeral works because of implicit output.
More interesting 4 byte solution

\A7*

\A     # Push char 'A'
  7    # Push 7
   *   # Multiply

(for reference this language is largely unfinished; I made it a couple months ago as a side project)

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

Racket, 72 - 25 = 47 bytes

#!racket
((λ(n)(display(make-string(*(if(eq? eof n)2 n)72)#\a)))(read))

Try it online!


Explanation

The language expression for Racket is #!racket. This just tells Racket's system what language to run the program with.

On line two, we create an immediately invoked lambda that receives one optional input from the user. User input can be either #<eof> (no input) or a number n. If there is no input, we set n to be 2.

We multiply n with the length of the program which is 72 bytes (λ counts as two bytes) and use the result to make a string of as. I could have saved 3 bytes by not specifying any character to be printed, but that would print an empty string with 72 null characters. Once the string is made, we print it to standard output.

#lang racket

((lambda (n)
   (display (make-string (* (if (eq? eof n) 2 n) 72) #\a)))
 (read))

Links to relevant documentation

Have a wonderful weekend!

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

Pascal, 39 Bytes

This complete program in accordance to ISO standard 7185 “Standard Pascal”

program p(output);begin write(6:78)end. { No trailing end‑of‑line character. }

prints

                                                                             6

without a trailing end‑of‑line character (tested with the GNU Pascal Compiler and FreePascal Compiler).

Pascal, 90 − 25 = 65

The overhead for the bonus does not pay off since you must add input to the program parameters list and test for EOF, because reading from input is illegal if the end of file has been reached.

program p(input,output);var n:integer;begin n:=2;if not EOF then read(n);write(1:90*n)end.
\$\endgroup\$
0
\$\begingroup\$

YASEPL, 22 - 25 = -3 bytes

=a'}7,""$2`1*22;"a",a~

YASEPL, 10 bytes (no input)

=a;"a",20~
\$\endgroup\$
1
6 7 8 9
10

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.