Create output twice the length of the code

86

14

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>

Daniel M.

Posted 9 years ago

Reputation: 3 737

1For the bonus, does the output have to be exactly n * program length bytes, or is that a minimum? – xnor – 9 years ago

2It has to be exact – Daniel M. – 9 years ago

3Looks like the code snippet has to be modified to handle negative scores. – El'endia Starman – 9 years ago

40A 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. – xnor – 9 years ago

4For "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. – xnor – 9 years ago

1

@El'endiaStarman I'm not really a javascript expert, so I used the leaderboard snippet. I think I found the regex that controls which number gets used, so I changed that to accept a dash. How long does it take for the snippets to update?

– Daniel M. – 9 years ago

@xnor If the program waits for user input, then it is an empty string. For "no input", I was thinking along the lines of command-line args. – Daniel M. – 9 years ago

@DanielM. So you mean that if we accept input, we have to account for empty input and in that case use 2? – Alex A. – 9 years ago

@AlexA. That is correct. On another note, I found the regex that it actually uses, and when that was changed, it updated immediately. – Daniel M. – 9 years ago

@DanielM.: Excellent! :) – El'endia Starman – 9 years ago

Since there are so many answers, I'm just changing it to "shortest answer in each language" instead of "shortest answer overall". – Daniel M. – 9 years ago

ASCII or printable ASCII? (Dunno if that would change anything, but worth clarifying.) – jpmc26 – 9 years ago

Any 8-byte ASCII (for 2 reasons).

  1. I just chose ASCII as it is a standard format, and it's clearer to say to "write ASCII" than "write bytes". Additionally, it avoids the 16/32 bit nonsense of unicode (seriously, 8 extra bits?).

  2. There are already submissions with unprintable characters that I don't want to invalidate.

  3. < – Daniel M. – 9 years ago

Should the "Done\n" in this answer count as output?

– lirtosiast – 9 years ago

Can someone fix the snippet? Hyperlinked language names are sorted incorrectly. – mbomb007 – 9 years ago

at least 1 byte Why. – ev3commander – 9 years ago

@BlockCoder1392 in some languages, an empty program is a Quine, but that's no fun – Daniel M. – 9 years ago

No, I was like "WHY MUST YOU DO THIS" because anything*empty=empty, so you could get a really easy -25 polyglot. – ev3commander – 9 years ago

Does CRLF count as one character? – user8397947 – 8 years ago

@dorukayhan I'd count bytes for this – Daniel M. – 8 years ago

Would "\n" count as two characters? – Stan Strum – 7 years ago

Why [tag:quine]? – Qwertiy – 7 years ago

1It seems there's some disagreement about what a "complete program" is here. Some answers are just functions; others are more what I would think of as complete programs that take input from stdin or the command line. Can you clarify? – dfeuer – 6 years ago

Answers

139

HQ9+, 2 bytes

QQ

outputs

QQQQ

I think it is not forbidden here.

randomra

Posted 9 years ago

Reputation: 19 909

14It may not be forbidden, but it's not very inter... wait, how did it get eight upvotes? – John Dvorak – 9 years ago

58@JanDvorak Much as I dislike HQ9+, this to me is a creative use. This usage most likely wasn't envisioned when HQ9+ was created, which is more than can be said of most other Hq9+ programs. +1 from me. – Digital Trauma – 9 years ago

13I didn’t even know that Q prints “the program’s source code”. I thought it just printed a Q. Well done for spotting the crucial difference! – Timwi – 9 years ago

Sadly, HQ9+ isn't considered a programming language. – LegionMammal978 – 9 years ago

7@LegionMammal978 Technically this is a constant output challenge, which means non-programming languages are allowed. – a spaghetto – 9 years ago

3This has 120 votes. 1,200 rep for typing QQ into an interpreter. – Stan Strum – 7 years ago

95

Shakespeare, 768

Yeah, Shakespeare's not much of a golfing language. Outputs 1,536 spaces.

Rosencrantz and Guildenstern: A Series of Tedious Events.

Rosencrantz, a count of extraordinary determination.
Guildenstern, a spacy character.

Act I: The Long Conversation

Scene I: A Tortured Friendship

[Enter Rosencrantz and Guildenstern]

Rosencrantz:
 You are a gentle, noble, valiant, loyal, loving companion.

Guildenstern:
 You are nothing!

Scene II: Asking the Hard Questions

Rosencrantz:
 Speak your mind.

Guildenstern:
 You are as fair as the sum of yourself and a daisy. Are you as
 daring as the sum of a big, bold, fiery, feisty, rough, rowdy,
 ham-fisted, hawk-eyed, broad-shouldered, bright-eyed lad and a
 large, yellow, vicious, hairy, wild, scary, long-tailed,
 sharp-clawed, small-eared lion?

Rosencrantz:
 If not, let us return to scene II.

Edit: 256

Okay, I'll actually golf it. Note that the above does not compile in any existing Shakespeare implementation because I wrote it painstakingly by hand (but am prepared to defend its correctness.)

The below translates to C with one warning in spl-1.2.1, and outputs 512 spaces:

Ummm.Ajax,1.Puck,2.Act I:I.Scene I:A.[Enter Ajax and Puck]Ajax:You old old old old old cow.Puck:You are zero!Scene II:B.Ajax:Speak thy mind.Puck:You are the sum of you and a red cat.Are you as big as the square of me?Ajax:If not, let us return to scene II.

Luke

Posted 9 years ago

Reputation: 5 091

15I'll +1 if you actually golf this. – lirtosiast – 9 years ago

1What manner of whitchcraft is this? I didn't even know such thing existed... – Malavos – 9 years ago

@Malavos don't you mean which manner of whitchcraft? – cat – 9 years ago

1@sysreq probably. shrugs My english is bad and I feel bad. Not really, because it's not my native language. Sorry about that. – Malavos – 9 years ago

10woah, you golfed it. Holy havens. – Malavos – 9 years ago

2@Malavos I was just joking about the way you misspelled witchcraft, sorry -- both what and which are probably ok – cat – 9 years ago

2No, I ask for your forgiviness if I sounded offensive or defensive. I was just making a reference to Futurama! :)

On a serious note, I'm still surprised by this answer. We need more of those on the site. – Malavos – 9 years ago

1I think you can use “you is”. – ev3commander – 9 years ago

69

Recall, 17 bytes

................!

16 NOOPs. Then the debugger ! is invoked and dumps the memory to the console. The memory is empty, but the header is 34 bytes long:

-- STATE DUMP --
----------------

Try it here.

mınxomaτ

Posted 9 years ago

Reputation: 7 398

13This is one of the cooler answers IMO. – cat – 9 years ago

67

Mathematica REPL, 1 byte

#

Prints #1.

alephalpha

Posted 9 years ago

Reputation: 23 988

14The question says to "write a complete program"; this is just a REPL snippet. – LegionMammal978 – 9 years ago

60

CJam, -17 bytes

r2e|i8,*

The source code is 8 bytes long and qualifies for the -25 bytes bonus.

Try it online in the CJam interpreter.

How it works

r         e# Read a token from STDIN.
 2        e# Push 2.
  e|      e# Logical OR; keep the token if it's not empty, 2 otherwise.
    i     e# Cast to integer.
     8,   e# Push [0 1 2 3 4 5 6 7].
       *  e# Repeat the array the corresponding number of times.

Dennis

Posted 9 years ago

Reputation: 196 637

4Crap. Well done. – The_Basset_Hound – 9 years ago

1How is it negative bytes? – Nick T – 9 years ago

3@NickT 8 bytes (source code) - 25 bytes (bonus). – Dennis – 9 years ago

16You can save several million copies of it if you're running out of disk space. – Robert Fraser – 9 years ago

No, I think metadata would make it positive – CalculatorFeline – 9 years ago

Cjam is reeeeeally nice for golfing! – Chromium – 7 years ago

48

Python 2.6, 10

print`-.1`

Prints -0.10000000000000001, which is 20 chars.

Note that the string repr shows more precision. print-.1 just gives -.1, and print.1/3 gives 0.0333333333333 for only 13 digits of accuracy.

xnor

Posted 9 years ago

Reputation: 115 687

5

This no longer works in Python 2.7 or 3.1.

– Anders Kaseorg – 9 years ago

@AndersKaseorg So repl.it is wrong, then?

– mbomb007 – 9 years ago

2

@mbomb007 Apparently. GitHub suggests that’s hardly the only thing it’s wrong about. Ideone agrees with CPython.

– Anders Kaseorg – 9 years ago

Same comment as for your other answer: doesn't this print a trailing newline, giving 21 bytes of output? – Martin Ender – 9 years ago

@MartinBüttner Here, changing it to \print`+.1` would compensate for the trailing newline. – xnor – 9 years ago

1You mean print\+.1``? – mbomb007 – 8 years ago

@wizzwizz4 I can't figure out how to show you in a comment. Try looking here: https://meta.stackexchange.com/a/70679/285610 I think it was triple backticks, the code, then a space, then triple backticks, but I can't be certain. Sometimes escaping with backslashes is necessary

– mbomb007 – 5 years ago

46

Seed, 10 bytes

4 56111240

This compiles to the Befunge program (found by brute force)

9k.@

which produces the following 20 bytes when run (tested in CCBI, note the trailing space):

0 0 0 0 0 0 0 0 0 0 

Being unfamiliar with Befunge 98, I had to double check the spec a few times for this one:

  • k seems pretty broken to me, executing one more time than intended due to the IP moving into the repeated instruction
  • Befunge 98's stacks have infinite zeroes at the bottom
  • . outputs as a number, followed by a space

Sp3000

Posted 9 years ago

Reputation: 58 729

18.... I....just....can't. – Daniel M. – 9 years ago

44

R, 3 2 bytes

Code

!0           # NOT FALSE

Outputs

TRUE

Wow, finally R, finally.

It seems that {} work too, it outputs NULL

Bonus 33 16 bytes:

Code

rep(1,number*16)

Outputs

# if number is not defined
> rep(1,number*16)                     
> Error: object 'number' not found     # output is 32 (or 2*16) bytes long error

# if number is defined
> number = 3                            
> rep(1,number*16)                     # output is 16*number bytes long
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Mutador

Posted 9 years ago

Reputation: 1 361

2I hope using the name "number" for the variable is not equivalent to " adding unnecessary whitespace to the source code" – Mutador – 9 years ago

26

Matlab, 7 5 bytes

2 bytes fewer thanks to @flawr!

123;3

Output:

enter image description here

The output contains newline ans = newline newline 3 newline, so 10 bytes.

Luis Mendo

Posted 9 years ago

Reputation: 87 464

1Let's hope nobody has format compact as default :) – Sanchises – 9 years ago

2@sanchises :-) Yes, that depends on how Matlab's preferences have been set. But format loose is the default preference – Luis Mendo – 9 years ago

2How about 123;4? Is three bytes shorter=) – flawr – 9 years ago

@flawr Good idea! Post it yourself! – Luis Mendo – 9 years ago

Nope, way too much inspired by your answer=) – flawr – 9 years ago

@flawr Edited then! – Luis Mendo – 9 years ago

26

JavaScript, 2 bytes!

Even shorter than the 3 bytes solution:

!0

Returns true after running.

Unihedron

Posted 9 years ago

Reputation: 1 115

2You should note that this only works in a REPL environment – Cyoce – 9 years ago

21

Python 2, 11

print`id`*1

Print the string representation of the built-in id, which is 22 chars:

<built-in function id>

The *1 is to get the code to 11 chars. You could also do print id;00.

More boring alternative 11's are:

print'1'*22
print 9**21

xnor

Posted 9 years ago

Reputation: 115 687

I've been playing around with complex numbers, but unfortunately print.8/-9j is one char short – Sp3000 – 9 years ago

Don't these print a trailing newline, bringing the output's byte count to 23? – Martin Ender – 9 years ago

1@MartinBüttner That rule was edited in later, but changing it to print id,;1 suffices to suppress the trailing newline. It doesn't add a trailing space either. – xnor – 9 years ago

@xnor print 9**21 doesn't work. It's 21 characters. print 9**23 works though – Koishore Roy – 8 years ago

18

dc, 10 - 25 = -15

2?A*Ar^1-n

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.

Digital Trauma

Posted 9 years ago

Reputation: 64 644

dang, that is so clever. And lucky with the code length there :) But maybe you should add a small explanation for the uninitiated. And I think newline counts, so you should probably use n instead of p. – daniero – 9 years ago

17

TI-Basic, 3 bytes

1ᴇ5

Prints 100000.

Deusovi

Posted 9 years ago

Reputation: 1 420

Actually, I think the newline would count, so you can just do 0 for 1 byte. – lirtosiast – 9 years ago

2How about ᴇ3? And @lirtosiast, since TI-Basic doesn't have newlines I'm skeptical about that. – Jakob – 7 years ago

16

Brainfuck, 14 bytes

+++++++[....-]

This is a little mathematical exercise. Let's denote the number of + characters in the code by a, and the number of . characters by b.

The code outputs a*b bytes, with values from a down to 1 (these are non-ASCII bytes, but it seems OK according to the spec). The code's length is a+b+3. So we have

a*b = 2 * (a+b+3)

Trying different values for a and b, we see that the minimum for a+b+3 is achieved for

a = 4       or       a = 7
b = 7                b = 4

anatolyg

Posted 9 years ago

Reputation: 10 719

A veteran brainfuck programmer will spot the +[[>....]-<<+] option. – orthoplex – 6 years ago

