82
\$\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\$
  • 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
  • 40
    \$\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

254 Answers 254

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\$
  • \$\begingroup\$ Is it really worth it to have all the input stuff for a mere -25 bytes? \$\endgroup\$ – Jo King Dec 9 '18 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 '18 at 9:15
  • \$\begingroup\$ @AmirM Isn't reading the source code a standard loophole? \$\endgroup\$ – NieDzejkob Dec 9 '18 at 9:34
  • \$\begingroup\$ @NieDzejkob This isn't a quine question \$\endgroup\$ – Jo King Dec 9 '18 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\$
  • \$\begingroup\$ 50 \$\endgroup\$ – ASCII-only Mar 13 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\$
  • \$\begingroup\$ @JoKing Thanks, I keep forgetting that the interactive compiler doesn't need semicolons at the last statement \$\endgroup\$ – Embodiment of Ignorance Mar 6 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\$

Excel Formula, 23 - 25 = -2 bytes

=REPT("A",MAX(A1,2)*23)

However, this doesn't work for A1 (n) = 1(!)

Version supporting N=1, 28 - 25 = 3 bytes

=REPT("A",(A1=0)*56+(A1*28))
\$\endgroup\$
0
\$\begingroup\$

Keg, 6 2 bytes

(|A,)

It loops 12 times printing 12 A's to the console, which is double the size of the program. There is a control character (0x0C) between the ( and |, which makes this 6 bytes.

Another shorter version:

A

This prints A plus a newline, which contains 2 characters.

\$\endgroup\$
  • \$\begingroup\$ I don't think you have the byte count correct at the top of your answer. (|A,) is 5 bytes. Is there supposed to be a trailing newline? \$\endgroup\$ – mbomb007 Jun 6 at 19:18
  • \$\begingroup\$ There should be a control character between ( and |, which should be 0x0C. \$\endgroup\$ – A__ Jun 7 at 2:08
0
\$\begingroup\$

Python 3, 37 14 bytes

print('a'*27)

\$\endgroup\$
  • 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 at 19:13

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.