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\$ 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
6
7
8 9 10
1
\$\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.

Worth a mention(3 bytes):

5/

TIO

\$\endgroup\$
2
  • \$\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 '19 at 19:18
  • \$\begingroup\$ There should be a control character between ( and |, which should be 0x0C. \$\endgroup\$
    – user85052
    Jun 7 '19 at 2:08
1
\$\begingroup\$

GolfScript, 18 - 25 = -7

.!35 n*{~18*(n*}if

Try it online!

Prints \$input * 6 - 1\$ newlines if there is an input else 35 newlines, plus one trailing newline.

                if           If
.!                           input is empty:
  35 n*                      35 newlines
       {       }             Else:
        ~18*(n*              18 * input - 1 newlines
                             Trailing newline
\$\endgroup\$
2
  • \$\begingroup\$ My mistake. I thought for the bonus it would always take input. I'll edit to account for that. \$\endgroup\$
    – Pseudo Nym
    Dec 9 '19 at 18:09
  • \$\begingroup\$ It's been fixed. \$\endgroup\$
    – Pseudo Nym
    Dec 9 '19 at 18:46
1
\$\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*
\$\endgroup\$
1
\$\begingroup\$

naz, 2 bytes

4o

Outputs 0000.

Explanation

The default value of the register is 0; if the register's value is between 0 and 9 inclusive, use of the o instruction will output that number as an ASCII character.

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

TlanG 3 bytes

.*6

Out: ......

Explainations in the readme on the TlanG github.

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

Python - (32 bytes - 25) = 7

k="1"*32
n=int(input())
print(k*n)

So close :(. This code takes a string k (which is 32 chars long, same as this code), takes n as an input, and prints k repeated n times.

Python - 16 bytes (no bonus)

k="1"*32
print(k)

Same as above, but without taking input, and thus, the code is only 16 bytes long.

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

BRASCA, 2 bytes

CK

Try it!

Explanation

C   - Output implicit output as number
 K  - Push 1000
\$\endgroup\$
1
\$\begingroup\$

Pxem, 30 bytes (Filename) + 0 bytes (Content) - 25 bytes (bonus) = 5 bytes, requires nonprintable character, does not deal with default.

  • Filename (nonprintable is escaped): ._.c.w.tXXX.eX.eX.e.p.m\001.-.c.a
  • Content is empty.

Try it online! (with pxem.posixism)

With comments

XX.z
# read integer and push it (pxem.posixism errors when not given)
.a._XX.z
# dup; while pop!=0; do
.a.c.wXX.z
  # heap=pop
  .a.tXX.z
  # .e command actually stands for calling content as
  # subroutine BUT content is empty so it stands for
  # duplicating entire stack
  # also non-command substrings stand for literals
  # so stack would have (3*2+1)*2+1*2=30 X's
  .aXXX.eX.eX.eXX.z
  # pop all to output each of them
  .a.pXX.z
  # push heap; push 1; push abs(pop-pop); dup
  .a.m\001.-.cXX.z
# done
.a.a

Pxem, 12 bytes (Filename) + 0 bytes (Content) = 12 bytes.

  • Filename: XX.eXX.e.e.p
  • Content is empty.

It outputs 24 X's without trailing LF.

Try it online!

How it works

XX.z
# push two X's
.aXXXX.z
# call content (as subroutine), pushing final result
## NOTE if original stack was 1,2,3 from top,
## the subroutine stack is also intialized with 1,2,3
## Then when returning from subroutine with final result of stack 4,5,6
## then original stack would be 4,5,6,1,2,3
## Since content is empty, it stands for duplicatinf entire stack
.a.eXX.z
## now X,X,X,X
# push two X's
.aXXXX.z
## now four X's
# duplicate entire stack twice
.a.e.eXX.z
# finally pop all to output each of them
.a.p
\$\endgroup\$
1
\$\begingroup\$

Julia, 6 bytes

@info%

outputs in stderr (12 bytes including the trailing newline)

[ Info: rem

Explanation: % is the rem function (remainder)

Try it online!

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

Excel, 23 - 25 = -2 bytes

=REPT(0,IF(A1,A1,2)*23)

Saves 2 bytes by repeating a number instead of a character.

Excel, 4 bytes

=8^8

8^8 is an 8 digit number

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

Subleq, 12 11 bytes (Assuming an 8 bit word)

2 -1 88 10 11 -1 8 8 0 1 22

Subleq emulator

Explanation

0:  2 -1 88 ' Output 2: "X"
3:  9 10 -1 ' 10: = 10: - 9:, if 10: <=0 exit
6:  8  8  0 ' 8: = 0, goto 0
9:  1 22    ' data

64 bit word, 96 88 bytes

2 -1 88 9 10 -1 8 8 0 1 176
\$\endgroup\$
0
\$\begingroup\$

Python 3.4, 14 13 bytes

print("a"*26)
\$\endgroup\$
2
  • \$\begingroup\$ This is only 13 bytes. Which makes your score 41 (13 + 28). You can lose two points by changing 28 to 26. \$\endgroup\$
    – Zach Gates
    Oct 3 '15 at 3:31
  • \$\begingroup\$ Did you think about say()? \$\endgroup\$
    – Titus
    Jan 27 '17 at 6:59
0
\$\begingroup\$

Pyth, 6 bytes

*4"aaa

Explanation:

*4"aaa
-------+------------
  "aaa | Print "aaa"
*4     | 4 times

Pyth, -7 bytes

*.xvw2*2"aaaaaaaaa

Plain and simple.

*.xvw2*2"aaaaaaaaa
-------------------+----------------------
      *2"aaaaaaaaa | Print twice the "a"s
*                  | times
 .xvw              | try to evaluate input
     2             | otherwise, 2
\$\endgroup\$
2
  • \$\begingroup\$ For the bonus, if no input is provided, it should default to 2. \$\endgroup\$
    – Dennis
    Oct 3 '15 at 17:37
  • \$\begingroup\$ Yup, just noticed that. Fixed. \$\endgroup\$
    – clapp
    Oct 3 '15 at 17:39
0
\$\begingroup\$

C#, 63 62 bytes

class P{static void Main(){System.Console.Write($"{1,124}");}}

Will print 123 spaces followed by 1.

\$\endgroup\$
2
  • \$\begingroup\$ How does this work? \$\endgroup\$ Dec 29 '15 at 14:20
  • \$\begingroup\$ @LegionMammal978 in C# 6, @"{1,124}" is the equivalent of string.Format("{0,124}", 1) which means format the number 1 to a string with a minimum length of 124. It uses spaces to pad the value to the minimum length. See composite formatting. \$\endgroup\$ Dec 29 '15 at 14:45
0
\$\begingroup\$

Ruby, 22 bytes - 25 bytes = -3 bytes

c=->n=2{p ?d*21*n}
c[]

The reason the value shows up as 21 bytes in the code itself is that the quotation marks are printed, effectively reducing the number of bytes I need to print by 2 (left paren and right paren).

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

><>, (15 + 3) - 25 = -7

2}f*:?!;1n1-30.

Like torcado's answer, but a one-liner. Takes input via the -v flag, e.g.

py -3 fish.py double.fish -v 5

and outputs 15*<input> ones.

><>, 5 bytes

"nn#;

Here's a version without any bonuses. Outputs 5935110110.

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

Ruby, 5 bytes

p 1e6

Outputs 1000000.0 and a newline, which is 10 bytes in summary

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

GolfScript, 11 - 25 = -14 bytes

~2]0=11*(n*

Given n, outputs n times as many newlines as the length of the code in bytes (= 11). Given no (i.e. empty) input, outputs 22 newlines.

The implementation is very straightforward:

  • ~ evals the input,
  • 2]0= replaces an empty input with 2,
  • 11* multiplies the input number with 11 (the length of the program),
  • ( decrements the number by 1 (to account for the automatically inserted trailing newline), and
  • n* repeats a newline the given number of times.
\$\endgroup\$
0
\$\begingroup\$

Brainfuck, 25 bytes

Prints 50 characters, most of which are control characters.

+++++++[>+++++++<-]>+[.-]
\$\endgroup\$
0
\$\begingroup\$

Powershell, -10

"a"*15*$args[0]

Powershell, 2

This answer without the bonus is probably golfier though

$?

Outputs;

True
\$\endgroup\$
6
  • \$\begingroup\$ @TimmyD does the automatic Newline added after printing count as a character? If so that doesn't work (since you end up at 2n+1). Can use param($b=2)'1'*(24*$b-2) for -1 \$\endgroup\$ Oct 7 '15 at 15:11
  • \$\begingroup\$ @JonathanLeech-Pepin No - that won't work, either, for the same reason. See my corrected answer \$\endgroup\$ Oct 7 '15 at 15:14
  • \$\begingroup\$ @TimmyD Actually with -2 at the end of the multiplier it does. According to ISE @{1=23;2=47;3=71}. 24 characters in the function so that works when adding the newline. \$\endgroup\$ Oct 7 '15 at 15:26
  • \$\begingroup\$ @JonathanLeech-Pepin Let's continue this discussion in chat \$\endgroup\$ Oct 7 '15 at 16:21
  • \$\begingroup\$ Also, if given no input, it should default to 2. \$\endgroup\$ Dec 29 '15 at 14:08
0
\$\begingroup\$

Sed, 40 - bonus = 15

s/^$/11/
s/.*/&&&&&/
s//&&&&&&&&/
s/.//

There's no final newline. Input is in unary, as you'd expect for sed.

We begin by defaulting the input to two. Then we multiply it by 5 and then by 8 for a total multiplication of 40. Our output includes a newline, so we must subtract one before it's printed.

Test results

$ for i in '' 1 11 111 1111; do sed -e 's/^$/11/;s/.*/&&&&&/;s//&&&&&&&&/;s/.//' <<<"$i" | wc -c; done
80
40
80
120
160
\$\endgroup\$
1
  • \$\begingroup\$ It took a bit of trial and error to settle on 8*5 for 40; I had 5*3*3 and 7*3*2 as a couple of early attempts. \$\endgroup\$ Oct 6 '15 at 10:51
0
\$\begingroup\$

Python 3, 30 - 25 = 5

print(int(input()or 2)*30*"X")

It expects input on standard input, an empty input is treated the same as 2.

If we can use the REPL, rather than running as a script, you can remove the print call, to save 7 bytes and bring our score down to -2:

>>> int(input()or 2)*21*"X"
1
'XXXXXXXXXXXXXXXXXXXXX'

(Note that we multiply by 21, rather than 23 because of the quotation marks that appear in the string's repr.)

A Python 2 version of the same code can be written for three extra bytes (we need to add raw_ to the input, but can replace the pair of parentheses around print's arguments with a single space):

print int(raw_input()or 2)*33*"X"
\$\endgroup\$
0
\$\begingroup\$

C#, 77 bytes

102 bytes - 25 bonus

class c{static void Main(string[]a)=>System.Console.Write(new string('x',102*int.Parse(a[0]??"2")));}

Creates a string of the specified length, defaulting to 2.

\$\endgroup\$
1
  • \$\begingroup\$ @ThomasKwa: fixed it by providing a different solution. \$\endgroup\$ Oct 7 '15 at 20:50
0
\$\begingroup\$

Go, 59 Bytes

package main
import"fmt"
func main(){fmt.Printf("%118d",0)}

Prints 0 formatted with padding

Here is a version with argument (145-25 Bytes):

package main
import("os"
"fmt")
func main(){i:=2
if len(os.Args)>1{fmt.Sscanf(os.Args[1],"%d",&i)}
fmt.Printf("%"+fmt.Sprintf("%d",i*145)+"d",i)}
\$\endgroup\$
1
  • \$\begingroup\$ As has been mentioned in a suggested edit: You should output double length than the one of the code, not the exact length of the code. \$\endgroup\$
    – daniero
    Oct 10 '15 at 13:04
0
\$\begingroup\$

Hassium, 55 Bytes

use Math;func main(){ for(x=0;x<7;x++)print(Math.pi); }

Output:

3.141592653589793.141592653589793.141592653589793.141592653589793.141592653589793.141592653589793.14159265358979

Run and see online here

\$\endgroup\$
1
  • \$\begingroup\$ I thought extra whitespaces are not allowed? \$\endgroup\$
    – Leaky Nun
    Mar 30 '16 at 9:59
0
\$\begingroup\$

Simplex v.0.5, 22 - 25 = -3 bytes

i?[{u(' R)22vM}ug#]2O3
i                      ~~ take input as number
 ?[               ]    ~~ do inside if byte is nonzero
   {          }        ~~ loop inside until zero byte met
    u       v          ~~ up/down strip traversal
     (   )22           ~~ repeats the inner 22 times
      '@R              ~~ pushes an @ and goes right
               ug      ~~ goes to the string strip and clears the strip
                 #     ~~ cease!
                   2   ~~ sets the current byte to two (default N)
                    O3 ~~ goes to the third byte in the source code

Essentially, for each pass of an integer N (input), the string @@@@@@@@@@@@@@@@@@@@@@ is printed once, i.e., N*"@@@@@@@@@@@@@@@@@@@@@@". Since the (...) is a preproccesed command, variable inputs cannot be handled. If they could, then I might shorten the code to something like ('@R)ig whilst handling the special cases. Wouldn't that be something?

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

Mouse-2002, 32 - 25 = 7 bytes

A quine is not possible in Mouse, unfortunately, else I would have gone that way.

?&DUP 0=[1]32*y:(y.x.>^1!x.1+x:)

Explained:

? &DUP        ~ get some input; dup it
0 =           ~ if 0
[             ~ then
  2           ~ push 2 instead
]             ~ fi
32 * y:       ~ push 32* and assign into y
(             ~ while(true)
  y. x. > ^   ~ cmp
  1 !         ~ print a 1
  x. 1 + x:   ~ increment x
)             ~ endwhile
$             ~ (implicit) end prog
\$\endgroup\$
0
\$\begingroup\$

Note: This answer did not work when the question was asked, so it is not a competitive solution.

Pyth, 6 - 25 = -19 bytes

mb.xE2

Demonstration

First, we attempt to take STDIN input and evaluate it. It this throws an error, we use 2 instead. Then, we make a list of that many newline characters. Newline characters take 4 characters to represent ('\n') and there are 2 bytes of list overhead ([] or ,) per element, so it comes out to exactly 6 times longer than the above number.

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

Perl, 11 bytes

print"J"x22

Using the lovely x operator, prints 22 Js. I may be able to find a shorter answer.

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

Python 2, 11 -1 -6 -11 bytes

'M'*input()*14

Prints 14 * input Ms. Requires a REPL environment.

There may be a way to make it shorter, but at this point I doubt it.

Changes

  • Saved 5 bytes by not using int().
  • Saves 5 more bytes thanks to @cat and using a REPL environment.
\$\endgroup\$
3
  • \$\begingroup\$ the question doesn't say assuming a REPL environment is disallowed, so 'M'*input()*14 is shorter for 14 == -11 \$\endgroup\$
    – cat
    Dec 17 '15 at 16:29
  • 1
    \$\begingroup\$ @cat Thanks, I'll add that in now. \$\endgroup\$ Dec 17 '15 at 16:42
  • 2
    \$\begingroup\$ If no input is provided, you must default to 2. This does not. \$\endgroup\$
    – isaacg
    Mar 30 '16 at 1:54
1
6
7
8 9 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.