@orthoplex When I read your comment I immediately portmanteau'd brainfuck and programmer: brainfucker – Poke – 6 years ago

15

gs2, -18 bytes

CP437: W↕0!↨.2

Hex dump: 57 12 30 21 17 2e 32

W reads numbers from STDIN into a list. ↕0 appends a 2 to the list, and ! extracts the first element. Then ↨. (the list [0,1,2,3,4,5,6]) is repeated (2) this many times.

This is very similar to Dennis's CJam answer -- gs2 just combines r and i into one byte.

Note: I had to fix a bug in the gs2 implementation for this to work: previously, each program had a hidden newline appended to its output, which was entirely unintentional. It only surfaced after I tried to solve this program (the language was designed for anarchy golf, which ignores trailing newlines in all problems), and I only pushed a fix to master just now, so feel free to take this answer with a grain of salt.

Lynn

Posted 9 years ago

Reputation: 55 648

1First GS2 answer I've seen that doesn't have any card suit characters! – Cyoce – 9 years ago

14

Pyth, 10 9 - 25 = -16

-1 by Dennis

**N9?zvz2

Prints [input]*9 quote characters, or 2*9 if the input is empty.

isaacg has a shorter answer here

Pyth, 1 byte

T

Prints 10. It's a built in variable that initializes to 10.

lirtosiast

Posted 9 years ago

Reputation: 20 331

It would be useful if .x worked with errors. Is there a justification for why it doesn't? – lirtosiast – 9 years ago

2My best guess is that Q causes Pyth to eval the input before the actual code is executed. **N9.xvz2 works as expected, but it's not shorter than **N9?zvz2. – Dennis – 9 years ago

2Any trailing newline is included in the output's byte count. T outputs 10 and a newline. Use d, it's a space which gets a newline appended – Stan Strum – 7 years ago

14

Perl 5, 16 bytes - 25 = -9

$_ =$]x($_*2||4)

This is an oddball approach to the problem.

Run with the -p command line argument.

I saw a Perl answer below that used a special variable to print more text - and thus shorten their byte count. So I used a much more verbose special variable. It prints 8 characters with a 2 character variable name. Thus, with a byte count of 16 (padded with one whitespace character to make it 16), it prints 2 * $], where $] is the Perl version printed as 5.xxxxxx, dependent upon your Perl version. Without input it prints it four times, equaling 8*4 or 32, which is double the byte count of the code.

I love Perl.

Codefun64

Posted 9 years ago

Reputation: 297

I think this fails for empty input. Per the rules, if no input is provided, the multiple should default to 2. – Alex A. – 9 years ago

@AlexA. Damn, I missed that. New to code golf. Edit incoming, but my answer has a lot of characters now because I have no idea how to do this more creatively in perl :( – Codefun64 – 9 years ago

2Hey there, a few more tips that might help you here, by default in a program script, pop and shift work on @ARGV (in a sub they work on @_) so you could do something like $n=pop||2 to get the first code block down, and you have ;} at the end, which can almost always be just } to save another. Something that might help you save more chars is the string repetition operator x, consider print 1x20 or something along those lines... :) Hope that helps! – Dom Hastings – 9 years ago

@DomHastings Man, thanks! I got it down to 2 bytes total because of your help :) Thank you very much for your suggestions. – Codefun64 – 9 years ago

1I think you can shorten it to this print"n"x(21*pop||42). Run on the command line with perl -e'print"n"x(21*pop||42)' 3 | wc -c – hmatt1 – 9 years ago

@chilemagic Right you are! although no command line arguments are needed, you can run this straight from a .pl script file. That also saves some bytes, as one must count the bytes from special command line arguments if used. You've saved me 6 bytes however :) Thank you very much. – Codefun64 – 9 years ago

Updated the answer to use -p instead of taking command line arguments. – Codefun64 – 9 years ago

9

C, 27 25

main(){printf("%50f",0);}

Thanks @Titus for knocking off 2 bytes


And for my non-competing 16 byte solution in C, go here: https://codegolf.stackexchange.com/a/111330/16513

^I say non-competing because the error code could possibly depend on your compiler, Also note I'm using GCC in that solution. Also I'm not certain if it breaks rule 1 or not, I think it probably does so I went ahead and labeled it non-competing

Albert Renshaw

Posted 9 years ago

Reputation: 2 955

1I do not think that counts as a valid C program but main(){printf("%0.XXf",0);} works. – wefwefa3 – 9 years ago

But you have to #include <stdio.h>, right? – Zereges – 9 years ago

2

@Zereges No, C has the "implicit declaration" rule that usually lets you use stuff without the proper #include. The compiler will emit a warning, and it will sometimes crash, but it will usually work.

– anatolyg – 9 years ago

@ryvnf Thanks, good point! Got it in. :) – Albert Renshaw – 9 years ago

@anatolyg Thanks for the reference :D – Albert Renshaw – 9 years ago

@anatolyg From what you've posted, it seems, that it is undefined behaviour. So I would recommend adding at least one compiler, which handles this correctly as well as explanation, that this is UB. See this link.

– Zereges – 9 years ago

1

@AlbertRenshaw Also, I do not think it works here.

– Zereges – 9 years ago

1Note that 27*2 != 38. – mbomb007 – 9 years ago

1@Zereges. This code does not exhibit undefined behaviour. The "implicit declaration" and "implicit return type" features are deprecated in recent standards, but their usage is still permitted and results are well defined. There are circumstances in using such features causes undefined behaviour, but this code does not involve those. – Peter – 9 years ago

@Peter The undefined behavior here is not because of an implicit declaration - it's because of trying to extract double from a va_list which contains an int. – anatolyg – 9 years ago

Well that's easily fixed. Change the 6 to a 7 and add a . after the 0. – Peter – 9 years ago

1This compiles for me in Visual Studio Community 2013 using a C++ project and adding the above code to source.c with no other files, and runs from the Windows command prompt. As mbomb007 points out, 272!=38. However, 272=54, which can be achieved by changing the '%0.36' to '%0.52' with no change in code length. – MichaelS – 9 years ago

@MichaelS Ah sorry haha, they suggested I add "Main(){}" and I did and forgot to adjust that number as well to fit the new length, rookie mistake lol — fixed it now! – Albert Renshaw – 9 years ago

Can´t You use %50d? – Titus – 8 years ago

@Titus creates nonsense on my IDE, but said nonsense is indeed 50 bytes. Editing now, thanks – Albert Renshaw – 8 years ago

Couldn't you have less letters in title style? GRRRRRR... – sergiol – 8 years ago

9

Macaroni 0.0.2, 23 chars

print tobase pow 32 9 2

Prints 329 in binary, which happens to conveniently turn out to be 46 characters long (it's 1000000000000000000000000000000000000000000000), without a trailing newline.

Doorknob

Posted 9 years ago

Reputation: 68 138

9

JavaScript, 4 bytes

+1/0

Prints Infinity

I think this is the shortest possible JS solution without ES6 :P

Unihedron

Posted 9 years ago

Reputation: 1 115

What version of NodeJS do you have? This doesn't work with mine. – Dennis – 9 years ago

1This also works on Firefox console. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 9 years ago

1The trailing newline should be included in the output length. – lirtosiast – 9 years ago

Node.js v0.10.40 doesn't print anything at all because there's no print command. Do you have a different version of Node.js or does this only work in a shell that prints the evaluation of a line? (in which case I don't think this answer would be valid). – Nateowami – 9 years ago

4 bytes? Please make this actually like, the correct size. – Star OS – 9 years ago

You could do math ones like 1e5 without ES6 – Quill – 9 years ago

Im assuming that the file the code is stored in is main.js and the source is +1/0 — 4 bytes – Cyoce – 9 years ago

You should mark this as Node.js – ericw31415 – 9 years ago

What about !0?

– ETHproductions – 8 years ago

7

bash, 11 bytes

Here's a pleasingly ironic usage of a data compression tool :) ...

gzip -f<<<2

Here's a hex dump of the output (22 bytes)...

0000000: 1f 8b 08 00 e3 ce 32 59 00 03 33 e2 02 00 90 af  ......2Y..3.....
0000010: 7c 4c 02 00 00 00                                |L....

Wossname

Posted 9 years ago

Reputation: 221

This outputs 22 bytes of "extended ASCII" (eg. 8 bits per character). This seems to meet the OP's definition of ASCII if you read the comments on the Question post. – Wossname – 8 years ago

On TIO I got 16, but on my linux machine, I got 34

– Stan Strum – 7 years ago

@StanStrum, I don't know what TIO is, but that 34 under linux is odd. Perhaps you have gzip aliased to use different switches to normal? – Wossname – 7 years ago

I don't know if that's the case, but that does seem odd. I'll try it on some LiveCDs to see if I messed it up with one of my programs @Wossname – Stan Strum – 7 years ago

I think I originally used a stock Centos 7 install to create this answer. It worked at the time +shrug+. – Wossname – 7 years ago

On my fresh LiveCD, I got 16 – Stan Strum – 7 years ago

Beats me then. GIve it a downvote, since it's not universal. No worries. :) – Wossname – 7 years ago

1I'm not that guy, and I won't take advantage of my newly earned 129 rep tyvm. I'll see if I can make a version that works on my Linux installation – Stan Strum – 7 years ago

7

JavaScript ES6, 33 - 25 = 8

(a=2)=>Array(a*33).fill(0).join``

Try it online!

DankMemes

Posted 9 years ago

Reputation: 2 769

I can't seem to make this code run on console. Is it right? "Uncaught SyntaxError: Unexpected token =>" – Malavos – 9 years ago

@Malavos you need an es6 compliant browser such as the latest Firefox. Chrome doesn't support default args afaik – DankMemes – 9 years ago

I'm using UCBrowser, but that's right! It's based on chromium and gecko anyway. Tried it on nightly, got "000000000000000000000000000000000000000000000000000000000000000000". Nice! Could you explain your code for me? I'm a newbie. – Malavos – 9 years ago

2@Malavos The hardcoded 33 is actually the length of the code. It creates a new array with length 33*a where a is the input parameter defaulting to 2 as per the OP, fills it, and returns a joined string. – DankMemes – 9 years ago

2By creating your array with one extra element you can fill with the join Arrary(1+a*<length>) and join\0`` – Shaun H – 9 years ago

7

V, 2 Bytes

This outputs

ÿÿÿÿ

Try it online!

Explanation

This is a really hacky answer, and it works by abusing the internals of V. Essentially how it works is that ÿ is a command in V that signals the program is over, and any pending commands must complete. Otherwise, some implicit endings would not work, and the interpret would hang more often. This command is automatically sent several times at the end of the program, and most of the time has no effect on the output.

é is a command that inserts a single character. However, it does it by grabbing a raw byte, so it doesn't interpret ÿ as "end", it interprets it as "this is the character you need to insert." makes it insert this character 4 times instead of one.

James

Posted 9 years ago

Reputation: 54 537

6

CJam, -9

q_,{i}{;2}?G*'X*

Explanation

  • q_,

Reads the entire input and pushes it, then pushes the length.

  • {i}{;2}?

If the length of the input is over zero, convert it to an integer. Otherwise, pop the input and push 2.

  • G*

Pushes 16 (the program length), then multiplies it by 2 if there is no input, or by the input.

  • 'X*

Pushes X and multiplies it by the top of the stack.

The_Basset_Hound

Posted 9 years ago

Reputation: 1 566

@ThomasKwa Whoops. Updating in a sec. – The_Basset_Hound – 9 years ago

The comma is not necessary, however you can avoid the "if" altogether if you do a logical "or": q2e|i will give you the number you want – aditsu quit because SE is EVIL – 9 years ago

Also you could use S instead of 'X, the only issue is that the output will not be visible until you select it (well, if you run it offline and redirect to a file, it's not a problem) – aditsu quit because SE is EVIL – 9 years ago

Uh.. nevermind, I just saw Dennis's answer now :p – aditsu quit because SE is EVIL – 9 years ago

Even with the conditional, you can shorten this. You don't need to calculate the length, since an empty string is already falsey. You also don't need to pop the empty string off the stack, since it does not contribute to the output. Which also allows yo to avoid the braces for the else branch. I came up with this before I looked at any of the answers: r_{i}2?SB**. – Reto Koradi – 9 years ago

6

><>, 19 + 2 (-v flag) - 25 = -4 bytes

l?!2f4+*v
-1o;!?::<

test it here!

Thanks Cole and Sp3000

First checks the stack length, if it's 0 put 2 on the stack. Multiplies it by 21 (code length), then outputs the unicode representation of that number and decrements it by 1, loops until 0. (you'll have to inspect the output to see the characters, since the browser won't display them)

torcado

Posted 9 years ago

Reputation: 550

1Yeah, sorry to ruin your answer (but it is shorter than mine, if that makes you feel better). Edit: whoops hit enter too soon, your entry as it stands right now is not valid per the rule "You can assume that n will always be a positive integer. If no input is provided, n must default to 2." I also think it might print one too many characters (It goes from 14 to 0 which is 15 characters by my count, not 14). If I'm correct, l0=?2f6+*v as the first line and 1-::0=?;o> as the second should make it right. – cole – 9 years ago

Hm, not sure what you mean. It shouldn't print 0 in any case. Putting a 2 as the initial stack outputs (EDIT: stuff i can't paste) which, at least using this char counter, is 28 chars.

– torcado – 9 years ago

I understand what you're saying now. I interpreted "Your program can optionally take a number, n, as input" meaning that if the input would be 2. I'll edit the answer, thanks! (also i can save some by using a string instead of numbers) – torcado – 9 years ago

