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

1
\$\begingroup\$

Attache, 11 bytes

10^20|Print

Try it online!

Attache (bonus), 36 - 25 = 11 bytes

(Safely[ReadInt][]or 2)*36*$x|Output

Try it online!


Uh. Both come out to be the same byte count. So there's that.

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

Minecraft Functions (18w15a, 1.13 snapshots), 26 bytes

Uses one function named ab

ab

function ab
tp @e ~0 ~0 ~0

It just recurses until it hits the default limit of 65536, at which point it outputs Executed 65536 commands from function 'minecraft:ab'

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

Rebol, 24 bytes

copy/part mold system 48

Prints the first 48 characters of the system object.

Also works with the Red language

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

Hummus, 20 bytes (non-competitive)

().(rep('xx',20)).()

Explanation:

().(rep('xx',20)).()   //Empty anonymous function

().                   //Empty parameter declaration 
   (rep('xx',20))     //Repeat 'xx' 20 times
                 .()  //Empty value declaration

In contrast, a non-empty, anonymous function would look like this:

(x).(x*x).(2)

(x).          //Defines x as parameter
    (x*x)     //Defines the output to be x*x or x²
         .(2) //Defines the input of the anonymous function to be 2 (hence the output is 4)

Alternative, 2 bytes:

!0

This works as well and outputs true but since this was posted multiple times already, I found it to be quite a boring solution.

\$\endgroup\$
  • \$\begingroup\$ You should add the fact that this is non-competitive. Also is the language a stable release or a WIP ? \$\endgroup\$ – Muhammad Salman Jun 4 '18 at 19:33
  • \$\begingroup\$ @MuhammadSalman It's in Beta rn (still missing a lot of standard functions) but it's actually quite stable. \$\endgroup\$ – Azeros Jun 4 '18 at 19:36
  • \$\begingroup\$ Okay. So still a WIP then. I like the language so far (also an interesting choice of languages in which you are building this) \$\endgroup\$ – Muhammad Salman Jun 4 '18 at 19:48
  • \$\begingroup\$ @MuhammadSalman Thanks! Appreciated! But why did you add the "non-competitive"? \$\endgroup\$ – Azeros Jun 4 '18 at 19:54
  • \$\begingroup\$ The challenge precedes the language. \$\endgroup\$ – Muhammad Salman Jun 4 '18 at 20:01
1
\$\begingroup\$

///, 15 bytes

/o/ttttt/oooooo

Try it online!

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

Z80Golf, 14 bytes - 25 bytes of bonus = 11 anti-matter bytes (-11 classic bytes)

00000000: 3e02 cd03 8006 0eff 10fd 3d20 f876       >.........= .v

Try it online!

Takes input as a byte value.

    ld a, 2
    call $8003
outer:
    ld b, 14
inner:
    rst $38
    djnz inner
    dec a
    jr nz, outer
    halt
\$\endgroup\$
1
\$\begingroup\$

Python 3, 26 25 Bytes

lambda n=2:print(n*26*'-')

Improved thanks to @JoKing

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

Come Here, 39 bytes

CALL"9999999999999"iTELLi i i i i iNEXT
\$\endgroup\$
1
\$\begingroup\$

Boolfuck, 21 bytes

+[[>+>+[<;;;]<]>+>>]>

This program outputs 330 bits (41.25 bytes) which get buffered to 42 bytes. I found it by systematically (but not quite exhaustively) searching through several million possible candidates.

Here is a hexdump of the output:

00000000: fc0f ffe3 ffc7 ffff ff1f fe3f ffff f8ff  ...........?....
00000010: ffff ffff c0ff fe3f ffff ff1f ffff ffff  .......?........
00000020: ff1f ffff ffff ffff fe00                 ..........

Try it online!

I also recommend taking a look at this in fatiherikli's Brainfuck visulizer (optimized and with minimal delay of course).

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

8088 machine code, IBM PC DOS, 35 bytes

Unassembled listing:

        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
81 FE 0123  CMP  SI, OFFSET _EF ; is SI < last byte? 
7C DE       JL   _LOOP          ; if so, keep looping 
C3          RET                 ; return to DOS 
        _EF EQU $               ; get program size 

