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

308 Answers 308

0
\$\begingroup\$

Scala, 52 - 25 = 27 bytes

object A extends App{println("#"*(args(0).toInt*52)}

Simply prints the string # repeated (arg * lengthOfCode) times.

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

s-lang, 30 bytes

t[][sssssssssssssss]t[s][ssss]

Link

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

Python 3, 20 bytes

print('#'*40,end='')

The optional argument end removes the newline. This is necessary due to universal newline support in Python which generates a \n on Linux and \r\n on Windows.

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

TI-Basic, -2 bytes

:Input N
:".
:While N23>length(Ans
:Ans+".
:End
:Ans
\$\endgroup\$
2
  • \$\begingroup\$ Where is the default value? \$\endgroup\$
    – Titus
    Commented Jan 27, 2017 at 4:40
  • \$\begingroup\$ TI-Basic doesn't accept empty input. \$\endgroup\$ Commented Jan 27, 2017 at 11:33
0
\$\begingroup\$

Juggle, Non-competing, 8 bytes

Golfed: 1<4=a[p]

Ungolfed

1<4    <--- literal for 1 bit-shifted left 4 indices, equal to 16
=a     <--- Set a equal to 16
[      <--- Iterate until a == 0
p      <--- Print a new line
]      <--- Decrement a by 1

This code effectively just outputs 16 \n characters, so there's not much to it.

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

Kitanai, 35 bytes

$0[70]#?(neq@0)([sub@1]print"!"&1)%

Just a simple loop to print 70 times the character "!".

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

PKod - 6 bytes

Code:
=0+ni6

Explanation:

=0 - Set variable as 0 (ascii code of 0 is 48, thus 48 is stored in the variable)
+n - Add 1 to variable (making it 49 on first iteration) and print ascii char code
i6 - 'i' kicks you back 2 blocks in code (to the '+' sign) until variable equals next char
which is '6'

Output:
495051525354
(note how it prints ascii char code from 1 to 6 (49 50 51 52 53 54) but without spaces.)

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

Java - 132 - 25 = 107 bytes

interface o{static void main(String[]a){int i=2,k=0;if(a.length>0)i=Integer.parseInt(a[0]);for(;k<132*i;k++)System.out.print('X');}}

Takes one number(Supposed to be a number, NumberFormatException otherwise) and converts it to an integer, if no input is present, it defaults to 2. Prints X characters.

Ungolfed version:

interface o {
    static void main(String[] a) {
        int i=2, k=0;
        if (a.length > 0)
            i = Integer.parseInt(a[0]);
        for (; k < 132 * i; k++)
            System.out.print('X');
    }
}
\$\endgroup\$
0
\$\begingroup\$

Processing, 31 29 bytes

for(int i=1;i++<34;)print(i);

I stumbled upon this submission from long ago and decided that it can be golfed more.

Outputs all the integers from 2 to 34 in a single line (58 bytes).

2345678910111213141516171819202122232425262728293031323334
\$\endgroup\$
2
  • \$\begingroup\$ I count 31 bytes of code ;) \$\endgroup\$
    – Titus
    Commented Jan 27, 2017 at 6:38
  • \$\begingroup\$ @Titus Haha, thanks for noticing that :) \$\endgroup\$
    – user41805
    Commented Jan 27, 2017 at 7:37
0
\$\begingroup\$

ForceLang, 13 bytes

io.write 1e25
\$\endgroup\$
0
\$\begingroup\$

Alice, 10 bytes - 25 = -15

2/
&oi@/a*

Try it online!

Prints a 0x02 byte and 10n-1 null bytes when given an argument n, and simply 20 null bytes when no argument is given.

Explanation

2   Push 2 as the default input.
/   Reflect to SE. Switch to Ordinal.
i   Read all input as a string. Pushes "" if no input is given.
    Reflect off bottom boundary, move NE.
    Reflect off top boundary, move SE.
/   Reflect to E. Switch to Cardinal
a   Push 10, the length of the source code.
*   Multiply. The first argument this pops is 10. But two pop another integer 
    argument, some implicit conversion needs to happen. If an input was given,
    that string is popped and converted to an integer, which will be used as
    the second argument. But if no input was given, the value "" contains no 
    integers, so it's discarded and Alice pops the next value instead (the
    default value 2 we pushed earlier).
    IP wraps around to the first column.
&   Repeat the next command that many times.
o   Pop that many values and print them as bytes.
i   Try to read more input, irrelevant.
@   Terminate the program.

Some alternatives

Without the bonus, we can do this in 4 bytes, printing 8 null bytes:

8&o@

Simple enough. There's a really fun and 6 byte solution with readable output though:

 /
O@n

This prints Jabberwocky with a trailing linefeed. The reason is that n is logical not, and the "canonical" truthy (non-empty) string used by Alice when applying this command to a falsy (empty) string is "Jabberwocky". So...

/   Reflect to SE. Switch to Ordinal.
n   Logical NOT. Pops an implicit empty string from the stack and turns it into
    "Jabberwocky".
    Reflect off bottom right corner, move back NW.
/   Reflect to W. Switch to Cardinal.
    IP wraps around to the last column.
/   Reflect to NW. Switch to Ordinal.
    Reflect immediately off top boundary, move SW.
O   Print "Jabberwocky" with a trailing linefeed.
    Reflect off bottom left corner, move back NE.
/   Reflect to S. Switch to Cardinal.
@   Terminate the program.

Try it online!

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

J, 2 bytes