Happy to help, especially if it's ><>. – cole – 9 years ago

2?! is usually better than 0=? – Sp3000 – 9 years ago

@Sp3000 oh man i can't believe i didn't realize this. Edited, thanks! – torcado – 9 years ago

Out-golfed – Esolanging Fruit – 8 years ago

6

dc, 19 - 25 = -6

2?19*[1n1-d0<l]dslx

Takes a number (2 is pushed to the stack as backup) and multiplies it by 19. Prints a 1 (no newline) and decrements the number. Loops while the number is greater than 0.

daniero

Posted 9 years ago

Reputation: 17 193

6

C++, 80 bytes

#include<iostream>
int main(){int i=0;while(i<20){std::cout<<&i;i++;}return 0;}

note the newline character is two characters. (if you don't want it to be, change i<20 to i<=19 to get back to the same byte count.)

Sample output (will change every time)

0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C

same 8 character memory address 20 times.

Liam

Posted 9 years ago

Reputation: 3 035

Some golfing hints: a for loop is shorter than a while loop and lets you drop the braces, it's slightly cheaper to use cstdio and just printf a string, and you don't need to return anything. – Luke – 9 years ago

You can strip your approach to 63 bytes: #include<iostream> int main(){for(int i=10;--i;)std::cout<<&i;} But there is already a shorter answer with a slightly different approach. – movatica – 6 years ago

6

JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

(in case your browser won't allow for the snippet to run for security reasons, try this fiddle http://jsfiddle.net/thePivottt/c3v20c9g/ )

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
  <head>
    <title>Minimalist HTML5 page</title>
    <script>alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))</script>
  </head>
</html>

This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

  • Array(1+(+prompt()||2))

    • Array(INT) creates an Array of INT cells.

    • +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

    • +prompt()||2 returns the input if it is truthy, else it returns 2.

    • This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

  • .join(document.scripts[0].textContent)

    • The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

    • document.scripts[o] is the first <script> element of the document.

    • The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.

Domino

Posted 9 years ago

Reputation: 459

Note that if you use ES6's str.repeat and still output the code itself, it brings the score down to 26, but it's a bit too boring :P – Domino – 9 years ago

Erm, I don't know where that 26 came from, now I get 33. I should probably get some sleep. – Domino – 9 years ago

Note that some browser settings may prevent the use of prompt on a snippet. You might have to save it to run it. – Domino – 9 years ago

5

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.

Jo King

Posted 9 years ago

Reputation: 38 234

5

Julia, 42 bytes - 25 = 17

print("@"^42((r=readline())>""?int(r):2))

This reads a line from STDIN using readline(). If it's empty, i.e. no input has been provided, then n is defined to be the input converted to an integer. Otherwise n is 2. We then print 42​n @s to STDOUT.

Alex A.

Posted 9 years ago

Reputation: 23 761

5

Perl, 18 - 25 = -7

print$=x(<>*9||18)

The special variable $=, a.k.a. $FORMAT_LINES_PER_PAGE, begins its life as 60, and therefore only needs to be duplicated half as many times as byte output needed.

primo

Posted 9 years ago

Reputation: 30 891

1I had a very similar answer of: print$=x9x(pop||2) nice! – Dom Hastings – 9 years ago

5

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.

Conor O'Brien

Posted 9 years ago

Reputation: 36 228

I think the newline counts as part of the output. – lirtosiast – 9 years ago

@ThomasKwa What newline? You mean the "enter" key? – Conor O'Brien – 9 years ago

No, the newline printed automatically after every program is executed. – lirtosiast – 9 years ago

Oh. So change it to ᴇ3? – Conor O'Brien – 9 years ago

1

Yes, but it can just be 0 as I commented on the other TI-BASIC answer by Deusovi.

– lirtosiast – 9 years ago

4

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

J. Merdich

Posted 9 years ago

Reputation: 41

4

Ruby, 24 - 25 = -1

$><<?x*24*(gets||2).to_i

histocrat

Posted 9 years ago

Reputation: 20 600

4

Bubblegum, 1 byte

Ä

prints

!#

Test run

$ echo -en '\xc4' > double.bg
$ bubblegum double.bg 
!#

Dennis

Posted 9 years ago

Reputation: 196 637

That's two or three bytes, one character (depends on encoding). Do bytes == characters here? – Nateowami – 9 years ago

I/O is raw in Bubblegum. It only knows bytes, not characters. – Dennis – 9 years ago

1Yeah, 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"? – Nateowami – 9 years ago

2@Nateowami in ISO-8859-1, for example, Ä is a single byte, 0xC4. – primo – 9 years ago

@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). – Nateowami – 9 years ago

@Nateowami I've edited my answer. Sorry for the confusion. – Dennis – 9 years ago

4

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):

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

mbomb007

Posted 9 years ago

Reputation: 21 944

4

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

Status

Posted 9 years ago

Reputation: 995

4

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.

mrco

Posted 9 years ago

Reputation: 81

2-2 bytes. Length check – Benjamin Urquhart – 6 years ago

3

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

kalsowerus

Posted 9 years ago

Reputation: 1 894

You have been outgolfed. – Oliver Ni – 8 years ago

@OliverNi Does the input default to 2 if not given? – kalsowerus – 8 years ago

Oh. I'll fix that. – Oliver Ni – 8 years ago

3

Bash, 5 bytes

seq 5

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

1
2
3
4
5

Wossname

Posted 9 years ago

Reputation: 221

3

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.

CensoredUsername

Posted 9 years ago

Reputation: 951

1Could you print -1 to shorten it? – Jo King – 7 years ago

@JoKing managed to save off 2 bytes with an idea I got from your suggestion. – CensoredUsername – 7 years ago

3

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!

Gabriel Mills

Posted 9 years ago

Reputation: 778

3You could to try 1. Output includes a trailing newline! – mazzy – 6 years ago

3

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

Jo King

Posted 9 years ago

Reputation: 38 234

3

Deadfish~, 5 bytes

You expected a worthwhile submission, but it was ME:

{dio}

Try it online!

Prints the number "1" ten times.

Reinstate Monica

Posted 9 years ago

Reputation: 1 382

3

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
)$

Alex A.

Posted 9 years ago

Reputation: 23 761

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. – cat – 9 years ago

eg. (i.31<^9!i.1+i:) is 16 bytes – cat – 9 years ago

3

q, 10 3 bytes

3#0

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

Alexander Belopolsky

Posted 9 years ago

Reputation: 191

1If I understand the challenge correctly, an 8-byte long program should produce 16 bytes of output... – undergroundmonorail – 9 years ago

Right. I should have read past the title. I've updated my answer. – Alexander Belopolsky – 9 years ago

3

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

alert('s'.repeat(30*prompt()))

Patrick Roberts

Posted 9 years ago

Reputation: 2 475

The question requires a full program. Your code will only work inside a REPL environment. – Dennis – 9 years ago

@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. – Patrick Roberts – 9 years ago

@PatrickRoberts If you use prompt to input, then you should use something like alert to output. – Doorknob – 9 years ago

prompt isn't the issue. This will produce no output outside a REPL environment. – Dennis – 9 years ago

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. – Patrick Roberts – 9 years ago

3

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.

anatolyg

Posted 9 years ago

Reputation: 10 719

3

Python 2, 11 bytes

print 9**21

displays 109418989131512359209\n (22 chars)

dieter

Posted 9 years ago

Reputation: 2 010

3

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║
╚═══╝╘╤╝╚══╝

Timwi

Posted 9 years ago

Reputation: 12 158

You could use the TAB character, 9. – Titus – 8 years ago

3

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.

Addison Crump

Posted 9 years ago

Reputation: 10 763

3

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.)

Candles

Posted 9 years ago

Reputation: 683

3

Python, 15 bytes

print 'aaaaa'*6

Prints:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Which is 30 bytes.

TheDoctor

Posted 9 years ago

Reputation: 7 793

1

There are already two shorter Python 2 answers.

– lirtosiast – 9 years ago

2@ThomasKwa well I'm sorry I didn't read through all 110 answers </sarcasm> – TheDoctor – 9 years ago

6There'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. – lirtosiast – 9 years ago

You could use print'a'*11 to save 4 bytes. – ASCIIThenANSI – 9 years ago

1@ASCIIThenANSI print'a'*22. The output needs to be twice the length of your code. – Erik the Outgolfer – 8 years ago

3

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.

Leaky Nun

Posted 9 years ago

Reputation: 45 011

Looks like I am not the first one to discover <code>7^7</code>... never mind, I still discovered it myself. – Leaky Nun – 9 years ago

3

Desmos, 3 bytes

9^6

Equals 531441

weatherman115

Posted 9 years ago

Reputation: 605

I'm not sure desmos is considered a language, though it is pretty awesome. – Daniel M. – 8 years ago

1Desmos is technically a programming language since you can program things with it. – weatherman115 – 8 years ago

Desmos satisfies our requirements. – Mego – 8 years ago

2

PHP no bonus, 19 17 16 14 9 bytes

<?=99**9;

prints 913517247483640899

longer versions:

  • echo date(Mc); 14 bytes print the first three letters of the month name followed by
    an ISO-8601 formatted date (like 2017-01-26T21:57:38-08:00 - length=25)
  • var_dump([01]); 15 bytes print array(1) {\n [0]=>\n int(1)\n}\n
  • echo decbin(~0); 16 bytes print 32 ones (on a 32 bit machine)
  • echo md5(12345); 16 bytes print 827ccb0eea8a706c4c34a16891f84e7b
  • <?=str_pad(_,34); 17 bytes print one underscore and 33 spaces.
  • <?=decbin(2**33); 17 bytes print a 1 and 33 zeroes
  • printf("%34d",0); 17 bytes print 33 spaces and a 0
  • echo date(uuuuuu); 18 bytes print 6*6 zeroes
  • <?=date(uuuuYY); 16 bytes print 6 zeroes four times and the current year twice

close but no cigar:

  • <?=pi(); 8 bytes print 3.1415926535898 (15 characters; 64 bit machine)
  • <?=log(2); 10 bytes print 0.69314718055995 (16 chars; 64 bit)
  • <?=date(wc); 12 bytes print 26 chars
  • var_dump(_.pi()); 17 bytes print 30 chars (64 bit)

Titus

Posted 9 years ago

Reputation: 13 814

2

[Non-Competing] C, 16

Code:

//score=16 bytes

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

Albert Renshaw

Posted 9 years ago

Reputation: 2 955

2

Excel,10 Bytes

=pi()&1234

prints 3.141592653589791234

Jörg Hülsermann

Posted 9 years ago

Reputation: 13 026