This is a complete IBM PC DOS executable that displays itself as ASCII hex, so will always output as twice the program size.

Output

enter image description here

Download and test SELF.COM!

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

Husk, 13 bytes - 25 = -12

R'A*13→←`↓ΘN←

Try it online! (Try it with no arguments!)

(Both TIO links use capital xi instead of A because it looks cooler, but since I just realized that output has to be ASCII and xi isn't exactly ASCII although it is one byte in Husk's code page, the "canonical" program here uses A instead.)

I tried to come up with a well-thought-out and enlightening explanation of why Husk's overload resolution for built-ins doesn't support distinguishing type signatures by number of arguments alone, but I couldn't quite get it right and it took long enough just to write the solution. Suffice it to say, it doesn't, so I had to get a bit creative.

The first part functions the same with and without an input:

R           Repeat
 'A         capital A (could be any character)
    13      (thirteen
   *         times
      →      (one plus
       ←      the first element of
              whatever expression we get to the right of this))
R           times.

The rest of the program handles the defaulting behavior, by exploiting 's possession of overloads for using either a function or a number to drop a prefix from a list.

Explained with an input:

   N     The infinite list of the natural numbers
  Θ      with a zero tacked on to the beginning
`↓       with the first
         (input
    ←     minus one)
`↓       elements removed.

Without an input:

   N     The infinite list of all natural numbers
  Θ      with a zero tacked on to the beginning