!7

Prints 7 fatorial, or 5040.

If you include the trailing newline then use:

!6

Which would print 720.

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

k, 2 bytes

This is one byte, but I don't like the answer because it doesn't feel "proper".

1

When run in oK as a file (as opposed to interactively) it prints out a newline after printing the 1.


Another sort-of cheating answer:

11

If run in the closed-source k interpreter, it would output 11 followed by a newline and a space (and it would expect the next command).


$1

This would result in ,"1" if trailing whitespace was not counted.

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

Fourier - Non-competing, 12 - 25 = -13 bytes

Fourier is newer than this challenge.

I*12(1ox^~x)

Works by multiplying the input by 12 (the length of the program) and outputting the number 1 that many times.

Try it online!

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

Powershell 4 Bytes

,1*8

This prints '1' 8 times in the console window.

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

REXX 33 Bytes -25 = 8

say copies("x",max(2,"0"arg(1))*33)
\$\endgroup\$
0
\$\begingroup\$

Pari/GP, 2 bytes

7!

Prints 5040 in the REPL.

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

Fourier, 12 - 25 = -13 bytes

Non competing: Fourier is newer than the challenge

I*12(1oi^~i)

Try it on FourIDE!

Explanation pseudocode:

For i = 0 to (Input * 12)
    Print 1
\$\endgroup\$
0
\$\begingroup\$

Check, 14 - 25 = -11 bytes (non-competing)

.>2\&"?"*>14*o

Explanation:

.>2\& puts 2 at the back of the stack. If there were no arguments passed, this means 2 is at the top of the stack. Otherwise, the passed input is on top of the stack. We then repeat the character ? as many times as the stack number, and then repeat the result 14 times, and then output it.

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

QBIC, 16 - 25 = -9 36 - 25 = 11 32 - 25 = 7 bytes

:~a|q=a][q*4|?@ABCDEFGHIJKLMNOP

Explanation:

:           Get a cmd line paramenter 'a'
~a|         IF a <> 0 THEN
q=a]        set q to the value of a
            If we don't hit that IF-branch, q will be 1 by default in QBIC
[q*4|       And execute the following 4 times for each 'a/q'
?@QBICFTW!IJKLMNOP  Print this 16-byte string literal

The code is 16 bytes boilerplate and 16 bytes repeated output. Printing that output four times = 16x4 = 2x32 = double my source code length. And it accepts an input that does this N times.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Where is the default value? \$\endgroup\$
    – Titus
    Commented Jan 27, 2017 at 4:42
  • \$\begingroup\$ @Titus Hm, missed that bit. Fixed. \$\endgroup\$
    – steenbergh
    Commented Jan 27, 2017 at 6:52
0
\$\begingroup\$

Python 2, 28 bytes

Quick and simple, also unimaginative.

This prints 1 14 times, separated by spaces, and a newline at the end.

for i in range(14):print 1,

Try it online!

Note: the newline in the code is required, otherwise it won't run.

\$\endgroup\$
1
  • \$\begingroup\$ Correction: It will run, just won't give valid output. \$\endgroup\$
    – Makonede
    Commented May 11, 2021 at 21:04
0
\$\begingroup\$

Jq 1.5, 1 -9 -10 -1 bytes

range(inputs?//2)|23*"a"

Source is 24 bytes (-1 with bonus). Sample runs

Sample run with no input (defaults N=2)

$ jq -Mrn 'range(inputs?//2)|23*"a"' </dev/null
aaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaa

Confirm character count with no input (defaults N=2)

$ jq -Mrn 'range(inputs?//2)|23*"a"' </dev/null | wc -c
      48

Sample run with N=4

$ jq -Mrn 'range(inputs?//2)|23*"a"' <<< "4" | wc -c
      96

Verify length of program

$ echo -n 'range(inputs?//2)|23*"a"' </dev/null | wc -c
      24

Jq 1.5, 1 byte

1

Sample Run

$ jq -Mnr 1
1
$ jq -Mnr 1 | wc -c
       2
$ echo -n 1 | wc -c
       1
\$\endgroup\$
0
\$\begingroup\$

RProgN 2, 8 - 25 = -17

2)i‘8*x*

Try it online!

Explained

2)i‘8*x*    #
2           # Push two to the stack.
 )i‘        # Create a stack from the registry stack, inverse it, and pop the top value. If an argument is provided, it will use that, otherwise, it will use 2.
    8*      # Multiply it by 8 (The length of the code)
      x*    # Multiplied by the string "x".
\$\endgroup\$
0
\$\begingroup\$

Implicit, 1 byte

a

Pushes the ASCII character code for a (97). Implicit output. Try it online!

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

JavaScript (Node.js), 22 - 25 = -3 bytes

(x=2)=>''.padEnd(22*x)

Try it online!

If we require an alert-type output, this can be managed in 29 bytes - 25 = 4 points:

(x=2)=>alert(''.padEnd(29*x))

Versions without bonus (7 bytes):

x=>1e13

And with output as alert (12 bytes):

alert({}+$4)

Or without special console variables (14 bytes):

alert({}+1e12)
\$\endgroup\$
0
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.

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

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

\$\endgroup\$
1
  • \$\begingroup\$ @JoKing well so the other few Javascript answera are wrong ... \$\endgroup\$
    – l4m2
    Commented May 22, 2018 at 2:39
0
\$\begingroup\$

Ruby, 18 Bytes

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

36.times{print"a"}
\$\endgroup\$

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.