A different approach gives 5 bytes: `=10^9' – Wernisch – 5 years ago

2

Carrot, 4 bytes, non-competing

.^*7

Prints ........ (8 .s).

Try it online!

Explanation

.^                        Sets the stack-string to "."
  *7                      Append seven duplicates of the stack-string to itself
                          Implicit output

user41805

Posted 9 years ago

Reputation: 16 320

2

Pyth, 3 - 25 = -22 bytes

This was an accident, but it magically works, however, to make this work, I had to waste a byte.

yDQ

This returns a range between 0-input. The brackets, commas, and spaces add up to Q times 3.

I honestly can't quite tell you how or why this works.

Test Suite

Pyth, 1 byte (no bonus)

d

Returns a space and a newline, which is 2 characters.

Test Suite

Stan Strum

Posted 9 years ago

Reputation: 436

doesn't appear to work for no input – ASCII-only – 7 years ago

@ASCII-only I believed that input was always going to be in regex /[0-9]+/, unless otherwise specified. – Stan Strum – 7 years ago

"If no input is provided, n must default to 2." idk though, the question may be unclear :/ – ASCII-only – 7 years ago

@ASCII-only Give me 24 hours while I finish up my 2 weeks of work due tomorrow. It's 9;31 UTC-8 – Stan Strum – 7 years ago

Note: @Blue just pointed out that input will always be positive so you can just do logical or – ASCII-only – 7 years ago

@ASCII-only is 0 positive? I've been taught in Maths that 0 is neither positive nor negative – Stan Strum – 7 years ago

Let us continue this discussion in chat.

– ASCII-only – 7 years ago

What if the input is bigger than 10? Two digit numbers = two characters – Jo King – 7 years ago

2

dc, 4 bytes

1dff

prints

1
1
1
1

TIO

cab404

Posted 9 years ago

Reputation: 141

nope. 1 \n 1 \n 1 \n 1 \n @Stephen – cab404 – 7 years ago

2

LibreLogo, 21 bytes

Code:

input_half_the_length

Result:

Unknown name: ‘input_half_the_length”.

enter image description here

Grant Miller

Posted 9 years ago

Reputation: 706

2

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'

Noskcaj

Posted 9 years ago

Reputation: 421

2

Perl 5, 17 - 25 = -8

Tip of the hat to primo for getting me to reread perlvar

die$/x(<>*17||34)

Try it online!

fockjef

Posted 9 years ago

Reputation: 51

2

Brachylog, 10 bytes - 25 = -15

{2|};Ṿj₍jw

Try it online!

         w    Print
     Ṿ        "aeiou"
      j       concatenated with itself
 2            two
{ |}          or whatever else the input is
    ;  ₍      times
        j     concatenated with itself again.

A version without the bonus:

Brachylog, 3 bytes

ẈẈw

Try it online!

Bypasses the ban on unnecessary whitespace by using unnecessary variable unification instead.

  w    Print
 Ẉ     the built-in constant "aeiouy" which is
Ẉ      the built-in constant "aeiouy".

A version without any silly redundancy:

Brachylog, 4 bytes

1j₈w

Try it online!

   w    Print
1       the digit 1 (could be any digit other than 0)
 j      repeated
  ₈     eight times.

Unrelated String

Posted 9 years ago

Reputation: 5 300

2

Runic Enchantments, 10 bytes -25 = Score: -15

"9q2i{S*$;

Try it online!

Program reads a string literal (effectively its own source), concats a 9, pushes a literal 2, and attempts to read input.

Reading input and there being no input to read causes the next two commands, {S, to be NOP. This leaves the literal 2 on top of the stack. If there was input, the input ends up on top and the literal 2 on the bottom. Non-numerical input has undefined behavior.

Then multiplication between the integer on the top of the stack with the next item (the string) duplicates it n times (Python style). String is exactly the length of the program, being almost a quine, with 9q putting a 9 on the end substituting for the missing " from the beginning. $; prints only the resulting string and terminates (discarding any remaining literal 2 if input was taken).

Draco18s no longer trusts SE

Posted 9 years ago

Reputation: 3 053

2

INTERCAL, 32 bytes

PLEASE,1<-#64DOREADOUT,1DOGIVEUP

Try it online!

Prints 64 null bytes and takes no input. If you like your output printable, the next version is for you:

INTERCAL, 45 bytes

PLEASE,1<-#90DO,1SUB#1<-#4DOREADOUT,1DOGIVEUP

Try it online!

This is one of those rare cases where C-INTERCAL’s “Turing Tape” I/O is actually helpful. Essentially, what it does is for each value in an array, rather than directly print the corresponding character, is subtract the value from the previous value (starting at 0) mod 256, reverse the bits, and then print that, for every value up to the end of the array. So to print a string of a certain length, you just need to READ OUT an array of that size, and to make it more than just a bunch of null bytes, you only need to set the first element of the array and it’ll print a bunch of something else instead: here, setting the first value to 4 prints 90 question marks, since 0 - 4 mod 256 ≡ 252 = 0b11111100 which is 0b00111111 = 63 backwards, and since every cell in the array after the first has a 0 in it the byte which gets printed never changes on account of that 252 - 0 is still 252.

A version with the bonus which prints null bytes:

INTERCAL, 67 bytes - 25 = 42 (except it can't default to 2)

DOWRITEIN.1DO.2<-#67DO(1530)NEXTPLEASE,1<-:1DOREADOUT,1PLEASEGIVEUP

Try it online!

A version which prints question marks instead:

INTERCAL, 80 bytes - 25 = 55 (except it can't default to 2)

DOWRITEIN.1DO.2<-#80DO(1530)NEXTPLEASE,1<-:1DO,1SUB#1<-#4DOREADOUT,1PLEASEGIVEUP

Try it online!

Uses a call to syslib for multiplication of the input with 80 into :1. (Also note that INTERCAL’s native number input format is the digits of a number spelled out with a trailing newline.)

Unrelated String

Posted 9 years ago

Reputation: 5 300

Also also note that both versions which take input can't handle not taking input and are thus invalid. – Unrelated String – 6 years ago

2

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).

orthoplex

Posted 9 years ago

Reputation: 339

2

Guile (5)

"oof" outputs $1 = "oof"

SYZYGY-DEV 333

Posted 9 years ago

Reputation: 71

1Hello, welcome to PPCG! – James – 6 years ago

2

Bash, 10 bytes

yes|head -

outputs 10 lines of ys for 20 total bytes output.

Beefster

Posted 9 years ago

Reputation: 6 651

2

Triangular, 10 8 7 bytes

tdC%.`y

Try it online!

Prints odd numbers from 11 to 1 descending, twice each.

Triangular executes as if written in the shape of a triangle. For example, if your program was 123456, the triangle representing your program would be drawn like this:

  1
 2 3
4 5 6

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

   t
  d C
 % . `
y

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

t             - If ToS != 0, set direction to SouthEast
 C            - Push 12
  `           - Set direction to NorthWest (This means we hit "t" with ToS > 0)
   d          - Decrement the top value of the stack
    %y        - Print the top value of the stack, then change direction to NorthEast if ToS != 0

Previous Version (8 bytes):

Dn,%d./<

Reinstate Monica

Posted 9 years ago

Reputation: 1 382

2

Ruby, 6 bytes

p ?a*9

Prints "aaaaaaaaa" (including the quotes) and a newline.

daniero

Posted 9 years ago

Reputation: 17 193

2

JavaScript (ES6), 23 bytes - 25 = -2

(n=2)=>'x'.repeat(23*n)

Just for fun here's a quine version with a score of 27 bytes -25 =2

a=(n=2)=>`a=${a}`.repeat(n)

George Reith

Posted 9 years ago

Reputation: 2 424

1Does this really write to standard output? – user253751 – 9 years ago

It's a function return, using fat arrow notation. – MayorMonty – 9 years ago

3The spec requires a full program... – John Dvorak – 9 years ago

2Running this program just gives me a function. Its output is a function that the length isn't double, nor does it take standard input. – Unihedron – 9 years ago

Writing functions that return the required result, as well as taking input from function arguments, is allowed. – ivzem – 8 years ago

2

JavaScript (ES6), 50-25=25

a=prompt();alert("0".repeat(48*(isNaN(a|0)?2:+a)))

SuperJedi224

Posted 9 years ago

Reputation: 11 342

2

Element, 16 bytes - 25 bonus = -9

_2:1<[2]16*'[X`]

Explanation:

_2:1<[2]16*'[X`]
_                  take input
 2:                duplicate it
   1<              test "if less than one" (like an empty input)
     [2]           FOR/IF push 2 if true
        16*        multiply by 16
           '       move result to control stack
            [  ]   FOR
             X`    output the letter X

Element, 6 bytes

9 12^`

prints 282429536481

Explanation:

9       push 9
  12^   to the twelfth power
     `  output

PhiNotPi

Posted 9 years ago

Reputation: 26 739

2

PHP 7, 9 Bytes

<?=str_repeat(1,($argv[1]??2)*34);

Uses the short opening tag with echo <?= and the null coalesce operator ?? which falls back to 2 if $argv[1] is not set, without throwing an error.

Fabian Schmengler

Posted 9 years ago

Reputation: 1 972

2

Pyth, 8 - 25 = -17 bytes

mU2?zvz2

Demonstration

Note: This only works in the online compiler, because it removes the trailng newline.

Output form:

[[0, 1], [0, 1], [0, 1]]

isaacg

Posted 9 years ago

Reputation: 39 268

2

Haskell, 19 bytes

main=print[92..102]

Outputs: [92,93,94,95,96,97,98,99,100,101,102] and a NL.

nimi

Posted 9 years ago

Reputation: 34 639

The output is 37 long... unless you count newline. In that case I suggest main=print[3..15]. Actually, per OP, "No adding unnecessary whitespace to the source code to change its length". – Leif Willerts – 9 years ago

1@LeifWillerts: the newline is there, so it counts. Removed the whitespace. – nimi – 9 years ago

2

GolfScript, 1 byte

1

At the end of a GolfScript program, the interpreter outputs everything that's on the stack, and a trailing newline. So the output of the above program is 1 with a trailing newline, two bytes.

ProgramFOX

Posted 9 years ago

Reputation: 8 017

2

PHP, 56-25bytes = 31 bytes

I wanted one where size of the code doesn't matter:

<?=str_repeat(file_get_contents(__FILE__),$n!=''?$n:2)?>

Or a more modern version:

<?=str_repeat(file_get_contents(__FILE__),$argv[1]?:2)?>

Martijn

Posted 9 years ago

Reputation: 713

1I started down the same path but "No file/disk/network io allowed." – Alex Howansky – 8 years ago

Where do you get $n from? Try $argv[1]?:2; it has the same length as your expression. – Titus – 8 years ago

This post is a year old, where register_globals was frowned upon, but not forbidden :) – Martijn – 8 years ago

register_globals went off in the default config with PHP 4.2 (about 15 years ago). The other one requires 5.3 or later. No file/disk/network io allowed. But who cares; it´s nice. And you can still save four bytes with $n?$n:2. – Titus – 8 years ago

2

Retina, 25 24 - 25 = -1 bytes

^$
11
1
11111111!
&!`111

Use the -s flag to run the code from a single file. Input is in unary.

For reference, without the bonus, there's a 1-byte solution:

!

Really any single character would do, so long as it's a valid regex (so an unmatched parenthesis wouldn't). This will just print the number of matches (zero in this case) followed by a newline, which makes two bytes.

Explanation

A translation of the sed answer, requires 25 bytes (computed as 5x5) instead of 40 (see revision history). However, we can do better in Retina:

First, we default the input to (unary) 2 if it's empty with:

^$
11

Now we turn each 1 into eight 1s and an exclamation mark with:

1
11111111!

What we ultimately want is to print 24 bytes for each of those chunks. The idea is to get a "free" multiplication by using Match mode's options to a) print all matches and b) consider overlapping matches. We also note that each match is terminated by a linefeed. So if each match is 3 bytes, we'll get 4 bytes per line, and need 6 lines. How many possible 3-byte matches are there in a string of 8 ones?

11111111
111
 111
  111
   111
    111
     111

Six. How convenient :). So we the final stage is simply:

&!`111

Which means that for each unit of source code length requested, we print:

111
111
111
111
111
111

with a trailing newline, which is exactly 24 bytes.

Note that this is why we needed to append the exclamation mark to each line: it ensures that we don't get additional matches which are shared between chunks.

Martin Ender

Posted 9 years ago

Reputation: 184 808

2

T-SQL, 16 bytes

SELECT SPACE(32)

This returns a string of 32 spaces. Can't think of anything fancier at the minute.

PenutReaper

Posted 9 years ago

Reputation: 281

Save one byte with PRINT SPACE(30) – BradC – 7 years ago

2

SWI-Prolog, 3 bytes

nl.

This outputs:

\n
true.

(the \n is printed as an actual linefeed, not the two characters).

Fatalize

Posted 9 years ago

Reputation: 32 976

Is the dot after true in the Prolog specs or is it interpreter specific? The swish online interpreter doesn't print it allowing the 2-byte program p. – Emigna – 9 years ago

@Emigna Hmm, then I guess it depends on what interpreter you have. I used SWI-Prolog, so I will update the title of this answer to be SWI-PROLOG specific and you may answer with a shorter solution for other interpreters. – Fatalize – 9 years ago

2

Jelly, non-competing

-21 bytes This answer is non-competing, since the challenge predates the creation of Jelly.

o2⁴x

The source code is 4 bytes long and qualifies for the -25 bytes bonus. Output is a list of 16's.

Try it online! without input or with input.

How it works

o2⁴x  Main link.
      If there's input, the left argument is set to that input.
      Otherwise, it defaults to 0.
o2    Logical OR of the left argument and 2.
      The return value is now either the input or 2.
  ⁴x  Repeat 16 that many times, creating an array.

16 is two bytes long, and n copies are separated by n - 1 instances of . That, plus the two bytes of [ and ] gives 2n + 2(n - 1) + 2 = 4n bytes of output.

Dennis

Posted 9 years ago

Reputation: 196 637

It seems that you have (ab)used array representations here. – Erik the Outgolfer – 8 years ago

2

PHP, 34 bytes - 25 = 9

$i=34*$argv[1];while($i--)echo"x";

34 bytes generating 34 * $argv[1] characters

2x version, 25 bytes

$i=50;while($i--)echo"x";

25 bytes generating 50 characters

ricdesi

Posted 9 years ago

Reputation: 499

2

Brian & Chuck, 9 bytes

{?
#.{-?

Try it online! There's a single unprintable \x12 (code point 18) before the first { which gets decremented each iteration, giving an output of 18 ?s.

Sp3000

Posted 9 years ago

Reputation: 58 729

2

Batch, 17 bytes

@type %0 %0 2>nul

This one does not require a special locale (as the date solution does)

And it does not require %PATH% to be set. (No environment at all, for that matter)

2>nul is required to supress type to output the filenames on stderr (which it does when more than 1 file is printed)


Currently I couldn't conjure up a f(x)=x*N solution that is shorter than 17+25 bytes

This is the best I could come up with:

@if !%1 == ! (call %0 2) else (for /l %%x in (1,1,%1) do @type %0 2>nul)

Which has a score of (72-25) 45 bytes

MrPaulch

Posted 9 years ago

Reputation: 771

You could golf that n solution by 12 bytes to a total of 60 (-25 = 35): @if !%1==! (call %0 2)else for /l %%x in (1,1,%1)do @type %0, done by removing some unecessary spaces and parentheses. Also, the 2>nul thing is only needed for multiple files, and since you're only doing type %0, it isn't required there. Finally, I'm not 100% sure on how bytes for flags are counted, but you could possibly use the /v flag (if it only counts as 1 byte) on cmd to remove those 2 pesky @. Cheers! – Matheus Avellar – 7 years ago

I realize it's still not perfect as 35 is still more than 17, but it's something :T – Matheus Avellar – 7 years ago

I wonder isn't this 'file io'? – stevefestl – 7 years ago

2

JavaScript, 2 bytes

f=(n=2)=>("f="+f).repeat(n)
  • +27 bytes source code
  • -25 bytes bonus

ericw31415

Posted 9 years ago

Reputation: 2 229

2

Brain-Flak, 128 bytes

Try it online!(You probably wont be able to finish it before the universe ends)

(((((((((((((()()()){}){}){}){}()){}){({}[()])}{}){({}[()])}{}){({}[()])}{}){({}[()])}{}){({}[()])}{}){({}[()])}{}){({}[()])}{})

How it works

It starts simply by pushing ninety-eight to the stack:

((((((()()()){}){}){}){}()){})

It then implements my Triangulation algorithm:

(*push n*{({}[()])}{})

seven times.

This results in

1447283887869053957595051227533274962011504066726596247765427442496031260270109555118382532157345193860142997726793245725173763195275989332247013823819162395404940274645651775376645319691872778284304403703355308050412897911161964450479105938633399903762942

The program then terminates and spits the contents of the stack to the terminal. Since insert atrociously huge number here is 256 characters long in base 10, the output is exactly twice the source code's length.

As one might tell I used a computer aided search to find this solution. This is almost certainly the shortest solution using the triangulation method I outlined.

Post Rock Garf Hunter

Posted 9 years ago

Reputation: 55 382

1

PHP, 32 30 bytes -25 = 5

<?=str_pad(_,30*$argv[1]?:60);

prints an underscore, fills up with spaces

fancier, but longer (38 bytes):

<?=date(str_pad(r,3*$argv[1]?:6,MYr));

gives ("rMY" repeated N times) as argument to date(), which returns an RFC 2822 formatted date (e.g. Thu, 26 Jan 2017 23:32:31 -0800, length=31) followed by 3 letters of the month name and the 4 digit year - repeated N times. <?= prints the result.

Titus

Posted 9 years ago

Reputation: 13 814

1

SmileBASIC, 24 18-25= -7 bytes

N=2INPUT N?@A*N*9;

In SmileBASIC, labels (@LABEL) are treated as string literals in expressions, so you can make a 2 or more character long string without any quotes. Then it just has to print @A N*9 times to get the correct length.

Without bonus, 6 4 bytes

?1E7

There is a line break after the output, but technically no character is printed to the screen (it is different than if you just printed CHR$(10))

12Me21

Posted 9 years ago

Reputation: 6 110

Where is the default value? – Titus – 8 years ago

Alright, Fixed :( – 12Me21 – 8 years ago

Could you remove the ; at the end of the first program? I'd argue the linebreak on the console doesn't matter since it doesn't seem to actually write a character to output. – snail_ – 7 years ago

The program would then be an odd number of characters long, so you couldn't get an output n* the length by multiplying a string with length 2. – 12Me21 – 7 years ago

1

Pushy, 2 bytes

H#

Try it online! - this prints 100 followed by a trailing newline, 4 bytes of output.

H  \ Push 100 to the stack
 # \ Print with a trailing newline

FlipTack

Posted 9 years ago

Reputation: 13 242

1

Haskell, 25-25 = 0 bytes

f n=putStr$[1..25*n]>>"*"

prints n*25 Asterisks

Sacchan

Posted 9 years ago

Reputation: 621

Is this a "complete program"? It looks like just a function to me. – dfeuer – 6 years ago

1

PHP, 45 bytes

<?php print number_format(pow(10,66))."a"; ?>

output:

1,000,000,000,000,000,132,394,543,446,603,018,655,781,305,157,705,474,440,625,207,115,776a

<?php              //PHP start tag
print              //Prints what's ahead
number_format(arg) //format what's inside the parentheses as a number, with separators. (Used as escape function for having scientific notation result 
pow(base,exp)      //Gets the value of the `base` raised to the power of `exp`
.                  //Concatenation operator
"a"                //String of "a"
?>                 //End tag for PHP

Jimwel Anobong

Posted 9 years ago

Reputation: 159

1

Windows Batch, 148 144 73 30 bytes

@echo %OS%%OS%%OS%%OS%%OS%%OS%

The %OS% system variable should be Windows_NT on most Windows NT systems.

6 of this %OS%(i.e. Windows_NT) is exactly 60 character, which is codeLength * 2.

stevefestl

Posted 9 years ago

Reputation: 539

1

Japt, 1byte

My previous solution-with-bonus was invalid as I missed the requirement that input should default to 2. This is a stop-gap until I have a few minutes to come up with something better.

A

Output: 10

Try it online

B-G would also work, outputting 11-16 respectively, as would H (32), I (64) & J (-1).

Slightly less trivial solutions include (1000) and 8³² (262144), among many others.

Shaggy

Posted 9 years ago

Reputation: 24 623

1If no input is provided, n must default to 2. – Taylor Scott – 7 years ago

As Taylor Scott said, the input must default to 2. – Erik the Outgolfer – 7 years ago

@EriktheOutgolfer: Ah, missed that (the requirement and Taylor's comment). Will update with a bonusless solution momentarily as a stop-gap 'til I get a few minutes to come up with something else. – Shaggy – 7 years ago

1

Python 3, 26 25 Bytes

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

Improved thanks to @JoKing

MrGeek

Posted 9 years ago

Reputation: 231

1

Forth (gforth), 36 - 25 = 11 bytes

: x depth 0= if 2 then 36 * spaces ;

How it works:

Checks if no value is on the stack (depth 0=). If that is the case, push 2. Then just print n * 36 spaces.

Forth (gforth), 2 bytes

.S

Only works if the stack is empty. Prints <0> (<, 0, > and space)

2xsaiko

Posted 9 years ago

Reputation: 699

1

Braingolf, 1 byte

Prints 0 and a newline.

l

Try it online!

Explanation

l

l      push length of the stack to the stack
       implicit output
       implicit newline printed at end of program

totallyhuman

Posted 9 years ago

Reputation: 15 378

1

><>, 15 + 2 (-v flag) - 25 = -8 bytes

2{f*:?!;0n1-30.

Explanation:

2{ puts 2 at the bottom of the stack. If no input was provided, this means it is at the top. Otherwise, the provided input will be at the top.

f* multiplies the input by 15 (the length of the program)

We then go into a loop: :?!;0n1-30.

:?!; ends the program if the counter is 0.

Otherwise, 0n prints 0, 1- decrements the counter, and then 30. goes back to the start of the loop.

Esolanging Fruit

Posted 9 years ago

Reputation: 13 542

1

VBA, 2 1 -3 20 - 25 = -5 Bytes

?Spc([Max(A1,2)*20])

Which outputs [A1] (analagous to n) else 1 times 22 (length of the code) spaces

Previous Version 1 Byte

?

Output

 

Taylor Scott

Posted 9 years ago

Reputation: 6 709

1

TI-Basic, 2 bytes

::

(Ab)uses the fact that programs output Done when nothing is evaluated on the last line.

Timtech

Posted 9 years ago

Reputation: 12 038

This doesn't work. You need two colons after the last expression to display Done. – lirtosiast – 7 years ago

@lirtosiast Fixed – Timtech – 7 years ago

1

05AB1E, -23 bytes (non-competing)

Try it online!

Magic Octopus Urn

Posted 9 years ago

Reputation: 19 422

This doesn't default to 2 for no input – Jo King – 6 years ago

@JoKing it used to, 05AB1E basically got a massive overhaul. It for sure used to default to 10. – Magic Octopus Urn – 6 years ago

Doesn't work for 1. I don't see how this works, so may you explain your program? – None – 5 years ago

1

Java 8, 16 15 bytes

Golfed a byte by using a for loop instead of a while loop. (back to where I was before :P)

u->{for(int x=0;++x<40*u;)out.print(1);}

Using a static import to reduce the code by 7 bytes, this prints out 1 40u times, where u is the integer taken from input. Since the program code is 40 bytes long and I incorporated the bonus, that leads me with 40 - 25 = 15 bytes.

Try it online!

NotBaal

Posted 9 years ago

Reputation: 131

On TIO, this outputs in scientific notation, which means that the output for u.c(1) is ~6 bytes. Is that also how it works for you locally? If so, I'm not sure this is working as intended. – Stephen – 7 years ago

I, for some reason, thought the output simply had to represent double the length of the source code. Thanks for pointing it out; fixed accordingly. – NotBaal – 7 years ago

1

Ly, 17 - 25 = -8 bytes

"9>n[<&s&ol>1-]<;

Try it online!

A simple quine variant. Outputs 9>n[<&s&ol>1-]<; input times. (there's a tab at the end)

3 bytes, no bonus

"&|

Outputs:

38 124

Try it online!

LyricLy

Posted 9 years ago

Reputation: 3 313

1

Pyke, 1 byte

T

Try it here!

Outputs 10

Blue

Posted 9 years ago

Reputation: 26 661

1

Pyke, 5 bytes -25 = -20

2|}hV

Try it here!

Blue

Posted 9 years ago

Reputation: 26 661

1

Pyke, 3 bytes -25 = -22

2|S

Try it here!

2|  -  input or 2
2|S - range(1, ^)

Blue

Posted 9 years ago

Reputation: 26 661

Not sure if this is valid, input of 0 acts as if n=2, but I guess there isn't really a way to avoid that – ASCII-only – 7 years ago

It says input will be a positive integer though it doesn't specify if 0 is valid or not – Blue – 7 years ago

Oh, fair enough – ASCII-only – 7 years ago

1

BASH + coreutils, 22 (-25) = -3 bytes

printf %$[${1:-2}*22]d

Pass repeat count as 1st argument. Omit argument to default to 2 repeats.

Andrew Dunai

Posted 9 years ago

Reputation: 321

1

Scala, 35 bytes

object X extends App{print("X"*70)}

Try it online!

cubic lettuce

Posted 9 years ago

Reputation: 181

1

Fission, 7 6 bytes

'#ORR"

This is a variation on a standard Fission quine. With two R's it creates two atoms and reads through the program twice.

Outputs ''##OORRRR##

Try it online!

-1 byte thanks to Jo King

KSmarts

Posted 9 years ago

Reputation: 1 830

Why do you need the _? '#ORR" seems to work fine – Jo King – 7 years ago

@Joking It outputs ## at the end instead of "".

– KSmarts – 7 years ago

And? That’s still twice the bytes. It doesn’t need to be quine-like – Jo King – 7 years ago

@JoKing Ah, I didn't re-read the challenge well. Updated. – KSmarts – 7 years ago

aORR". – jimmy23013 – 7 years ago

2

Or just ORR".

– jimmy23013 – 7 years ago

1

Befunge-98, 12 - 25 = -13 bytes

j& 6*1-k.@>2

Try it online!

Prints the correct amount of 0s, each with a trailing space.

How It Works:

j  No effect
 & Gets input. If no input, reflect
         >2 If it reflected put two 2s on the stack 
j  Use one of the 2s to jump past the &
  6*1- Multiply by 6 (length/2) and subtract 1 because it prints an extra 0 later
      k.@ Print that many 0s and end the program

Jo King

Posted 9 years ago

Reputation: 38 234

1

C (gcc), 35 - 25 = 10 34 - 25 = 9 bytes

-1 byte thanks to PrincePolka

Input is in the form of number of command-line arguments. No arguments counts as no input.

main(i){printf("%*d",34*--i?:68);}

Try it online!

gastropner

Posted 9 years ago

Reputation: 3 264

main(i){printf("%*d",34*--i?:68);} - 1 byte – PrincePolka – 5 years ago

@PrincePolka Cheers! – gastropner – 5 years ago

1

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.

Conor O'Brien

Posted 9 years ago

Reputation: 36 228

1

Rebol, 24 bytes

copy/part mold system 48

Prints the first 48 characters of the system object.

Also works with the Red language

FriendlySpoon

Posted 9 years ago

Reputation: 11

1

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.

Azeros

Posted 9 years ago

Reputation: 41

You should add the fact that this is non-competitive. Also is the language a stable release or a WIP ? – Muhammad Salman – 7 years ago

@MuhammadSalman It's in Beta rn (still missing a lot of standard functions) but it's actually quite stable. – Azeros – 7 years ago

Okay. So still a WIP then. I like the language so far (also an interesting choice of languages in which you are building this) – Muhammad Salman – 7 years ago

@MuhammadSalman Thanks! Appreciated! But why did you add the "non-competitive"? – Azeros – 7 years ago

The challenge precedes the language. – Muhammad Salman – 7 years ago

1

///, 15 bytes

/o/ttttt/oooooo

Try it online!

Tanner Swett

Posted 9 years ago

Reputation: 531

1

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

NieDzejkob

Posted 9 years ago

Reputation: 4 630

1

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.

Unrelated String

Posted 9 years ago

Reputation: 5 300

1

Come Here, 39 bytes

CALL"9999999999999"iTELLi i i i i iNEXT

SuperJedi224

Posted 9 years ago

Reputation: 11 342

1

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!

640KB

Posted 9 years ago

Reputation: 7 149

1

Excel Formula, 23 - 25 = -2 bytes

=REPT("A",MAX(A1,2)*23)

However, this doesn't work for A1 (n) = 1(!)

Version supporting N=1, 28 - 25 = 3 bytes

=REPT("A",(A1=0)*56+(A1*28))

i_saw_drones

Posted 9 years ago

Reputation: 413

1

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!

Dehodson

Posted 9 years ago

Reputation: 111

1

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

user85052

Posted 9 years ago

Reputation:

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? – mbomb007 – 6 years ago

There should be a control character between ( and |, which should be 0x0C. – None – 6 years ago

1

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.

LegenDUST

Posted 9 years ago

Reputation: 799

1

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.

negative seven

Posted 9 years ago

Reputation: 1 931

1

MathGolf, 2 bytes

7!

Outputs 5040, which is 4 bytes.

Try it online!

Matthew Anderson

Posted 9 years ago

Reputation: 131

1Congratulations on your first MathGolf answer! There are also quite a few 1-byte answers, as the bytes A to Z hold values between 11 and 38. Other approaches are Hf (19th fibonacci number) or (push 7 and quadruplicate to 7777). – maxb – 5 years ago

1

MathGolf, 5 - 25 = -20 bytes

╜2╩[*

Try it online!

Explanation

╜2      If not implicit input, push 2
  ╩[    Push dictionary word "great"
    *   Repeat string

To make it work, I just had to find a word within the top 256 lines of the dictionary which had the same length as the code.

Almost working 3-byter with 25 byte bonus

╜2r

Try it online!

Basically the same as Stan Strum's Pyth answer. If (implicit) input is equal to 0, push 2. Then create a range using either the 2, or the implicit input. The length of the output is the length of the string representation of the array, which is 3 times the length of the array. This only works for input $\leq 10$.

maxb

Posted 9 years ago

Reputation: 5 754

1

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

user85052

Posted 9 years ago

Reputation:

1

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.

sporeball

Posted 9 years ago

Reputation: 461

1

><>, 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.

cole

Posted 9 years ago

Reputation: 3 526

1

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.

El'endia Starman

Posted 9 years ago

Reputation: 14 504

1

Microscript, 1

0

Prints the digit 0, followed by a newline.

SuperJedi224

Posted 9 years ago

Reputation: 11 342

http://codegolf.stackexchange.com/revisions/59457/3 What kind of edit is that?? Hahaha – Albert Renshaw – 9 years ago

1

q (bonus), 27 bytes

1#[;"x"]27*2^first"J"$.z.x;

Alexander Belopolsky

Posted 9 years ago

Reputation: 191

1

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'

dev-masih

Posted 9 years ago

Reputation: 111

1I think there's one rule missing: If no input is provided, n must default to 2 – Thomas Weller – 9 years ago

1

awk, 29 - 25 = 4 bytes

{printf"%0"($0?$0:2)*29"d",0}

Prints the wanted number of zeros.

Cabbie407

Posted 9 years ago

Reputation: 1 158

1

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)

user19214

Posted 9 years ago

Reputation:

@Unihedron I don't see how this violates that rule. – Doorknob – 9 years ago

1

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

steve

Posted 9 years ago

Reputation: 2 276

1print$=x9 for one byte. – primo – 9 years ago

1I think print$~x3 also works for the same score. On my system, it outputs STDOUTSTDOUTSTDOUT. – PhiNotPi – 9 years ago

1

Julia, 9

warn(⊆)

prints

"WARNING: issubset\n"

mschauer

Posted 9 years ago

Reputation: 1 348

Might want to format your header differently so your score doesn't look like -8 instead of 9 – Patrick Roberts – 9 years ago

1

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.

Kade

Posted 9 years ago

Reputation: 7 463

1

Pyth, 4 bytes

*8"1

will print out

11111111

Erik the Outgolfer

Posted 9 years ago

Reputation: 38 134

1Why did someone EDIT my answer??? – Erik the Outgolfer – 9 years ago

I like how you rolled back their changes and then added them back in. – Luminous – 9 years ago

1@Luminous I did it because I want editors to learn not to edit my answers. They can suggest in comments instead! – Erik the Outgolfer – 9 years ago

1Well 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. – Luminous – 9 years ago

@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. – Erik the Outgolfer – 9 years ago

@Luminous I mean not completely edit it. – Erik the Outgolfer – 9 years ago

Meta discussion on editing other people's code, if you or @Luminous want to post/vote. – trichoplax – 9 years ago

1

C, 25

main(){printf("%*p",50);}

This makes use of UB, but it should work. At least it works with gcc 5.2.0

Vincent

Posted 9 years ago

Reputation: 13

1

MSM, 12 bytes

'...;.;.;...

Outputs ........................

nimi

Posted 9 years ago

Reputation: 34 639

1

Lua, 35 - 25 = 10 bytes

Takes input from the command line, which is in the varargs.

print(("n"):rep(35*(...or 2)-1))

Trebuchette

Posted 9 years ago

Reputation: 1 692

You can shave off 3 bytes with print(("n"):rep(35*(...or 2)-1)) – Katenkyo – 9 years ago

1

R, 3 bytes

10;

will print

[1] 10

flodel

Posted 9 years ago

Reputation: 2 345

1

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.

DLosc

Posted 9 years ago

Reputation: 21 213

1

Insomnia, 1

7

Output:

00

8, A, B are 3 other programs that satisfy the requirement. Their output contains NUL characters, though.

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 9 years ago

Reputation: 5 683

1

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.

senshin

Posted 9 years ago

Reputation: 641

1

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

wefwefa3

Posted 9 years ago

Reputation: 166

I think you can shave some off by modifying b as you go: b&&*++b&&(a=atoi(*b)-1) – Toby Speight – 9 years ago

Yes comrade! It does work. – wefwefa3 – 9 years ago

1

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).

Berend

Posted 9 years ago

Reputation: 131

With my system settings it prints 2015.10.07\n – SuperJedi224 – 9 years ago

Got 6.2 bytes using "type %0". – Star OS – 9 years ago

@StarOS That gives me The system cannot find the specified file (roughly translated) – Berend – 9 years ago

Berend, it only works in a Batch file. +1 beacuse all of the other things don't use a shell, it uses a file – Star OS – 9 years ago

@Berend Note, you are using Windows Batch, not DOS Batch. The string manipulation function is added in Windows, not DOS. – stevefestl – 7 years ago

1

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.

Toby Speight

Posted 9 years ago

Reputation: 5 058

1

Javascript, 3 bytes!

1e5

Returns 100000. Y'all JS golfers are overthinking it!

Mama Fun Roll

Posted 9 years ago

Reputation: 7 234

After bashing my head on the wall for several hours I managed to come up with a even shorter pure JS solution: http://codegolf.stackexchange.com/a/60082/21830

– Unihedron – 9 years ago

1

POSIX bc, 4 bytes

10^7

This creates the output 10000000.

awd123

Posted 9 years ago

Reputation: 21

1

CJam, 1 byte

A

Prints 10. Very straightforward.

Mama Fun Roll

Posted 9 years ago

Reputation: 7 234

1

[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]

Florrie

Posted 9 years ago

Reputation: 831

1It's standard for input to mean STDIN or a function argument. – lirtosiast – 9 years ago

1

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.

mroman

Posted 9 years ago

Reputation: 1 382

Does your bonus version have a default value? – Titus – 8 years ago

No. ri just converts a string to integer. – mroman – 8 years ago

1

Minkolang 0.9, 11-25 = -14 bytes

This language was created after this challenge, but not for it.

nd1+?2["d].

Try it here.

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.

El'endia Starman

Posted 9 years ago

Reputation: 14 504

1

Perl 6, 3 points

say 'a'x 21 # 11
# say adds a newline
print 'a'x 28*(@*ARGS[0]//2)
# 28 - 25 = 3

Brad Gilbert b2gills

Posted 9 years ago

Reputation: 12 713

1

Sass, 30 bytes

codegolf is absolutely awesome

if you try to compile this with sass the result is the following error

Invalid CSS after "...olutely awesome": expected "{", was "" 
/* 60 bytes */

Fabrizio Calderan

Posted 9 years ago

Reputation: 470

I get invalid top-level expression on line 1 at column 1, but I also don't think this is a language as it's not turing-complete and it only compiles to CSS. – cat – 9 years ago

@cat I'm pretty sure I could implement /// in Sass using just string manipulation and a while loop, and /// is turing complete. – Sparr – 9 years ago

@Sparr fair enough – cat – 9 years ago

1

PlatyPar, 1 byte

#

# starts a number, but since no number is found after it, it is substituted with 59. Here's a "real" answer:

77^

Prints the result of 7^7, or 823543, which is of length 6.

Try it online!

Cyoce

Posted 9 years ago

Reputation: 2 690

1

Z80 machine code, 16 bytes

3E 1F 0E 02 1E 2A F5 CD 05 00 F1 3D F2 02 01 C7

This was made on an Osborne Executive running CP/M version 3.0 using SID. Here is a disassembly (with comments following # characters for readability)

MVI A,1F     # Set register A equal to 0x1F (iterations-1)
MVI C,2      # Write is BDOS call 2 (CP/M's system calls)
MVI E,2a     # I'm writing '*' as output. Its ASCII value is 0x2a
PUSH PSW     # Push operates on register pairs. This pair contains A.
CALL 5       # Do the BDOS call (which destroys some registers)
POP PSW      # But we can get A back from the stack.
DCR A        # Decrement the loop counter
JP 102       # If last result is non-negative, go to address 0x102
RST 0        # Otherwise, exit

All programs are loaded at a fixed address of 0x100, so the jump to 0x102 is well-defined. After running this, CP/M wants to print a newline character. If we count that as output from the program, change the second byte from 1F to 1E.

Fox

Posted 9 years ago

Reputation: 341

1

Fuzzy Octo Guacamole, 8 bytes

42*![o;]

Also could use:

8  ![o;]

Or

81*![o;]

But that is cooler.

Prints 8 "8"s and 8 newlines, including a trailing one.

Explanation:

4: Push 4 to the stack.

2: Push 2 to the stack.

*: Pop and multiply the top 2 items on the stack and push the result (8)

!: Set the loop counter to the top. Is now 8.

[: Start a loop that lasts 'loopcounter' (8) iterations.

o: Peek at the top of the stack and push it to the temp variable.

;: Print the temp var.

]: End the loop.

Rɪᴋᴇʀ

Posted 9 years ago

Reputation: 7 410

1

Java, 90 bytes

class T{public static void main(String[]a){for(int i:new int[90])System.out.print("##");}}

HyperNeutrino

Posted 9 years ago

Reputation: 26 575

1

Pylongolf, 2 bytes

.;

. - Reset the stack
; - Debugally print both the stack and the variables.

The interpreter I use prints debugally by converting an 2 arrays into a string which has that string begin with [ and end with ] which prints:

[][]

user47018

Posted 9 years ago

Reputation:

1

Labyrinth, 10 bytes - 25 = -15

Another Labyrinth collaboration with Sp3000.

?02
`\
~"@

