106
\$\begingroup\$

The Challenge

Write a complete program that writes twice as many bytes to standard output as the length of the program.

Rules

  • The program must write ASCII characters to the standard output.

  • The contents of the output doesn't matter.

  • The output, measured in bytes, must be exactly twice the length of the program, also measured in bytes, unless you fulfill the bonus.

  • Any trailing newline is included in the output's byte count.

Bonus

Your program can optionally take a number, n, as input. If so, the output must be exactly n * program length bytes. You can assume that n will always be a positive integer. If no input is provided, n must default to 2.

If you do this, you can subtract 25 bytes from your score.

Shortest program wins.

Restrictions

  • No standard loopholes.

  • The program must be at least 1 byte long.

  • No adding unnecessary whitespace to the source code to change its length. Similarly, comments don't count.

  • Unless you fulfill the bonus, the program must accept no input. If you do fulfill the bonus, the integer must be the only input.

Lowest score (program length in bytes - bonus) wins.

The shortest answer for each language wins for that language.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=59436,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\-?\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

Jo King
48.1k6 gold badges130 silver badges187 bronze badges
asked Oct 2, 2015 at 23:14
\$\endgroup\$
25
  • 1
    \$\begingroup\$ For the bonus, does the output have to be exactly n * program length bytes, or is that a minimum? \$\endgroup\$ Commented Oct 2, 2015 at 23:19
  • 2
    \$\begingroup\$ It has to be exact \$\endgroup\$ Commented Oct 2, 2015 at 23:20
  • 3
    \$\begingroup\$ Looks like the code snippet has to be modified to handle negative scores. \$\endgroup\$ Commented Oct 2, 2015 at 23:49
  • 46
    \$\begingroup\$ A bonus of -25 is basically mandatory for some languages, since it lets them achieve a negative score. In the future, I'd suggest using a percent bonus, or just making the bonus the question if you really want answers to go for it. Or, just don't have a bonus. \$\endgroup\$ Commented Oct 2, 2015 at 23:58
  • 4
    \$\begingroup\$ For "no input is provided", do we assume the empty string is passed in? I can't see how one would deal with the user never typing in an input and the program just waiting. \$\endgroup\$ Commented Oct 2, 2015 at 23:59

312 Answers 312

1 2 3
4
5
...
11
2
\$\begingroup\$

LibreLogo, 21 bytes

Code:

input_half_the_length

Result:

Unknown name: ‘input_half_the_length".

enter image description here

answered Oct 14, 2017 at 3:19
\$\endgroup\$
2
\$\begingroup\$

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

Uses one function named ab

ab

function ab
tp @e ~0 ~0 ~0

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

answered May 27, 2018 at 23:29
\$\endgroup\$
2
\$\begingroup\$

Perl 5, 17 - 25 = -8

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

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

Try it online!

answered Jun 1, 2018 at 16:03
\$\endgroup\$
2
\$\begingroup\$

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

1j8w

Try it online!

 w Print
1 the digit 1 (could be any digit other than 0)
 j repeated
 8 eight times.
answered Mar 5, 2019 at 20:27
\$\endgroup\$
2
\$\begingroup\$

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

answered Mar 5, 2019 at 21:07
\$\endgroup\$
2
\$\begingroup\$

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

answered Apr 1, 2019 at 1:18
\$\endgroup\$
1
  • \$\begingroup\$ Also also note that both versions which take input can't handle not taking input and are thus invalid. \$\endgroup\$ Commented Apr 1, 2019 at 18:04
2
\$\begingroup\$

Boolfuck, 21 bytes

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

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

Here is a hexdump of the output:

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

Try it online!

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

answered Apr 5, 2019 at 14:14
\$\endgroup\$
2
\$\begingroup\$

Guile (5)

"oof" outputs 1ドル = "oof"

answered Apr 9, 2019 at 15:36
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Hello, welcome to PPCG! \$\endgroup\$ Commented Apr 9, 2019 at 17:28
2
\$\begingroup\$

Bash, 10 bytes

yes|head -

outputs 10 lines of ys for 20 total bytes output.

answered Apr 30, 2019 at 17:50
\$\endgroup\$
2
\$\begingroup\$

MathGolf, 2 bytes

7!

