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

300 Answers 300

1
2
3 4 5
10
5
\$\begingroup\$

TI-BASIC, 1 byte

0

Output:

0    ;there is a newline; counts as char

Thanks to Thomas Kwa for his spectacular observation. The i/o looks as thus:

0
               0   ;right-aligned, but newline is part of output.
\$\endgroup\$
5
  • \$\begingroup\$ I think the newline counts as part of the output. \$\endgroup\$
    – lirtosiast
    Oct 4, 2015 at 17:53
  • \$\begingroup\$ @ThomasKwa What newline? You mean the "enter" key? \$\endgroup\$ Oct 4, 2015 at 18:18
  • \$\begingroup\$ No, the newline printed automatically after every program is executed. \$\endgroup\$
    – lirtosiast
    Oct 4, 2015 at 18:32
  • \$\begingroup\$ Oh. So change it to ᴇ3? \$\endgroup\$ Oct 4, 2015 at 18:36
  • 1
    \$\begingroup\$ Yes, but it can just be 0 as I commented on the other TI-BASIC answer by Deusovi. \$\endgroup\$
    – lirtosiast
    Oct 4, 2015 at 18:39
5
\$\begingroup\$

Python 2.7, 26 24 - 25 = -1 byte

def s(c=2):print'A'*24*c

24 characters long, prints twice its length on no input:

>>> s()
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

prints n*length for any other input:

>>> s(1)
AAAAAAAAAAAAAAAAAAAAAAAA
>>> s(3)
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
\$\endgroup\$
5
\$\begingroup\$

Shakespeare Programming Language, 216 192 191 bytes

Twice the source.Ajax,.Puck,.Act I:.Scene I:.[Exeunt][Enter Ajax and Puck]Ajax:Open heart!You big big big big big big big cat!Puck:You is the sum ofyou a cat!Be you worse I?If solet us Act I!

Try it online!

Prints a 0 followed by 128 128s.

\$\endgroup\$
4
\$\begingroup\$

Ruby, 24 - 25 = -1

$><<?x*24*(gets||2).to_i
\$\endgroup\$
4
\$\begingroup\$

Self-modifying Brainfuck, 31 - 25 = 6 bytes

Checking for no input is a hassle...

>,>+<[>-]>[<++>->]<<[<<[.<]>>-]

Explanation:

See the If(x==0) algorithm I used (the one by Ben-Arba).

>,                      Take a byte of input x
>+<[>-]>[<++>->]<<      If x == 0 (no input), x++ (add 2 :D)
[<<[.<]>>-]             Print the program's source code in reverse x times

Without the bonus (10 bytes):

<[.<]>[.>]

Wishful thinking:

If we didn't have to default the input to two (13 - 25 = -12 bytes):

>,[<<[.<]>>-]
\$\endgroup\$
4
\$\begingroup\$

Bubblegum, 1 byte

Ä

prints

!#

Test run

$ echo -en '\xc4' > double.bg
$ bubblegum double.bg 
!#
\$\endgroup\$
6
  • \$\begingroup\$ That's two or three bytes, one character (depends on encoding). Do bytes == characters here? \$\endgroup\$
    – Nateowami
    Oct 5, 2015 at 10:23
  • \$\begingroup\$ I/O is raw in Bubblegum. It only knows bytes, not characters. \$\endgroup\$
    – Dennis
    Oct 5, 2015 at 13:33
  • 1
    \$\begingroup\$ Yeah, that's what I was thinking, but... how is Ä one byte in any sense? After all, if input is raw, that's two bytes, that just happen to be one character. Am I missing something? How can Ä possibly be "1 byte"? \$\endgroup\$
    – Nateowami
    Oct 6, 2015 at 9:12
  • 2
    \$\begingroup\$ @Nateowami in ISO-8859-1, for example, Ä is a single byte, 0xC4. \$\endgroup\$
    – primo
    Oct 6, 2015 at 11:34
  • \$\begingroup\$ @primo Thanks, I wouldn't have guessed. Perhaps the encoding should be specified though, because using the reference implementation I get -M?). Likely the encoding got changed when the post was submitted (or else when I used echo Ä > file.txt and gedit). \$\endgroup\$
    – Nateowami
    Oct 6, 2015 at 11:57