This prints 10n linefeeds to STDOUT.

Try it online!

Explanation

The most interesting part is probably how the default value of 2 is handled.

If an input number is given, the following code is executed:

?   Read integer from STDIN.
0   Multiply by 10. This is because digits in Labyrinth work by multiplying the top of
    the stack by 10 and then adding themselves, such that multi-digit numbers can be
    written into the code more easily.
    The top of the stack is now positive (and contains the number of characters to be
    printed) so the instruction pointer (IP) turns right/south towards the \.

If no input number is given, ? pushes a 0 instead, and this happens:

?   Push 0.
0   Multiply by 10, which is still 0. Since the top of the stack is now 0, the IP
    keeps moving forward/east instead.
2   Multiply by 10, add 2, which sets the top of the stack to 2. The IP hits a
    dead end so it turns around.
0   Multiply by 10 to give 20. Now the top of the stack is positive and IP
    turns left/south towards the \. Again, the top of the stack is the number
    of characters to be printed.

Now all we need to do is print one character each while decrementing the top of the stack to zero. The cheapest character to be printed in Labyrinth is a linefeed, because \ prints one without affecting the stack at all. As an additional trick, we decrement via multiply by -1, bitwise NOT, to ensure that the top of the stack is negative in the top left corner of the loop (otherwise the IP would move towards the ? again).

The loop is then simply:

\   Print linefeed.
`   Multiply by -1.
~   Bitwise NOT.
"   No-op. This cell acts a junction. While the top of the stack is positive
    the IP will turn left/north, otherwise it will move forward/east.

When the IP leaves the loop it hits the @ which terminates the program.


For completeness, here are also two 7-byte versions without the bonus:

7:(
@`!

prints

-7-6-5-4-3-2-1

Try it online!

And

>11!:
@

prints

11001011111011

Try it online!

The former is a very simply (but compact) loop which prints -n while decrementing n from 7 down to 0.

The latter is a simple modification of Sp3000's solution to this challenge (which makes the execution a little bit crazier though).

Martin Ender

Posted 9 years ago

Reputation: 184 808

1

Hexagony, 6 bytes

o!!!!@

Prints

111111111111

Try it online!

Explanation

Probably one of the simplest Hexagony programs I've written. The unfolded code is

 o !
! ! !
 @ .

and is simply executed in reading order. o sets the current memory edge to 111 (any letter from d to z would do). Then the ! print that four times and @ terminates the program.

I might try for the bonus later, but I have some doubts that it will fit in side-length 4 (and side-length 5 might end up costing more than the bonus gives).

Martin Ender

Posted 9 years ago

Reputation: 184 808

How about this? TIO

– Adyrem – 7 years ago

@Adyrem That only works if measured in characters (whereas the challenge requires counting bytes). And by the time you get to 5-digit code points (in order to fix that), UTF-8 requires 3 bytes for the character. – Martin Ender – 7 years ago

1

APL, 3 bytes

1e5

Print 100000...

TuxCrafting

Posted 9 years ago

Reputation: 4 547

1

dc, 7 bytes

2oFddnf

2o         Set the output radix to 2: write to stdout using the binary digits [01]
  F        Push 0xF on the stack, equivalent to 1111b
   dd      Duplicate the top-of-stack, then duplicate the top-of-stack: 1111b, 1111b, 1111b
     n     Pop the topmost item from the stack (1111b) and write it (using binary, per
               the above) to stdout. Do not follow with a newline.
      f    Dump the contents of the stack (1111b, 1111b), following each item with a
               newline.

