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>
312 Answers 312
Jalapeño, 6 bytes, -19 score
|2*6*
With a trailing space.
Hex-Dump of Bytecode
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: 57 32 52 36 52 25
Kind of boring answer, |2 gives either the Input, or 2 otherwise, *6 multiplies by 6, the source code length, and * then repeats space characters that many times.
As of Version 12 of Jalapeño, space is the only one byte string that takes one byte to represent, so it's optimal.
Nim, 19 bytes
echo newseq[00](12)
Produces output with a newline:
@[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Python 3, (削除) 28 (削除ここまで) 27 bytes - 25 bonus = 2 bytes
-1 byte by l4m2
lambda n=2:print(*[99]*9*n)
Takes in an int as input and outputs [99] (99 is an arbitrary two-char number) times 9, which is the length of the code (27) divided by 3. The star expansion operator * makes print print the contents of [99]*9*n as a space-separated string. There are 9*2n characters from the 99's, and 9*n-1 characters from the spaces, for a total of 18n+9n-1=27n-1 characters. With the newline (+1 byte) that becomes 27n characters printed.
-
\$\begingroup\$ What does the comma do? \$\endgroup\$l4m2– l4m22024年11月05日 05:36:01 +00:00Commented Nov 5, 2024 at 5:36
-
\$\begingroup\$ @l4m2 It's been a while, but I believe it was to pad the length to an even number. Because the
printoutputs newline a byte by default, we need to print lengths of the form(length)*n-1. I found this was easiest via the*operator, but that requires the length to be even. Because it is purely padding, maybe there are still optimizations. \$\endgroup\$Ethan C– Ethan C2025年03月19日 21:52:00 +00:00Commented Mar 19 at 21:52 -
-
\$\begingroup\$ @l4m2 That works, don't know how I missed that \$\endgroup\$Ethan C– Ethan C2025年04月10日 23:57:38 +00:00Commented Apr 10 at 23:57
><>, 29 + 2 (-v flag) - 25 = 6
l0=?21-:0(?;fe+1-ao:0=f*e+0.~
Takes input on the stack, which I believe is populated through -v on the official interpreter. Prints newlines only.
Microscript, 1
0
Prints the digit 0, followed by a newline.
-
\$\begingroup\$ codegolf.stackexchange.com/revisions/59457/3 What kind of edit is that?? Hahaha \$\endgroup\$Albert Renshaw– Albert Renshaw2015年10月03日 02:37:29 +00:00Commented Oct 3, 2015 at 2:37
q (bonus), 27 bytes
1#[;"x"]27*2^first"J"$.z.x;
C#, 104 bytes (79 point with bonus)
class a{static void Main(string[] p){System.Console.Write(new System.String('1',104*int.Parse(p[0])));}}
you can run the program by using an argument for example test.exe 2 prints 208 character '1'
-
1\$\begingroup\$ I think there's one rule missing: If no input is provided, n must default to 2 \$\endgroup\$Thomas Weller– Thomas Weller2015年10月07日 20:30:04 +00:00Commented Oct 7, 2015 at 20:30
awk, 29 - 25 = 4 bytes
{printf"%0"(0ドル?0ドル:2)*29"d",0}
Prints the wanted number of zeros.
Befunge-98, 26-25=1
&:#v_v>1.1-v
*d2<2<^_@#:<*
(削除) Run it in this interpreter. (削除ここまで) Apparently, it can't take input.
Befunge-93, (削除) 30 - 25 = 5 (削除ここまで) 27-25=2
&:#v_v>1.1-v
*93<2<^_@#:<*
There is a trailing space on the first line, and this is done because it's shorter to make 27 than it is to make 26 with Befunge-93. This outputs 27*n 1s in a row.
Perl, (削除) 10 (削除ここまで) 9 bytes
Uses @primo's suggestion of $=.
print$=x9
$= is a shortcut for $FORMAT_LINES_PER_PAGE, which defaults to 60.
Example:
$ cat doubler.pl
print$=x9
$ perl doubler.pl
606060606060606060
-
1\$\begingroup\$
print$=x9for one byte. \$\endgroup\$primo– primo2015年10月03日 08:35:18 +00:00Commented Oct 3, 2015 at 8:35 -
1\$\begingroup\$ I think
print$~x3also works for the same score. On my system, it outputsSTDOUTSTDOUTSTDOUT. \$\endgroup\$PhiNotPi– PhiNotPi2015年10月03日 19:55:46 +00:00Commented Oct 3, 2015 at 19:55
Stuck, -13 Bytes
i_0>;2?12*N*
This prints a bunch of newlines (N). Empty input is considered to be 0 (or anything less than 0). So, if 4 was given, it will print 48 newlines.
Old Answer - 3 Bytes
6Rj
will output
123456
Will be giving the bonus a shot.
C, 25
main(){printf("%*p",50);}
This makes use of UB, but it should work. At least it works with gcc 5.2.0
R, 3 bytes
10;
will print
[1] 10
QBasic, 2 bytes
?1
Nonnegative numbers in QBasic are output with both a leading and a trailing space. The PRINT command (for which ? is a shortcut) outputs a newline by default. Thus, I count 4 bytes of output: space 1 space newline.
Julia, 9
warn(⊆)
prints
"WARNING: issubset\n"
-
\$\begingroup\$ Might want to format your header differently so your score doesn't look like -8 instead of 9 \$\endgroup\$Patrick Roberts– Patrick Roberts2015年10月05日 04:05:31 +00:00Commented Oct 5, 2015 at 4:05
Insomnia, 1
7
Output:
00
8, A, B are 3 other programs that satisfy the requirement. Their output contains NUL characters, though.
MUMPS, 4 bytes
w ?8
Well, I'm not sure if this really counts. What this program does is advance the output cursor 8 characters to the right. On every terminal I've used, this is indistinguishable from outputting 8 spaces, but is it really the same thing? I dunno.
C, 82 bytes (with bonus)
main(int a,char**b){b&&b[1]&&(a=atoi(b[1])-1);a&&main(a-1,0),printf("%.80f",.0);}
Usage:
$ wc main.c
1 2 82
$ ./a.out | wc
0 1 164
$ ./a.out 4 | wc
0 1 138
$ ./a.out 133475 | wc
0 1 10944950
-
\$\begingroup\$ I think you can shave some off by modifying
bas you go:b&&*++b&&(a=atoi(*b)-1)\$\endgroup\$Toby Speight– Toby Speight2015年10月06日 10:31:04 +00:00Commented Oct 6, 2015 at 10:31 -
\$\begingroup\$ Yes comrade! It does work. \$\endgroup\$wefwefa3– wefwefa32015年10月06日 17:43:51 +00:00Commented Oct 6, 2015 at 17:43
DOS, 7 bytes
date /t
outputs di 06-10-2015 (and a newline) on my system, but I'll admit it's locale dependent. So my second best is:
echo %PATH:~0,33%
which outputs C:\WINDOWS\system32;C:\WINDOWS;C: (and a newline).
-
\$\begingroup\$ With my system settings it prints
2015年10月07日\n\$\endgroup\$SuperJedi224– SuperJedi2242015年10月07日 10:12:42 +00:00Commented Oct 7, 2015 at 10:12 -
\$\begingroup\$ Got 6.2 bytes using "type %0". \$\endgroup\$Star OS– Star OS2015年12月16日 12:03:16 +00:00Commented Dec 16, 2015 at 12:03
-
\$\begingroup\$ @StarOS That gives me
The system cannot find the specified file(roughly translated) \$\endgroup\$Berend– Berend2015年12月17日 07:45:56 +00:00Commented Dec 17, 2015 at 7:45 -
\$\begingroup\$ Berend, it only works in a Batch file. +1 beacuse all of the other things don't use a shell, it uses a file \$\endgroup\$Star OS– Star OS2015年12月17日 11:25:51 +00:00Commented Dec 17, 2015 at 11:25
-
\$\begingroup\$ @Berend Note, you are using Windows Batch, not DOS Batch. The string manipulation function is added in Windows, not DOS. \$\endgroup\$stevefestl– stevefestl2017年09月22日 23:52:51 +00:00Commented Sep 22, 2017 at 23:52
Bash + GNU coreutils, -1 byte
printf %24s `seq ${1-2}`
Score is 24-25
A non-bonus version for +5:
seq 5
which produces 1 nl 2 nl 3 nl 4 nl 5 nl.
Bash + GNU coreutils, (削除) 26 (削除ここまで) 24 - 25 = (削除) 1 (削除ここまで) -1 byte
The x file:
yes|head -c$[24*${1:-2}]
(no trailing newline)
Running:
$ bash x 1 | wc -c
24
$ bash x | wc -c
48
$ bash x 3 | wc -c
72
Old version with 26 bytes:
The x file:
yes|head -c$((26*${1:-2}))
(no trailing newline)
-
\$\begingroup\$ @Unihedron I don't see how this violates that rule. \$\endgroup\$Doorknob– Doorknob2015年10月04日 14:30:25 +00:00Commented Oct 4, 2015 at 14:30
POSIX bc, 4 bytes
10^7
This creates the output 10000000.
Javascript, 3 bytes!
1e5
Returns 100000. Y'all JS golfers are overthinking it!
-
\$\begingroup\$ After bashing my head on the wall for several hours I managed to come up with a even shorter pure JS solution: codegolf.stackexchange.com/a/60082/21830 \$\endgroup\$Unihedron– Unihedron2015年10月08日 12:17:30 +00:00Commented Oct 8, 2015 at 12:17
CJam, 1 byte
A
Prints 10. Very straightforward.
Pyth, 4 bytes
*8"1
will print out
11111111
-
1\$\begingroup\$ Why did someone EDIT my answer??? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2015年10月07日 15:25:36 +00:00Commented Oct 7, 2015 at 15:25
-
\$\begingroup\$ I like how you rolled back their changes and then added them back in. \$\endgroup\$Luminous– Luminous2015年10月09日 12:53:30 +00:00Commented Oct 9, 2015 at 12:53
-
1\$\begingroup\$ @Luminous I did it because I want editors to learn not to edit my answers. They can suggest in comments instead! \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2015年10月10日 12:41:30 +00:00Commented Oct 10, 2015 at 12:41
-
1\$\begingroup\$ Well the thing in this case was that editor didn't just edit your answer. They changed it to be completely different. They should've made it another answer. Other wise you shouldn't feel like your answer is being violated if someone edits it. We can edit other people's answers for plenty of reasons. \$\endgroup\$Luminous– Luminous2015年10月11日 14:43:32 +00:00Commented Oct 11, 2015 at 14:43
-
\$\begingroup\$ @Luminous Yeah, and I added them back in because I got that as a suggestion. But if they do not have rep to comment then they should add just a small not on the bottom of the answer but not EDIT it. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2015年10月12日 11:33:07 +00:00Commented Oct 12, 2015 at 11:33
APL, -8 bytes
×ばつ{0::2⋄⎕}⍬
Explanation:
{0::2⋄⎕}⍬: Try to read a number from the keyboard. If the user entered a valid number, return it; if not, return2.×ばつ: multiply it by 17 (the length of the code)'*'⍴⍨: output that many asterisks.
[this is a sticky note] This answer has multiple versions.
Due to the fact that I honestly am not quite sure what "input" means here. The first is the one I would use to score myself. Go down to the second to find an explanation. For scoring 1 point, do I tie with the Matmematica one? Or for scoring -1 (-5?) points, do I win? Hmm.
Anywho, this was quite a fun challenge. Maybe I can make my answer a bit better but anyways.
Python 2.7, 26 - 25 = 1
If input means input from stdin:
print("|"*26*input())[:-1]
Python 2.7, 24 - 25 = -1
If input means a variable:
n=2;print("|"*24*n)[:-1]
Wuut?
n=2 # Set a variable n to 2
; # Separate statements (like a line break)
print # Print..
( # This is in 2.7, not 3, where print is a
# statement, not function
"|" # Any character works here
*24 # Multiply said character by 24
*n # Multiply resulting string by n
)
[:-1] # Remove one character due to the line break
# automatically created by print.
Python 2.7, 20 - 25 = -5.
If input means a variable, and you don't count n=2; as part of the program:
Simply change 24 to 20:
print("|"*20*n)[:-1]
-
1\$\begingroup\$ It's standard for input to mean STDIN or a function argument. \$\endgroup\$lirtosiast– lirtosiast2015年10月27日 14:46:44 +00:00Commented Oct 27, 2015 at 14:46
Burlesque - 7 Bytes
blsq ) '*14.*Q
**************
It just prints 14 asteriks, while the length of the program is 7 bytes. As for the bonus:
ri12.*'*j.*Q
is 12 bytes long and prints 12*n (number provided on STDIN) asteriks.
Minkolang 0.9, 11-25 = -14 bytes
This language was created after this challenge, but not for it.
nd1+?2["d].
Explanation
This takes an integer from input, pushing a 2 on the stack if it's -1 (i.e., the input is empty). Then I use the clever quine trick: the " pushes the whole program (except the ") onto the stack. To make up for the ", I duplicate the top of stack with d. This is printed out n or 2 times and then the program stops. In the case where there is no input, there is indeed a -1 on the stack. However, Minkolang outputs nothing for negative numbers, so it does not add anything.
n * program lengthbytes, or is that a minimum? \$\endgroup\$