4
\$\begingroup\$

Python, 15 bytes

print 'aaaaa'*6

Prints:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Which is 30 bytes.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ There are already two shorter Python 2 answers. \$\endgroup\$
    – lirtosiast
    Oct 27, 2015 at 14:50
  • 2
    \$\begingroup\$ @ThomasKwa well I'm sorry I didn't read through all 110 answers </sarcasm> \$\endgroup\$
    – TheDoctor
    Oct 27, 2015 at 14:52
  • 6
    \$\begingroup\$ There's a stack snippet at the top. All you need to do is click two buttons and scroll down to Python. Both of those answers were on the first page anyway. \$\endgroup\$
    – lirtosiast
    Oct 27, 2015 at 14:58
  • \$\begingroup\$ You could use print'a'*11 to save 4 bytes. \$\endgroup\$ Dec 17, 2015 at 16:00
  • 1
    \$\begingroup\$ @ASCIIThenANSI print'a'*22. The output needs to be twice the length of your code. \$\endgroup\$ Sep 22, 2016 at 14:27
4
\$\begingroup\$

Java 8, 82 Bytes

interface A{static void main(String[]s){for(A a:new A[164])System.out.println();}}

Prints out 164 empty lines.

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

C, 36 bytes

main(a){for(a=4;a--;)puts(puts);}//!

Really hacky stuff here. The implementation of puts on my machine (gcc 6.3) has 16 bytes before it hits a null, and adds a newline and SOH (18 bytes total). Run four times, and it's 72 (or 0x48) chars. I padded mine with a 3-char comment to fit that. Most of the chars are unreadable, so here's a hexdump of the output.

0000000 5541 5441 8949 55fc 4853 ec83 e808 76ae
0000010 0a01 5541 5441 8949 55fc 4853 ec83 e808
0000020 76ae 0a01 5541 5441 8949 55fc 4853 ec83
0000030 e808 76ae 0a01 5541 5441 8949 55fc 4853
0000040 ec83 e808 76ae 0a01
0000048
\$\endgroup\$
4
\$\begingroup\$

W, -22 bytes

The program is 3 bytes long and qualifies for the -25 byte bonus. (Okay. One-digit problem fixed!)

 0M

Explanation

   % Filler space
 M % Map: (implicitly) generate a list from 1 to the input
   % There is an implicit 0, so the 0-input
   % will produce the output [0, 1], which is
   % 6 bytes by default.
 M % Map every item in that list ...
0  % .. with the numeric constant 0
\$\endgroup\$
4
\$\begingroup\$

Vim, 26 25 - 25 = 0 bytes

-1 thanks to Aaron Miller

:s/^$/2
C<c-r>=<c-r>"*26
<esc>|D@"ix<esc>

Try it online!

Explained:

:s/^$/2<cr>           Substitute blank line with 2. This is the case when no input is given.
C                     Cut the input line and enter insert mode
 <c-r>=               Enter expression mode
       <c-r>"         Paste input
             *26      Multiply by code length
                <cr>  Evaluate