Visible characters comprise 12 bytes; add two (2) newlines for a total of 14.

Edit: Since I'm the only dc answer with a natural number for a score, why not post the following?

dc, 8 bytes

cccccccP

Clears the stack seven times, then attempts to pop the top (non-existent) value and print it as text (i.e., a number with output-radix UCHAR_MAX+1). Since the stack is empty, this results in a fifteen-byte error message followed by a single newline. (Works for GNU dc 1.2)

Joe

Posted 9 years ago

Reputation: 895

Hello, and welcome to PPCG! This is a cool answer. Can you explain what exactly o, F, et cetera do? – NoOneIsHere – 8 years ago

1

PD, 204 bytes

#N canvas 1 7 1 1 1;
#X obj 1 6 loadbang;
#X msg 1 1 \; pd quit;
#X obj 2 5 print;
#X obj 2 2 metro 10;
#X obj 1 7 del 340;
#X connect 0 0 3 0;
#X connect 0 0 4 0;
#X connect 3 0 2 0;
#X connect 4 0 1 0;

run with pd -nogui patchname.pd 2>&1. The program will print the String print: bang (12 bytes including the newline) every 10ms. Then the program terminates after 340ms which will result in the string being printed 34 times (34 * 12 = 408 Bytes output).

Simon

Posted 9 years ago

Reputation: 141

1

Ruby, 24 bytes (with bonus)

->m{m.to_i.times {49.times {print "a"}}}[gets||2]

dkudriavtsev

Posted 9 years ago

Reputation: 5 781

Did you try that with input? Assignments have a lower precedence than the ternary operator, so you probably should add parentheses.

– Titus – 8 years ago

Hmm ... can you use gets||2?

– Titus – 8 years ago

1

Python, 24-25= 0 -1 bytes

print'a'*int(input())*24

It takes input, converts it to an integer, multiplies it by 24 (the length of my code) and multiplies the character a by it

Thanks to @EamonOlive for reducing 1 byte

vikarjramun

Posted 9 years ago

Reputation: 794

1You can eliminate the space between the print and the '. You would also have to change the 25 to a 24. – Post Rock Garf Hunter – 8 years ago

@EamonOlive I didn't know you could remove the space! Thanks for the tip – vikarjramun – 8 years ago

It looks as if you may have forgotten to make the change, the space is still there. – Post Rock Garf Hunter – 8 years ago

@EamonOlive I did everything I intended to except remove the space - thanks for pointing it out! :) – vikarjramun – 8 years ago

Is there a default value? – Titus – 8 years ago

1

Cubix, 10 bytes

Cubix is a 2D esolang with a twist: the source code is wrapped around the outside of a cube.

>..(NU@?O/

Test it online! This maps to the following cube:

    > .
    . (
N U @ ? O / . .
. . . . . . . .
    . .
    . .

The output is

10998877665544332211

Don't even ask how it works... though if you'd like to watch it in action, run it here.

ETHproductions

Posted 9 years ago

Reputation: 47 880

1

05AB1E, 7 - 25 = -18 bytes

Saved a byte thanks to Okx.

YI7*ð×?

Try it online!

Explanation

Y       # push 2
 I      # push input
  7*    # multiply top of stack with 6 (program length)
    ð×  # repeat <space> that many times
      ? # print top of stack

Emigna

Posted 9 years ago

Reputation: 50 798

Save 1 byte by using YI7*Xs×. There is no need to reverse the stack. – Okx – 8 years ago

@Okx: Good catch. Thanks! – Emigna – 8 years ago

Your current code will print the correct amount of spaces and then a newline :/ – Okx – 8 years ago

@Okx: True. I'm too used to trailing newlines being acceptable. Fixed now :) – Emigna – 8 years ago

@Okx: The Y is there to handle empty input (which should default to 2). – Emigna – 8 years ago

0

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.

steenbergh

Posted 9 years ago

Reputation: 7 772

1Where is the default value? – Titus – 8 years ago

@Titus Hm, missed that bit. Fixed. – steenbergh – 8 years ago

0

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.

Jimmy Johnson

Posted 9 years ago

Reputation: 71

0

TI-Basic, -2 bytes

:Input N
:".
:While N23>length(Ans
:Ans+".
:End
:Ans

Julian Lachniet

Posted 9 years ago

Reputation: 3 216

Where is the default value? – Titus – 8 years ago

TI-Basic doesn't accept empty input. – Julian Lachniet – 8 years ago

0

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.

Zavada

Posted 9 years ago

Reputation: 189

0

Kitanai, 35 bytes

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

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

Sygmei

Posted 9 years ago

Reputation: 1 137

0

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.)

P. Ktinos

Posted 9 years ago

Reputation: 2 742

0

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');
    }
}

cookie

Posted 9 years ago

Reputation: 271

0

ForceLang, 13 bytes

io.write 1e25

SuperJedi224

Posted 9 years ago

Reputation: 11 342

0

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!

Martin Ender

Posted 9 years ago

Reputation: 184 808

0

J, 2 bytes

!7

Prints 7 fatorial, or 5040.

If you include the trailing newline then use:

!6

Which would print 720.

Bijan

Posted 9 years ago

Reputation: 781

0

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.

zgrep

Posted 9 years ago

Reputation: 1 291

0

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!

Beta Decay

Posted 9 years ago

Reputation: 21 478

0

Braingolf, (9 - 25) = -16 bytes

91+<9*1-^

Takes n input and outputs a 1 followed by x zeroes where x = (n * 9) - 1

Both of these are non-competing

Braingolf, 5 bytes

91+9^

Outputs 1000000000 (10**9)

Skidsdev

Posted 9 years ago

Reputation: 9 656

This is non-competing. – Erik the Outgolfer – 8 years ago

0

Powershell 4 Bytes

,1*8

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

Sivaprasath Vadivel

Posted 9 years ago

Reputation: 139

0

REXX 33 Bytes -25 = 8

say copies("x",max(2,"0"arg(1))*33)

theblitz

Posted 9 years ago

Reputation: 1 201

0

Pari/GP, 2 bytes

7!

Prints 5040 in the REPL.

alephalpha

Posted 9 years ago

Reputation: 23 988

0

Christopher

Posted 9 years ago

Reputation: 3 428

No longer works, so you need to use this instead

– ASCII-only – 7 years ago

0

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

Beta Decay

Posted 9 years ago

Reputation: 21 478

0

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.

Esolanging Fruit

Posted 9 years ago

Reputation: 13 542

0

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.

Fedone

Posted 9 years ago

Reputation: 157

0

Implicit, 1 byte

a

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

MD XF

Posted 9 years ago

Reputation: 11 605

0

TI-BASIC, -20 bytes