Outputs 5040, which is 4 bytes.

Try it online!

maxb
7,0173 gold badges33 silver badges41 bronze badges
answered Jul 29, 2019 at 18:21
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Congratulations 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). \$\endgroup\$ Commented Aug 6, 2019 at 5:26
2
\$\begingroup\$

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

answered Aug 14, 2019 at 13:30
\$\endgroup\$
2
\$\begingroup\$

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./<
answered May 6, 2019 at 14:47
\$\endgroup\$
2
\$\begingroup\$

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
answered Dec 9, 2019 at 18:04
\$\endgroup\$
0
2
\$\begingroup\$

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*
answered Jan 10, 2020 at 10:12
\$\endgroup\$
2
\$\begingroup\$

Flurry, 28 bytes, no bonus

({<(({})){}{}>})({}){({})}{}

Verification

$ echo -n "({<(({})){}{}>})({}){({})}{}" | wc -c
28
$ ./flurry -iin -c "({<(({})){}{}>})({}){({})}{}"
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3
$ ./flurry -iin -c "({<(({})){}{}>})({}){({})}{}" | wc -c
56

Uses 3 ** 3 = 27, and enables both stack output and return value output so that 3 is printed 27 + 1 times.

(
 {<(({})){}{}>} Literal 3
) Push and return 3
({}) Pop, push and return 3; 3 3 -> 27
{({})} Push&return function
{} Pop 3; 27 push&return 3 -> push 27 copies of 3 and return 3

Flurry, 32 bytes, no bonus

<(({<({}){}>})({})){}{}>{({})}{}

Verification

$ echo -n "<(({<({}){}>})({})){}{}>{({})}{}" | wc -c
32
$ ./flurry -inn -c "<(({<({}){}>})({})){}{}>{({})}{}"
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
$ ./flurry -inn -c "<(({<({}){}>})({})){}{}>{({})}{}" | wc -c
64

How it works

In order to increase the output size, it is easiest to push numbers to stack and print them in integer mode. Basically the program follows the structure of n push&return m, where n is the repeat count, push&return is a function that, given an argument, pushes it and returns it unchanged, and m is the number to push. Then the stack contains n copies of m at the end, giving the output size of (length of m + 1) * n.

The second part of the challenge is to generate high enough numbers. Flurry uses Church numerals to represent natural numbers, so multiplication (<abc...> evaluates to a * b * c * ...) and exponentiation (ab evaluates to b**a) is much golfier than number literals (except 1), successor <><<>()>, and addition (which is defined via successor). So I tried various powers and products until I got the solution, where 32 is 4 * 4 * 2.

<
 (
 ({<({}){}>}) Push and return 2
 ({}) Pop 2, push back and return 2
 ) Push and return 2 ** 2 = 4
 {}{} Pop 4 and Pop 2
> Product; return 4 * 4 * 2 = 32
{({})} Function: push&return
{} Pop from empty stack, which gives I = 1
32 push&return 1 -> Push 1 to stack 32 times and return 1
answered Aug 12, 2020 at 1:51
\$\endgroup\$
2
\$\begingroup\$

Factor, 7 bytes

42 2^ .

Try it online!

2^42 is a 13-digit number. . outputs this number plus a newline.

answered Apr 27, 2021 at 1:05
\$\endgroup\$
2
\$\begingroup\$

Excel, 23 - 25 = -2 bytes

=REPT(0,IF(A1,A1,2)*23)

Saves 2 bytes by repeating a number instead of a character.

Excel, 4 bytes

=8^8

8^8 is an 8 digit number

answered Apr 28, 2021 at 14:47
\$\endgroup\$
2
\$\begingroup\$

Crystal, 9 bytes

print 5/7

Try it online!

answered Jan 28, 2022 at 21:54
\$\endgroup\$
2
\$\begingroup\$

Risky, 1 bytes

*1

Try it online!

(Prints 10, by doing 10 ** 1)

rydwolf
19.3k2 gold badges90 silver badges180 bronze badges
answered Jan 29, 2022 at 6:27
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Welcome to CGCC and I love the half-byte solution: it's a pity that the challenge rules specify "The program must be at least 1 byte long" - I suspect the original intention was just to avoid 0-byte programs... \$\endgroup\$ Commented Jan 29, 2022 at 10:37
2
\$\begingroup\$

