89
\$\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

267 Answers 267

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

Japt -P, 3 - 25 = -22 bytes

õ@L

Try it online!

How it works

Uõ@L

Uõ  Create range of [1..input] inclusive, and map...
@L  the function that returns the constant 100.

The õ generates [1,0] for no input (implicit zero) and [1,...,n] for positive integer input, which perfectly fits with the default=2 requirement.

The -P flag prints the resulting array with no separator, so the output length is exactly 3 times the length of the array.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

F#, 46 bytes

let[<EntryPoint>]m a=
 printf"%A"[|10..31|]
 0

Try it online!

Prints out:

[|10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31|]

which is 92 bytes long.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Brain-Flak, 30 bytes

([()()()()()]){((((({}))())))}

Try it online!

Prints three 0s, four each of -1 through to -4 and two -5s, each separated by spaces.

With bonus: 62 - 25 = 38 bytes

({{}[()()]}()()){({}<((()()()()()){}){({}(([()])))}>[()])}{}  

Try it online!

Outputs n*(20*"-1 "+"0 "). There are two extra spaces to pad it out to 62 bytes.

How It Works:

({{}[()()]}()()) Add a 2 to the stack if there is no input
{ Outer loop
  ({} Pop the outer loop counter
  <
  ((()()()()()){}) Add a 10 to the stack
  { Inner loop
    ({}(([()]))) Decrement the inner loop and add two "-1"s to the stack
  }
  > Discard the inner value
  [()]) Decrement the outer loop counter
}
{} Pop the excess 0
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

JavaScript REPL, 24-25 = -1 bytes

Array(24*prompt()||48)+0

JavaScript function, 20-25 = -5 bytes

(n=2)=>Array(20*n)+0
n=>Array(20*n||40)+0

Just how no one post this?

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ @JoKing well so the other few Javascript answera are wrong ... \$\endgroup\$ – l4m2 May 22 '18 at 2:39
0
\$\begingroup\$

Ruby, 18 Bytes

I am lazy to make the input thing. So take the *2.

36.times{print"a"}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 17 bytes - 25 = -8

Echo[10^(17#-5)]&

Try it online!

Assuming giving a function is OK. Prints >> 1, then (17 * input - 5) 0s, then a trailing new line, thus making the output 17 * input bytes long.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Charcoal, 1 byte

²

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ No longer works, so you need to use this instead \$\endgroup\$ – ASCII-only Jun 1 '18 at 23:13
0
\$\begingroup\$

Gol><>, 8 - 25 = -17 bytes

IE28*Rn;

Try it online!

Outputs all 0s.

Explanation:

I        Get inputted number
 E2      Push 2 if no input
   8*    Multiply by 8  (length of code)
     Rn  Print 0 that many times
       ; Halt

Without bonus, 4 bytes

"D;

Try it online!

Outputs [68 59]. Note that both input and output have a trailing newline.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Python3 Shell version

'2'*10

outputs:'2222222222'

| improve this answer | |
\$\endgroup\$
  • 3
    \$\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 '18 at 1:26
0
\$\begingroup\$

Ahead, 4 bytes

8kO@

Prints 00000000.

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

Try it online!

| improve this answer | |
\$\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!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This doesn't print 2*bytes for no input \$\endgroup\$ – Jo King Dec 9 '18 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);
    }
}
| improve this answer | |
\$\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!

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 50 \$\endgroup\$ – ASCII-only Mar 13 '19 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!

| improve this answer | |
\$\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 '19 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
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Tamsin, 40 bytes

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

Try it online!

Outputs 80 of the character a.

| improve this answer | |
\$\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!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

ink, 1 byte

s

Try it online!

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

| improve this answer | |
\$\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.

| improve this answer | |
\$\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!

| improve this answer | |
\$\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

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Python 3, 37 14 bytes

print('a'*27)

| improve this answer | |
\$\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 '19 at 19:13
0
\$\begingroup\$

Python 2, 12 Bytes

print 18**19

Outputs 708235345355337676357632 which is 24 characters.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

33, 8 bytes

13c1[mo]

Prints 1211109876543210, which is 16 bytes long

| improve this answer | |
\$\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

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

GolfScript, 13-25 = -12 bytes

.~13*(25if n*

Try it online!

Explanation

        if     # If
.              # Input is not a null string:
 ~             # Evaluate the input
  13*(25
           n*
| improve this answer | |
\$\endgroup\$
1
5 6 7 8
9

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.