10^(5Ans-1

As Julian Lachniet mentioned in a comment on his answer, TI-BASIC does not accept empty input, so I guess this is TECHNICALLY 5 bytes.

Note that 10^( is only one byte, as is Ans.

All this does is print a power of ten with 5Ans digits.

Khuldraeseth na'Barya

Posted 9 years ago

Reputation: 2 608

0

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

jq170727

Posted 9 years ago

Reputation: 411

0

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".

ATaco

Posted 9 years ago

Reputation: 7 898

0

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

Jo King

Posted 9 years ago

Reputation: 38 234

0

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)

Yair Rand

Posted 9 years ago

Reputation: 381

0

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.

Bubbler

Posted 9 years ago

Reputation: 16 616

0

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.

Ciaran_McCarthy

Posted 9 years ago

Reputation: 689

0

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?

l4m2

Posted 9 years ago

Reputation: 5 985

@JoKing well so the other few Javascript answera are wrong ... – l4m2 – 7 years ago

0

Ruby, 18 Bytes

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

36.times{print"a"}

Windmill Cookies

Posted 9 years ago

Reputation: 601

0

Wolfram Language (Mathematica), 17 bytes - 25 = -8

Echo[10^(17#-5)]&

Try it online!

Assuming giving a function is OK. Prints >> 1, then (17 * input - 5) 0s, then a trailing new line, thus making the output 17 * input bytes long.

Shieru Asakoto

Posted 9 years ago

Reputation: 4 445

0

Gol><>, 8 - 25 = -17 bytes

IE28*Rn;

Try it online!

Outputs all 0s.

Explanation:

I        Get inputted number
 E2      Push 2 if no input
   8*    Multiply by 8  (length of code)
     Rn  Print 0 that many times
       ; Halt

Without bonus, 4 bytes

"D;

Try it online!

Outputs [68 59]. Note that both input and output have a trailing newline.

Jo King

Posted 9 years ago

Reputation: 38 234

0

Python3 Shell version

'2'*10

outputs:'2222222222'

Whalalalalalala CHen

Posted 9 years ago

Reputation: 337

3I think the language name you're looking for is Python 3 REPL. Also, your output is only 10 bytes long while the program is 6 bytes – Jo King – 6 years ago

0

Ahead, 4 bytes

8kO@

Prints 00000000.

8k    8 times...
  O   ..pop and print number
   @  end

Try it online!

snail_

Posted 9 years ago

Reputation: 1 982

0

Ahead, 6 - 25 = -19 bytes

Here it is with the bonus.

I6*kO@

I       Read number from stdin
 6*      multiply by 6
   k    I*6 times...
    O   ...pop and print number
     @  end

Try it online!

snail_

Posted 9 years ago

Reputation: 1 982

This doesn't print 2*bytes for no input – Jo King – 6 years ago

0

Java, 234 - 25 = 209 bytes

import java.io.*;interface A{static void main(String a[])throws Exception{InputStream i=new FileInputStream("A.java");byte[]b=new byte[1];for(int l;(l=i.read(b))!=-1;)for(int n=0;n<Integer.parseInt(a[0]);n++)System.out.write(b,0,l);}}

Formatted :

import java.io.*;
interface A {
    static void main(String a[]) throws Exception {
        InputStream i = new FileInputStream("A.java");
        byte[] b = new byte[1];
        for (int l; (l = i.read(b)) != -1; )
            for (int n = 0; n < Integer.parseInt(a[0]); n++)
                System.out.write(b, 0, l);
    }
}

Amir M

Posted 9 years ago

Reputation: 1

Is it really worth it to have all the input stuff for a mere -25 bytes? – Jo King – 6 years ago

@JoKing No, not really. There are shorter answers, but this shows a different point of view. Also, this has no hard-coded program length. – Amir M – 6 years ago

@AmirM Isn't reading the source code a standard loophole? – NieDzejkob – 6 years ago

@NieDzejkob This isn't a [tag:quine] question – Jo King – 6 years ago

0

C# (Visual C# Interactive Compiler), 17 16 bytes

Write($"{0,32}")

Thanks to Jo King for saving one byte!

Try it online!

Embodiment of Ignorance

Posted 9 years ago

Reputation: 7 014

@JoKing Thanks, I keep forgetting that the interactive compiler doesn't need semicolons at the last statement – Embodiment of Ignorance – 6 years ago

0

SNOBOL4 (CSNOBOL4), 58 bytes - 25 = 33

	N =INPUT
O	OUTPUT =1
	X =LT(X,N * 29 - 1) X + 1	:S(O)
END

Try it online!

Giuseppe

Posted 9 years ago

Reputation: 21 077

0

MIPS, 58 bytes

main:li $v0,1
li $a0,63
l:sub $a0,$a0,1
syscall
bnez $a0,l

Try it online!

A counter loop that prints the count on each pass without spaces or a trailing newline.

Bsoned

Posted 9 years ago

Reputation: 31

50 – ASCII-only – 6 years ago

0

Perl 6 (8 bytes)

say 1e14

Perl 6 (with challenge, 27 bytes - 25 = 2)

print "a"x(@*ARGS[0]//2)*27

bb94

Posted 9 years ago

Reputation: 1 831

0

Tamsin, 40 bytes

main='aaaaaaaaaaaaaaaa'->T&''+T+T+T+T+T.

Try it online!

Outputs 80 of the character a.

Esolanging Fruit

Posted 9 years ago

Reputation: 13 542

0

Java, 86 bytes

Prints 172 (86*2 = 172) null bytes to STDOUT

interface A{static void main(String[]a){System.out.print(new String(new char[172]));}}

Try it online!

Benjamin Urquhart

Posted 9 years ago

Reputation: 1 262

0

ink, 1 byte

s

Try it online!

Outputs s and a newline for a total of two characters.

Sara J

Posted 9 years ago

Reputation: 2 576

0

Brainfuck, -5 bytes

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

Input is provided in binary.

Similar to anatolyg's solution, this program corresponds to the minimal solution of a*b=10+a+b+c.

orthoplex

Posted 9 years ago

Reputation: 339

0

C++ (gcc)

without bonus: 57 bytes

#include<cstdio>
int main(){for(int i=57;i--;)puts("x");}

Try it online!

with bonus: 77 bytes (= Score 52)

#include<cstdio>
int main(){int i;scanf("%i",&i);for(i*=77;i--;)putchar(46);}

Try it online!

movatica

Posted 9 years ago

Reputation: 635

0

Clam, 4 bytes

p^97

Try it online!

Not very interesting.

Outputs 4782969 followed by a newline

Explanation:

p      - Print next token's value
 ^     - Exponent operator on next 2 tokens
  9    - Literal 9
   7   - Literal 7

9^7 = 4782969

Skidsdev

Posted 9 years ago

Reputation: 9 656

0

Python 3, 37 14 bytes

print('a'*27)

Saksham Jain

Posted 9 years ago

Reputation: 11

1You should consider adding an explanation or link to an online interpreter to your answer. See other answers for examples. If you answer only with code, it will automatically be flagged as low-quality. – mbomb007 – 6 years ago

0

Python 2, 12 Bytes

print 18**19

Outputs 708235345355337676357632 which is 24 characters.

Matthew Anderson

Posted 9 years ago

Reputation: 131

0

33, 8 bytes

13c1[mo]

Prints 1211109876543210, which is 16 bytes long

TheOnlyMrCat

Posted 9 years ago

Reputation: 1 079

0

Underload, 10 bytes

()aaaaa:*S

I'm pretty sure this is unimprovable, since I made a python script to test all possible combinations of instructions. However, I did only include the instructions a:*S in it, and made it so it always starts with (), so there could be a crazy solution involving ^ or ~. Also, for those curious, there are actually 5 other valid 10 byte solutions:

()aaaaa:SS
()aa:a*:*S
()aa:a*:SS
()aa:*a:*S
()aa:*a:SS

Try it Online

EdgyNerd

Posted 9 years ago

Reputation: 1 106

I've checked and there isn't any possible output using ^ or ~. – None – 5 years ago

Oh ok, also, I might be able to get rid of the S and just leave the result on the stack to save a byte, but I'm not sure what the meta rules are on leaving stuff on the stack instead of printing – EdgyNerd – 5 years ago

0

Stax, 16 bytes - 25 = -9

|?xx{{dqF}{dqq}?

Run and debug it

Uses Stax's sneaky |? command, which means that the output is also 2 quines (or any other input number)

However, one downside is the fact that I can't use packed stax, as the |? operation prints out unpacked source code, even if the source is packed

user89655

Posted 9 years ago

Reputation: 31

0

APL (Dyalog Classic), 5 bytes

⎕←1e9

Try it online!

Explanation

Not very interesting... but I hope this hasn't been posted before.

   1e9 ⍝ This returns the constant 1000000000
⎕←    ⍝ Move this to the output buffer

user85052

Posted 9 years ago

Reputation:

0

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

Pseudo Nym

Posted 9 years ago

Reputation: 181

My mistake. I thought for the bonus it would always take input. I'll edit to account for that. – Pseudo Nym – 5 years ago

It's been fixed. – Pseudo Nym – 5 years ago

0

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*

user85052

Posted 9 years ago

Reputation:

0

Python 3.4, 14 13 bytes

print("a"*26)

user45510

Posted 9 years ago

Reputation:

This is only 13 bytes. Which makes your score 41 (13 + 28). You can lose two points by changing 28 to 26. – Zach Gates – 9 years ago

Did you think about say()? – Titus – 8 years ago

0

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

clap

Posted 9 years ago

Reputation: 834

For the bonus, if no input is provided, it should default to 2. – Dennis – 9 years ago

Yup, just noticed that. Fixed. – clap – 9 years ago

0

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)}

Fabian Schmengler

Posted 9 years ago

Reputation: 1 972

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. – daniero – 9 years ago

0

C#, 63 62 bytes

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

Will print 123 spaces followed by 1.

Lucas Trzesniewski

Posted 9 years ago

Reputation: 101

How does this work? – LegionMammal978 – 9 years ago

@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.

– Lucas Trzesniewski – 9 years ago

0

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).

Nathan McKinley-Pace

Posted 9 years ago

Reputation: 1

0

><>, (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.

Sp3000

Posted 9 years ago

Reputation: 58 729

0

Ruby, 5 bytes

p 1e6

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

CocoaBean

Posted 9 years ago

Reputation: 309

0

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.

Ilmari Karonen

Posted 9 years ago

Reputation: 19 513

0

Brainfuck, 25 bytes

Prints 50 characters, most of which are control characters.

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

Hand-E-Food

Posted 9 years ago

Reputation: 7 912

0

Powershell, -10

"a"*15*$args[0]

Powershell, 2

This answer without the bonus is probably golfier though

$?

Outputs;

True

tomkandy

Posted 9 years ago

Reputation: 167

@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 – Jonathan Leech-Pepin – 9 years ago

@JonathanLeech-Pepin No - that won't work, either, for the same reason. See my corrected answer

– AdmBorkBork – 9 years ago

@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. – Jonathan Leech-Pepin – 9 years ago

@JonathanLeech-Pepin Let's continue this discussion in chat

– AdmBorkBork – 9 years ago

Also, if given no input, it should default to 2. – LegionMammal978 – 9 years ago

This entry does not qualify for the bonus since it does not handle the constraint: "If no input is provided, n must default to 2." – Bevo – 8 years ago

0

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

Toby Speight

Posted 9 years ago

Reputation: 5 058

It took a bit of trial and error to settle on 85 for 40; I had 533 and 73*2 as a couple of early attempts. – Toby Speight – 9 years ago

0

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"

Blckknght

Posted 9 years ago

Reputation: 701

0

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

user41805

Posted 9 years ago

Reputation: 16 320

I count 31 bytes of code ;) – Titus – 8 years ago

@Titus Haha, thanks for noticing that :) – user41805 – 8 years ago

0

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.

Thomas Weller

Posted 9 years ago

Reputation: 1 925

@ThomasKwa: fixed it by providing a different solution. – Thomas Weller – 9 years ago

0

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.

marinus

Posted 9 years ago

Reputation: 30 224

0

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

Jacob Misirian

Posted 9 years ago

Reputation: 737

I thought extra whitespaces are not allowed? – Leaky Nun – 9 years ago

0

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?

Conor O'Brien

Posted 9 years ago

Reputation: 36 228

0

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

cat

Posted 9 years ago

Reputation: 4 989

0

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.

isaacg

Posted 9 years ago

Reputation: 39 268

0

Perl, 11 bytes

print"J"x22

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

ASCIIThenANSI

Posted 9 years ago

Reputation: 1 935

0

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.

ASCIIThenANSI

Posted 9 years ago

Reputation: 1 935

the question doesn't say assuming a REPL environment is disallowed, so 'M'*input()*14 is shorter for 14 == -11 – cat – 9 years ago

1@cat Thanks, I'll add that in now. – ASCIIThenANSI – 9 years ago

2If no input is provided, you must default to 2. This does not. – isaacg – 9 years ago

0

MATLAB, 5 bytes

a=123

Which displays

a =
   123

By my count that is 10 bytes of output if you include the new-line as 1 byte.

Tom Carpenter

Posted 9 years ago

Reputation: 3 990

0

Binary-Encoded Golfical, 13+1 (-x flag)=14 bytes

Noncompeting, language postdates the question.

Hexdump:

00 90 01 00 09 17 17 17 17 17 17 17 1D

This encoding can be converted back into the original graphical representation using the included Encoder utility, or run directly by adding the x flag.

Original image:

enter image description here

Magnified 64x, with color labels:

enter image description here

Explanation: Stores 9, prints it seven times (with a newline each time), then turns around and prints it seven more times.

SuperJedi224

Posted 9 years ago

Reputation: 11 342

0

Mumps, 31 - 25 = 6 bytes

My submission was supposed to be unique (but I hadn't checked all of the answers yet) in that the basic "Assume 2x" code and the bonus-enabled code would work out to be the same length!

Basic code:

F J=1:1:28 W 1

Which is 14 bytes.

Here's the initial bonus-enabled code that takes input, anything that equates to '0' including any non-numeric input assumes 2, then outputs the correct number of output characters. This version is 39 bytes not including the bonus.

R I S:+I=0 I=2 F I=1:1:I F J=1:1:39 W 1

Calculating the bonus 39-25=14 bytes as well!

Too bad (for my narrative) that I looked it over and came up with a shorter version of the bonus code:

R I S:+I=0 I=2 F I=1:1:I*31 W 1

This is only 31 bytes long, so 31-25=6 bytes total, and the header reflects this.

zmerch

Posted 9 years ago

Reputation: 541

0

Mathematica, 9 bytes

Echo[16!]

If I am correct, this should output:

>> 20922789888000

with a trailing newline.

LegionMammal978

Posted 9 years ago

Reputation: 15 731

0

Gogh, 3 bytes

6GJ

You can run it like this:

./gogh o '6GJ'

Or without implicit output (4 bytes):

8GJ¡

You can run this using:

./gogh "" "8GJ¡"

The inverted exclamation point outputs the TOS.


Explanation

6    “ Push the integer literal 6 ”
G    “ Push a range (0, TOS]      ”
J    “ Join the TOS               ”

Zach Gates

Posted 9 years ago

Reputation: 6 152

0

Python 2, 11 bytes

print`0`*21

This outputs 21 zeroes and a newline.

000000000000000000000


From the Python 2 documentation:

A '\n' character is written at the end, unless the print statement ends with a comma.

Zach Gates

Posted 9 years ago

Reputation: 6 152

0

Cubix, 15 bytes

Non competing due to language age.

While having some fun with @ETHproductions language, I thought this would be interesting. It turned out a little longer than I thought it would and I'm sure it can be improved.

(.O.NU.\!@O$..u

This maps to a cube with edge length 2

    ( .
    O .
N U . \ ! @ O $
. . u . . . . .
    . .
    . .

Outputs

109998887776665554443332221110

N push 10 to the stack
U turn left moved forward turn left
O output number of TOS
$ skip a no op
( decrement TOS, followed by a number of no ops
u turn right, move forward and turn right, more no ops
O output number of TOS, more no ops
\ reflect to the east
! jump end program @ if truthy
O output number of TOS
$ skip N at start of program

MickyT

Posted 9 years ago

Reputation: 11 735

0

Lua, 20 bytes (bonus: 11 bytes)

Program:

print(("a"):rep(40))

Output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

(Change 40 to 39 if newline is counted)

Bonus:

print(("a"):rep(36*(io.read()or 2)))

(If newline is counted, use print(("a"):rep(38*(io.read()or 2)-1)) [13 bytes] instead.)

Leaky Nun

Posted 9 years ago

Reputation: 45 011

Welcome to PPCG! Usually, our community does not like storing input in variables beforehand. It would be better accepted to read from STDIN. – GamrCorps – 9 years ago

0

Underload, 12 bytes

(\/)a:*::**S

Outputs

(\/)(\/)(\/)(\/)(\/)(\/)

Try It Online

Explanation

(\/)            # push \/ to the stack        : \/
    a           # add brackets to TOS         : (\/)
     :*         # duplicate the TOS and join. : (\/)(\/)
       ::       # duplicate a couple of times : (\/)(\/)<>(\/)(\/)<>(\/)(\/)
         **     # join stack items            : (\/)(\/)(\/)(\/)(\/)(\/)
           S    # output TOS

MickyT

Posted 9 years ago

Reputation: 11 735

0

Tellurium, 10 bytes

µa~Åm16.

Outputs a 16 times. Simple enough.

More detailed explanation:

µ         Begins reading a string
a
~         Stops reading a string and stores it in the selected cell
Å         Command set 2
m         Print the cell's value n times
16
.

There might be a shorter version using Åw but I'm too tired to do that :P

m654

Posted 9 years ago

Reputation: 765

0

Java, 85

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

HopefullyHelpful

Posted 9 years ago

Reputation: 208

0

Perl5, 11 bytes

x is string repetition operator

print 1x22

Byeonggon Lee

Posted 9 years ago

Reputation: 419

That's only 10 bytes, and you can use 'say' to cut down on two more (run with -M5.010 flag which is free) – Gabriel Benamy – 8 years ago

0

BASH, 19 bytes

54 bytes -25 bonus. Using the variable input for x repeats:

#!/bin/sh
a=$1;for i in `seq 1 ${a:=2}`;do cat $0;done

similar but more readable:

#!/bin/sh
a=$1
for i in `seq 1 ${a:=2}`; do
 cat $0
done

19 bytes for a simple sh script.

#!/bin/sh
cat $0 $0

CousinCocaine

Posted 9 years ago

Reputation: 1 572

Personally I dislike `backticks` a lot, but it saves 1 char. – CousinCocaine – 8 years ago

1DARN, "No file/disk/network io allowed", therefor I exclude this answer from the competition. – CousinCocaine – 8 years ago

0

Turtlèd, 8 bytes (non-competing)

15:[*,l]

explanation:

[implicit] initial cell is *, initial char var is *
15       put 15 in register
  :      move right by as many cells as the amount in register
   [*  ] while cell not *
     ,l  write char var, move left 1 cell

Destructible Lemon

Posted 9 years ago

Reputation: 5 908

0

Nim, 27 bytes

echo getStackTrace()[0..51]

Prints the first 53 bytes of the following, plus a trailing newline:

Traceback (most recent call last)
<filename>.nim(1)       <filename>

Note that despite having the filename in the output, this answer's validity is not dependant on the length of the filename. For example, saved in x.nim, this is output:

Traceback (most recent call last)
x.nim(1)         

There are nine trailing spaces there. Conversely, when saved in areallylongfilename.nim, this is output:

Traceback (most recent call last)
areallylongfilena

Newlines are also output in each example. Example usage:

$ nim c length.nim
$ ./length | wc -c
54

Copper

Posted 9 years ago

Reputation: 3 684

0

Scala, 52 - 25 = 27 bytes

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

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

corvus_192

Posted 9 years ago

Reputation: 1 889

0

s-lang, 30 bytes

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

Link

Erik the Outgolfer

Posted 9 years ago

Reputation: 38 134