Carrot, 4 bytes

.^*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
emanresu A
46.2k5 gold badges111 silver badges257 bronze badges
answered May 21, 2017 at 12:43
\$\endgroup\$
2
\$\begingroup\$

PHP, 56-25 = 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)?>
Shaggy
45k4 gold badges39 silver badges95 bronze badges
answered Oct 6, 2015 at 12:53
\$\endgroup\$
4
  • 1
    \$\begingroup\$ I started down the same path but "No file/disk/network io allowed." \$\endgroup\$ Commented Aug 4, 2016 at 15:27
  • \$\begingroup\$ Where do you get $n from? Try $argv[1]?:2; it has the same length as your expression. \$\endgroup\$ Commented Jan 27, 2017 at 6:47
  • \$\begingroup\$ This post is a year old, where register_globals was frowned upon, but not forbidden :) \$\endgroup\$ Commented Jan 27, 2017 at 8:04
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 27, 2017 at 16:14
2
\$\begingroup\$

Python REPL, 4 Bytes

9**8

\9ドル^8=43046721\$

answered Jun 1, 2023 at 18:53
\$\endgroup\$
2
\$\begingroup\$

C, (削除) 47 - 25 = 22 (削除ここまで) 46 - 25 = 21 bytes

x=2;main(){scanf("%d",&x);printf("%*x",x*46);}

Try it online!

Works by printing an uninitialised int, padded to the specified size. Credit to anatolyg's answer.

answered Jun 2, 2023 at 15:16
\$\endgroup\$
2
\$\begingroup\$

Desmoslang Assembly, 11 - 25 = -14 Bytes