`↓       without the largest prefix every element of which
    ←    is not equal to 1.

A version which elects to not take the bonus:

Husk, 2 bytes

←.

Try it online!

Husk assumes that, in the absence of any digits on the left of the radix point, a single 0 is meant, and in the absence of any on the right, a single 5 is meant. So, it is possible to write 0.5 as just .. 0.5, as a string, is three bytes long (and so is 1/2, which is what actually gets printed), so to add a byte, subtract 1 for -0.5 (although what we actually print is -1/2).

←     Subtract 1 from
 .    0.5.

A longer and sillier no-input version:

Husk, 3 bytes

ss"

Try it online!

Prints "\"\"".

s      The string representation of
 s     the string representation of
  "    the empty string.

A version which must take input, having no valid type if it doesn't take an input, and thus neither does nor doesn't take the bonus, failing to comply with the challenge at all:

Husk, 4 bytes (invalid but here anyways, would be -21 with bonus)

*s"¨

Try it online!

Prints n copies of "\"".

 s      The string representation of
  "     the string containing
   ¨    a single "
*       repeated n times.
\$\endgroup\$
1
\$\begingroup\$

TinCan, 122 bytes

# 62367, A, &                          #
# -256, A, -1                          #
# 0, A, 1                              #

Outputs 244 'a's.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Try it online!

Explanation:

Lines have a minimum length of 40 characters in TinCan, and there is only one instruction, so 40 bytes would be the shortest feasible TinCan program other than an empty file.

TinCan's interpreter is written in PHP and uses the PHP chr function to output the character value of each number on the stack when the program ends. This also works for values outside the range of 0 to 255, using bitwise and with 255 to get the result.

For this program, I multiplied the length of the program (122 bytes) times two, minus one for the positive case, times 256 and added (256 - 97), 97 being the ASCII value of 'a'. This gives 62367.

The loop then generates a sequence of values starting at -62367 and counting upwards by 256 each iteration. Each value in sequence when processed by chr produces another 'a'. When the variable A becomes positive, the program exits and prints 244 'a's.

With the fixed line length, golfing this down would require removing one whole instruction, which I don't believe is possible. But I'd be happy to be proven wrong!

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

Triangular, 10 bytes

F\(?)1/%-<

Try it online!

Prints from 14 to 0 without any spaces.
Triangular executes as if written in the shape of a triangle, drawn like this:

  1
 2 3
4 5 6

And so on. The program executes starting from 1, and has a Southeast direction (I.e., the above would run as 1, 3, 6). This explanation is for its actual execution order, which is why it doesn't visually look the same as the submission.

Ungolfed/Directional

   F
  \ (
 ? ) 1
/ % - <

-------------------------------------------------------------------

F              - Push 15
 (             - Set a point to jump back to
  1<-          - Push 1, change directions, subtract ToS from ToS-1
     %/        - Print ToS as an integer
       ?\)     - If ToS!= 0, jump back to the point set previously
\$\endgroup\$
1
\$\begingroup\$

Aheui (esotope), 87 bytes

삭밦밢따밥다사바바바바바바우a
샥ㅇ뱟ㅇ탸ㅇ뺘소처희ㅇㅇ아멍a

Try it online!

output is 174 bytes of 0. Aheui program is written in Korean, so one character is 3 bytes, and question said measured in byte, so 174. Trailing a is for making program to proper bytes.

How does this work?

삭밦밢따밥다 : to stack , then put 58. (28 Korean characters. Aheui cannot put 1 to stack, so I'll subtract 2 instead of 1 when counting loop.)

사바바바바바바우 : to stack (Nothing), put 6 zeros, than move downside.

아멍 : print from current stack till nothing left. if nothing left, move to start of the line.

샥ㅇ뱟ㅇ탸ㅇ뺘소처희 : to stack , subtract 2, check if zero, halt if zero, to stack (Nothing) and move to 사바바바바바바우 again.

a : At first, I thought this code would work just fine, but something went wrong. I used online character counter, and I got 29, so I made code with that. But code was 85 bytes and output was 174 bytes. I found the reason of this error : newline character. So I added 2 bytes to my code, than everything works fine. Aheui don't evaluate non-Korean characters, so a is just blank.

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

Befunge-93, 25 - 25 = 0 bytes

&+:0\`3*+::%+"CG"*:*:.:*.

Try it online!

Uses no control flow instructions! This code is implicitly looped n amount of times.

To get the n as input once and not have it interfere with subsequent iterations, we use Befunge-93's feature of returning -1 for input if the input stream is empty. At the start of each iteration, the top of the stack is the loop counter. It starts off at 0 (the default value on the stack). &+ gets a value from input and adds it to the counter. Conveniently, this sets the counter to the received input on the first iteration, and subtracts 1 on every subsequent iteration, creating a for (i = input();; i--) loop. :0\`3*+ computes (counter < 0) * 3 and adds it to the counter. This has the effect of adding 3 if the counter is negative (which happens if there was no input and we want to set n to -1+3=2), and otherwise adding 0 (if the input was positive or this is not the first iteration).

::%+ simply calculates counter % counter and discards the result, so as to halt when the counter reaches 0.

At the end, we output two large numbers by repeatedly squaring the product of two ASCII characters. Note that after each outputted number there is a trailing space.

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

Python 3.4, 14 13 bytes

print("a"*26)
\$\endgroup\$
  • \$\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\$
  • \$\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\$ – clap 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\$
  • \$\begingroup\$ How does this work? \$\endgroup\$ – LegionMammal978 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\$ – Lucas Trzesniewski 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
\$\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\$
  • \$\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\$ – Jonathan Leech-Pepin Oct 7 '15 at 15:11
  • \$\begingroup\$ @JonathanLeech-Pepin No - that won't work, either, for the same reason. See my corrected answer \$\endgroup\$ – AdmBorkBork 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\$ – Jonathan Leech-Pepin Oct 7 '15 at 15:26
  • \$\begingroup\$ @JonathanLeech-Pepin Let's continue this discussion in chat \$\endgroup\$ – AdmBorkBork Oct 7 '15 at 16:21
  • \$\begingroup\$ Also, if given no input, it should default to 2. \$\endgroup\$ – LegionMammal978 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\$
  • \$\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\$ – Toby Speight 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\$
  • \$\begingroup\$ @ThomasKwa: fixed it by providing a different solution. \$\endgroup\$ – Thomas Weller Oct 7 '15 at 20:50
0
\$\begingroup\$

APL, -8 bytes

'*'⍴⍨17×{0::2⋄⎕}⍬

Explanation:

  • {0::2⋄⎕}⍬: Try to read a number from the keyboard. If the user entered a valid number, return it; if not, return 2.
  • 17×: multiply it by 17 (the length of the code)
  • '*'⍴⍨: output that many asterisks.
\$\endgroup\$
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\$
  • \$\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\$
  • \$\begingroup\$ I thought extra whitespaces are not allowed? \$\endgroup\$ – Leaky Nun Mar 30 '16 at 9:59

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.