<esc>                 Return to normal mode (from insert mode)
     |                Move to the beginning
      D               Delete the line (which is the number of characters to output)
       @"             Paste the deleted line as the count argument to `i'
         ix           Insert `x'
           <esc>      Exit insert mode and repeat that many times
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think ignoring the bonus here would result in a shorter answer. Nice answer! \$\endgroup\$
    – Razetime
    Apr 27, 2021 at 5:26
  • 1
    \$\begingroup\$ 25 bytes - score 0 \$\endgroup\$ Apr 28, 2021 at 4:51
4
\$\begingroup\$

Hexagony, 3 bytes

?"&}>'􏑇!_!!}(\\2"^$\<_!\@

Try it online! Note: For some reason, the special Unicode character my code uses (􏑇, 0x10f447) seems to break TIO's link generator. So to make a linkable version, I replaced the character with X. Unfortunately, to run the code properly you'll have to copy and paste the character into the code in place of the X. Sorry about that.

Expanded:

    ? " & }
   > ' 􏑇 ! _
  ! ! } ( \ \
 2 " ^ $ \ < _
  ! \ @ . . .
   . . . . .
    . . . .

Whoops, thought I had a -3 but looked back over the problem and realized I missed that n defaults to 2 for an empty input. So here's 28 bytes, qualifies for 25 byte bonus. Works for values of n > 0, and defaults to n = 2 for empty input.

Explanation:

The first bit of code thats run is ?"&}2"^. ? reads n from input. Then "&}2" populates the cell to the right of n with a copy of itself, and the cell to the left with 2. This sets up for ^, which copies the value to the left of the current cell if the current cell is non-positive or empty, or the value to the right if it is positive. So if n does not exist or is non positive it is replaced with 2, otherwise it keeps its current value. After that, its just a matter of running through a simple for loop which decrements n until it reaches 0, each time printing the Unicode character 0x10f447 4 times using !. ! prints the decimal representation of a character, and 0x10f447 is 7 digits long, so in total 28 bytes are printed for each decrement it takes n to reach 0. The Unicode character is arbitrary, any with 7 digits in decimal would work (there are no 8 decimal digit characters.)

Edit: 5 byte bonus answer (doesn't qualify for answer bonus):

!<gg@

4 byte bonus answer, but it doesn't terminate:

!<)0
\$\endgroup\$
1
  • \$\begingroup\$ Hm can't seem to get the TIO link working, not sure whats up with that \$\endgroup\$
    – je je
    Apr 27, 2021 at 2:28
3
\$\begingroup\$

Mouse, 21 bytes

1I:(I.43<^9!1I.+I:)$

Ungolfed:

1 I:                  ~ Begin a loop index at 1
( I. 43 < ^           ~ While I < 43...
  9 !                 ~ Print 9 to STDOUT
  1 I. + I:           ~ Increment I
)$
\$\endgroup\$
2
  • \$\begingroup\$ I didn't know others knew Mouse! you csn shave bytes by not initialisingI, because its value will start at zero, and making it 42 instead. \$\endgroup\$
    – cat
    Dec 16, 2015 at 12:17
  • \$\begingroup\$ eg. (i.31<^9!i.1+i:) is 16 bytes \$\endgroup\$
    – cat
    Dec 16, 2015 at 13:34
3
\$\begingroup\$

q, 10 3 bytes

3#0

Outputs 6 bytes: "0 0 0\n".

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If I understand the challenge correctly, an 8-byte long program should produce 16 bytes of output... \$\endgroup\$ Oct 3, 2015 at 5:46
  • \$\begingroup\$ Right. I should have read past the title. I've updated my answer. \$\endgroup\$ Oct 3, 2015 at 6:19
3
\$\begingroup\$

JavaScript (ES6), 24 30 - 25 = 5 bytes

alert('s'.repeat(30*prompt()))
\$\endgroup\$
5
  • \$\begingroup\$ The question requires a full program. Your code will only work inside a REPL environment. \$\endgroup\$
    – Dennis
    Oct 4, 2015 at 13:32
  • \$\begingroup\$ @Dennis, there is no other way for JavaScript to receive input, and using prompt is standard practice in other golfing challenges where input is required. \$\endgroup\$ Oct 4, 2015 at 14:19
  • \$\begingroup\$ @PatrickRoberts If you use prompt to input, then you should use something like alert to output. \$\endgroup\$
    – Doorknob
    Oct 4, 2015 at 14:27
  • \$\begingroup\$ prompt isn't the issue. This will produce no output outside a REPL environment. \$\endgroup\$
    – Dennis
    Oct 4, 2015 at 14:59
  • \$\begingroup\$ I updated the answer to alert the value, also removing the unnecessary unary plus operator since the multiplication will coerce the value to a number. \$\endgroup\$ Oct 4, 2015 at 16:22
3
\$\begingroup\$

C, 23 (without bonus)

main(){printf("%46d");}

Outputs an uninitialized value, padded by spaces to 46 bytes. Trying to do it with a bonus, I arrived to a tie. I don't know whether it's unfortunate or cool.

C, 23 (with bonus)

main(x){printf("%*d",(~scanf("%d",&x)?x:2)*48);}

The code has 48 bytes. I use bit-complement ~ to check whether scanf returned -1.

\$\endgroup\$
3
\$\begingroup\$

Python 2, 11 bytes

print 9**21

displays 109418989131512359209\n (22 chars)

\$\endgroup\$
3
\$\begingroup\$

Funciton, 78 bytes

Not very advanced. Just output 156 As. Of course you can change 65 to any two-digit ASCII code. If non-printable characters are allowed as well, you could shorten it by 6 bytes by outputting character #1 144 times.

╔═══╗┌─╖╔══╗
║156╟┤…╟╢65║
╚═══╝╘╤╝╚══╝
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You could use the TAB character, 9. \$\endgroup\$
    – Titus
    Jan 27, 2017 at 6:36
3
\$\begingroup\$

Vitsy, 14 11 - 25 = -14 Bytes

Note: This language was made after this question was asked, but it was not created for this task.

2a{b*\[DO];

I'm pretty sure this can be golfed down a little more, but here you go:

2a{b*\[DO];
2              Push 2 to the stack as the backup value - if input is pushed, then it will already exist in the stack.
 a             Push "\n" (the literal) to the stack as an integer - this will be our output.
  {            Rotate the stack to the left
   b*          Multiply the top value (used to be the back-most (2 or input) value) by 11.
     \[..]     Repeat as many times as the top item of the stack specifies for all instructions within []
       DO      Duplicate the top value, then output it.
          ;    End execution.
\$\endgroup\$
3
\$\begingroup\$

Common Lisp REPL, 9

(write -)

- is a variable that holds the currently evaluating expression in the REPL, while write returns whatever it writes. So it writes (write -) then returns "(write -)" which is printed by the REPL without the quotes. (If this was done in an REL instead of an REPL, then it'd be a quine instead.)

\$\endgroup\$
3
\$\begingroup\$

J, 6 5 3 2 bytes (bonus: -11 bytes) (try it online)

Program:

%4

Output:

0.25

Explanation: The reciprocal of 4.

Bonus:

10,1$~_1+7*]/2

Testcases:

10,1$~_1+7*]/2    :10 1 1 1 1 1 1 1 1 1 1 1 1 1
10,1$~_1+7*]/2 2  :10 1 1 1 1 1 1 1 1 1 1 1 1 1
10,1$~_1+7*]/2 3  :10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Explanation:

10,               NB. prepend 10 to
   1$~            NB. the "~" reverses the arguments.
                  NB.    e.g. 1 $~ 5 becomes 5 $ 1.
                  NB.    5 $ 1 means create an array of size 5,
                  NB.    using the number 1. The number is
                  NB.    recycled because there is not enough number.
                  NB.    For example, 5$1 2 3 would produce 1 2 3 1 2.
      _1+         NB. add negative one to
         7*       NB. seven multiplied by
           ]/2    NB. if the input is 5, then this part
                  NB.    becomes 2]5, which evaluates to 5.
                  NB.    if there is no input, then this
                  NB.    part is only 2.

3-byte attempt:

7^7

Output:

823543

Explanation: 7 raised to the power 7.

Notes: Looks like I am not the first one to discover this.


5-byte attempt:

Program:

*:i.5

Output:

0 1 4 9 16

Explanation: *: means square. i.5 means generate a list from 0 to 4


6-byte attempt:

Program:

10,5$5

Output:

10 5 5 5 5 5

Explanation:

5$5 means create an array of size 5 (on the left of $), using the number 5 (on the right of $). The number is recycled because there is not enough number.

For example, 5$1 2 3 would produce 1 2 3 1 2.

\$\endgroup\$
1
  • \$\begingroup\$ Looks like I am not the first one to discover <code>7^7</code>... never mind, I still discovered it myself. \$\endgroup\$
    – Leaky Nun
    Mar 30, 2016 at 2:15
3
\$\begingroup\$

Desmos, 3 bytes

9^6

Equals 531441

\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure desmos is considered a language, though it is pretty awesome. \$\endgroup\$
    – Daniel M.
    Jul 3, 2016 at 22:54
  • 1
    \$\begingroup\$ Desmos is technically a programming language since you can program things with it. \$\endgroup\$ Jul 4, 2016 at 1:22
  • \$\begingroup\$ Desmos satisfies our requirements. \$\endgroup\$
    – user45941
    Jul 4, 2016 at 5:21
3
\$\begingroup\$

[Non-Competing] C, 16

Code:

//score=16 bytes

Outputs: error: ld returned 1 exit status (32 bytes)

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

05AB1E, 6 - 25 = -19 bytes (noncompeting)

VžOY×?

Try it online!

VžMY×?  Argument n
V       Assign n to Y, if n is empty Y defaults to 2
 žO     Push 'aeiouy' to stack (has same length as program)
   Y×   Repeat the string Y times
     ?  Print top of stack without newline
\$\endgroup\$
3
  • \$\begingroup\$ You have been outgolfed. \$\endgroup\$
    – Oliver Ni
    Jun 3, 2017 at 16:05
  • \$\begingroup\$ @OliverNi Does the input default to 2 if not given? \$\endgroup\$
    – kalsowerus
    Jun 3, 2017 at 16:09
  • \$\begingroup\$ Oh. I'll fix that. \$\endgroup\$
    – Oliver Ni
    Jun 3, 2017 at 16:18
3
\$\begingroup\$

Bash, 5 bytes

seq 5

Output (with a newline char on the end of each gives 10 bytes)...

1
2
3
4
5

\$\endgroup\$
3
\$\begingroup\$

Whitespace, 38 36 bytes

SSTTTSTTNNSSNSNSTNSTSSSTNTSSSSNSNTTN

Try it online!

Prints "-27-26-25-24-23-22-21-20-19-18-17-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1". Whitespace doesn't have optional input so I can't go for the bonus.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Could you print -1 to shorten it? \$\endgroup\$
    – Jo King
    May 21, 2018 at 22:50
  • \$\begingroup\$ @JoKing managed to save off 2 bytes with an idea I got from your suggestion. \$\endgroup\$ May 21, 2018 at 23:02
3
\$\begingroup\$

PowerShell, 3 bytes

1e4

Try it online!

PowerShell, 1 byte

Thanks to @mazzy for pointing this one out!

1

Try it online!

Both programs' outputs includes a trailing newline!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ You could to try 1. Output includes a trailing newline! \$\endgroup\$
    – mazzy
    Dec 9, 2018 at 7:03
3
\$\begingroup\$

Perl 6, 17 - 25 = -8 points

print e x(get||2)

Try it online!

Prints the builtin constant e (\$2.718281828459045\$) either input or 2 times. Luckily, the precision of the constant is 17 bytes long, exactly the same as my code length.

Explanation:

print              # Print without newline
      e            # The constant e (2.718281828459045)
        x(      )  # String multiplied by
          get      # The input
             ||2   # Or two if the input does not exist
\$\endgroup\$
3
\$\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\$
3
\$\begingroup\$

Deadfish~, 5 bytes

You expected a worthwhile submission, but it was ME:

{dio}

Try it online!

Prints the number "1" ten times.

\$\endgroup\$
1
2
3 4 5
10

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.