[1...11*IOT

Note that you can't not give input.

answered May 30, 2023 at 4:59
\$\endgroup\$
2
  • \$\begingroup\$ Just to confirm, do you mean that you have to give it input, or is that a typo for you cannot give it input? And if it's the former, will any input work? \$\endgroup\$ Commented Jul 14, 2023 at 23:32
  • \$\begingroup\$ @RydwolfPrograms you do have to give it input, and yea, any input that you can give works \$\endgroup\$ Commented Jul 15, 2023 at 1:50
2
\$\begingroup\$

><>, 22 bytes

095*>1-:?v;
 ^o*86<

Try it online!

Pushes 0 and 45 (which is subtracted by 1 right after), then outputs a zero that many times.

answered Aug 1, 2024 at 14:52
\$\endgroup\$
2
\$\begingroup\$

Uiua -9 bytes

Try it out!

&pf▽16+@0⇡⍣⋕2&sc

Will print 16 copies of each ascii character up to the input length, starting with 0. i.e. Input of 3 gives 000000000000000011111111111111112222222222222222 (defaults to 2 if no input given)

answered Aug 1, 2024 at 15:33
\$\endgroup\$
2
\$\begingroup\$

Setanta, 14 bytes

scriobh([1]*9)

try-setanta.ie link

answered Aug 2, 2024 at 0:05
\$\endgroup\$
2
\$\begingroup\$

///, 15 bytes

/a/bbbbb/aaaaaa

Try it online!

answered Sep 6, 2024 at 5:04
\$\endgroup\$
2
\$\begingroup\$

AArch64 machine code + Linux syscalls, 56 - 25 = 31 bytes

00: 4f03e7c0 movi v0.16b, #126 // v0 / q0 = '~' * 16
04: ad0003e0 stp q0, q0, [sp] // stack = '~' * 32
08: ad0103e0 stp q0, q0, [sp, #32] // stack = '~' * 64
0c: 52800048 mov w8, #2 // default to 2
10: 71000409 subs w9, w0, #1 // argc - 1
14: 1a890109 csel w9, w8, w9, eq // argc - 1 ?: 2
18: 910003e1 mov x1, sp // pointer to '~' * 64
1c: d2800702 mov x2, #56 // 56 bytes
20: d2800808 mov x8, #64 // 64 = write()
24: d2800020 mov x0, #1 // 1 = stdout (loop starts here)
28: d4000001 svc #0 // syscall, write(stdout, '~' * 64, 56)
2c: 51000529 sub w9, w9, #1 // loop countdown
30: 35ffffa9 cbnz w9, 0x24 // loop
34: d65f03c0 ret // return result of last syscall

Should be linked as main.

The input is the number of command line arguments.


If it needs to be linked as _start and isn't allowed to segfault out:

AArch64 machine code + Linux syscalls, 60 - 25 = 35 bytes

00: 4f03e7c0 movi v0.16b, #126 // v0 / q0 = '~' * 16
04: ad0003e0 stp q0, q0, [sp] // stack = '~' * 32
08: ad0103e0 stp q0, q0, [sp, #32] // stack = '~' * 64
0c: 52800048 mov w8, #2 // default to 2
10: 71000409 subs w9, w0, #1 // argc - 1
14: 1a890109 csel w9, w8, w9, eq // argc - 1 ?: 2
18: 910003e1 mov x1, sp // pointer to '~' * 64
1c: d2800782 mov x2, #60 // 60 bytes
20: d2800808 mov x8, #64 // 64 = write()
24: d2800020 mov x0, #1 // 1 = stdout (loop starts here)
28: d4000001 svc #0 // syscall, write(stdout, '~' * 64, 60)
2c: 51000529 sub w9, w9, #1 // loop countdown
30: 35ffffa9 cbnz w9, 0x24 // loop
34: d2800ba8 mov x8, #93 // 93 = exit()
38: d4000001 svc #0 // syscall, exit(result of last syscall)

If the input number being the number of command-line arguments doesn't count, here's one with no bonus:

AArch64 machine code + Linux syscalls, 40 bytes

00: 4f03e7c0 movi v0.16b, #126 // v0 / q0 = '~' * 16
04: ad0003e0 stp q0, q0, [sp] // stack = '~' * 32
08: ad0103e0 stp q0, q0, [sp, #32] // stack = '~' * 64
0c: 3d8013e0 str q0, [sp, #64] // stack = '~' * 80
10: 910003e1 mov x1, sp // pointer to '~' * 80
14: d2800a02 mov x2, #80 // 80 bytes
18: d2800808 mov x8, #64 // 64 = write()
1c: d2800020 mov x0, #1 // 1 = stdout
20: d4000001 svc #0 // syscall, write(stdout, '~' * 80, 80)
24: d65f03c0 ret // return result of last syscall

And for both of the above conditions:

AArch64 machine code + Linux syscalls, 44 bytes

00: 4f03e7c0 movi v0.16b, #126 // v0 / q0 = '~' * 16
04: ad0003e0 stp q0, q0, [sp] // stack = '~' * 32
08: ad0103e0 stp q0, q0, [sp, #32] // stack = '~' * 64
0c: ad0203e0 stp q0, q0, [sp, #64] // stack = '~' * 96
10: 910003e1 mov x1, sp // pointer to '~' * 96
14: d2800b02 mov x2, #88 // 88 bytes
18: d2800808 mov x8, #64 // 64 = write()
1c: d2800020 mov x0, #1 // 1 = stdout
20: d4000001 svc #0 // syscall, write(stdout, '~' * 96, 88)
34: d2800ba8 mov x8, #93 // 93 = exit()
38: d4000001 svc #0 // syscall, exit(result of last syscall)
answered Jun 28, 2023 at 21:55
\$\endgroup\$
2
\$\begingroup\$

SAKO, 22 bytes

1)LINII44
STOP1
KONIEC

This is just a port of my answer here.

Almost qualifies for a bonus, but doesn't default to 2, 38 bytes

1)CZYTAJ:N
LINIIENT(×ばつN)
STOP1
KONIEC

Unforunately do get an empty input we would need to read a string instead of a number and parse it, which is just not really worth it even with the bonus.

I did it anyway, 143 - 25 = 118 bytes

CALKOWITE:*N,W,I
BLOK(9):N
CZYTAJWIERSZ:N
W=0
*)GDYN(I)=58:2,INACZEJ1
1)W=×ばつ10+N(I)-48
POWTORZ:I=0(1)9
2)×ばつ(W*SGN(1,I)+0*I)
STOP2
KONIEC

Maybe there is a way to shorten the loop, or the operation at label 2.

answered Mar 22 at 6:26
\$\endgroup\$
1 2 3
4
5
...
11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.