[Question]
  [
Your task is it to output a number as a unary string. You get the number of a non-negative integer input in the range of 0 - 2'000'000'000.
Rules
* You can choose any character for the digit you like. But it has to be the same everywhere and for every input.
* Output a unary string by outputting this character N times. N is the input.
* Input range is 0 - 2'000'000'000 (inclusive)
* A input of 0 result in a empty string except the optional starting and ending characters.
* You may or may not add optional starting and ending characters at the start and/or end, for example a newline character or `[` and `]`. If you do, all outputs (including of the input 0) must have one. This characters are different from the the character for the digit you have chosen.
* Input integer is given as decimal, hexadecimal, octal or binary number, whatever is convenient for you.
* You are free to use a pattern of multiple characters for a single digit. But it has to be the same pattern for all digits and for every input.
* Digit grouping is optional. If you use it, the group size has to be constant and the separation character has to be the same everywhere.
* Your program should finish in less than 4h on a modern desktop CPU with 4 GB of free RAM, for any valid input.
* Output is a string or stream of characters.
Examples / test cases:
```
Input  ->  Output
./yourProgram 1  -> 1
./yourProgram 12 -> 111111111111
./yourProgram 0  -> 
./yourProgram 2000000000 | tr -d -c '1' | wc -c -> 2000000000
./yourProgram 32 -> 11111111111111111111111111111111
```
Non-golf example program:
```
#!/usr/bin/env python3
import sys
for i in range( int(sys.argv[1]) ):
  print("1", end='')
```
This is `code-golf`, so the shortest code wins.
Related but they have significant differences:
* [Output a random unary string](https://codegolf.stackexchange.com/questions/243525/output-a-random-unary-string)
* [Parse a list of signed unary numbers](https://codegolf.stackexchange.com/questions/150775/parse-a-list-of-signed-unary-numbers)
* [Brainf\*\*k to Unary and Back](https://codegolf.stackexchange.com/questions/52712/brainfk-to-unary-and-back)
  
[Answer]
# [Python 3](https://docs.python.org/3/), 11 bytes
```
'0'.__mul__
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzX91AXS8@Prc0Jz7@f0FRZl6JRpqGqabmfwA "Python 3 ‚Äì Try It Online")
Note: `0` could be any other character. Function returning a string.
# [Python 3](https://docs.python.org/3/), 21 bytes
```
def f(n):print('0'*n)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI0/TqqAoM69EQ91AXStP83@ahqnmfwA "Python 3 ‚Äì Try It Online")
Function which prints the string.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 1 byte
```
ÔºÆ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMzr6C0xK80Nym1SENT0/r/fzPL/7plOQA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation: Charcoal prints a number as a number of `-`, `|`, `/` or `\` symbols depending on the direction of the pivot, the default being horizontal.
[Answer]
# [TypeScript](https://www.typescriptlang.org)‚Äôs Type System, 62 bytes
```
type U<N,L extends 1[]=[]>=L extends{length:N}?L:U<N,[...L,1]>
```
[Try it at the TypeScript Playground!](https://tsplay.dev/wE8Q2W)
Type definition taking a generic integer type and recursively appending 1 to a tuple type until its length is the integer type.
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 4 bytes
```
1 x*
```
[Try it online!](https://tio.run/##K0gtyjH7n1uplmb731ChQuu/NVdxYqVCmoahgeZ/AA "Perl 6 ‚Äì Try It Online")
[Answer]
# [Rust](https://www.rust-lang.org), 12 bytes
```
|a|vec![0;a]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqLS4ZMHGtDyF3MTMPA1Nheqc1BKFNNulpSVpuhZraxJrylKTFaMNrBNjrSFiewqKMvNKcvIUNZSqrexrlXQU0jQsDAw0Na25uGohShYsgNAA)
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 1 [byte](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
·π£
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVFMSVCOSVBMyZmb290ZXI9JmlucHV0PTUmZmxhZ3M9)
Uses a space as the character.
# [Vyxal](https://github.com/Vyxal/Vyxal), 1 byte
```
I
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCJJIiwiIiwiNSJd)
Same as above.
[Answer]
# [Lua](https://www.lua.org/), 21 bytes
```
print(('0'):rep(...))
```
[Try it online!](https://tio.run/##yylN/P@/oCgzr0RDQ91AXdOqKLVAQ09PT1Pz////pgA "Lua ‚Äì Try It Online")
[Answer]
# [J](https://www.jsoftware.com), 4 bytes
```
#&LF
```
Uses linefeed as the character. The large test case will not work on ATO, but `100 timex '# f 2000000000'` yields an average of 0.421414 seconds.
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxRFkNxrx5WJMrNTkjX0FdFztQh0inKRgSq86IKIUaaQoGmgq6ViAdCn5Oegop-anFCpklCrmJJckZ9gp5-XpEWmhsBPHKggUQGgA)
```
#&LF
#     NB. copy
 &LF  NB. bond LF as the right argument
```
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), ~~14~~ 12 bytes
```
(}?@_.)<!>*'
```
[Try it online!](https://tio.run/##y0itSEzPz6v8/1@j1t4hXk/TRtFOS/3/f0MDAwA "Hexagony ‚Äì Try It Online")
Layed out
```
   ( } ?
  @ _ . )
 < ! > * '
  . . . .
   . . .
```
### Explanation
`(}?` some irrelevant operations initially, then get the input
`<` branch, if 0 go to `@` and terminate, otherwise point the IP southeast
`(_` decrement the input cell and redirect the IP northeast
`}*)!` move the MP to the cell to the right, set that cell to 1 and print that out
`_>` redirect the IP back east
`*'` irrelevant operation, then move the MP back to the input cell
this then loops back to the branch command
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 5 bytes
```
.+
$*
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRev/fzNLAA "Retina 0.8.2 ‚Äì Try It Online") Explanation: Outputs `1` repeated by the input count, with a trailing newline.
For Retina 1, remove the `$`, and then the program outputs `_` repeated by the input count, without a trailing newline.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 21 bytes
`x=>new String('a',x);`
[Try it online!](https://tio.run/##NY0/D4IwEMVn@yneRglVUccCi4mTm4MDYTCk4EXTmraoCeGz1/rvll/uvXf3WjdvHYXdoFsUpL2A85Z0X6FDifAsK60eOHw0npwS8UxluJ8szCX63g5KsvdK@jZ4F6V3vG4wYiWwWgvkApsITBLL5Tr/D@uMBY@FoHiUy4ji92SxV7r3Z4kso5SNbLY12pmrWhwtebUnrXjHv9GamjSVbAov "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
My first time writing an answer here!
[Answer]
# [C (gcc)](https://gcc.gnu.org/) `-O3`, 24 bytes
*-1 byte thanks to [@12431234123412341234123](https://codegolf.stackexchange.com/users/59900/12431234123412341234123)*
```
f(n){n&&puts(f)+f(n-1);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOk9NraC0pFgjTVMbyNc11LSu/Z@ZV8KVm5iZp1GWn5miyVXNlaZhqmnNVfv/X3JaTmJ68X9df2MA "C (gcc) ‚Äì Try It Online")
---
# [C (gcc)](https://gcc.gnu.org/), 42 bytes
*Full program, input from stdin*
```
main(n){printf("%.*d",n,!scanf("%d",&n));}
```
[Try it online!](https://tio.run/##S9ZNT07@/z83MTNPI0@zuqAoM68kTUNJVU8rRUknT0exODkxD8QH8tTyNDWta///NwUA "C (gcc) ‚Äì Try It Online")
---
# [C (gcc)](https://gcc.gnu.org/) `-m32`, 44 bytes
*Full program, input as command line argument*
```
*p;main(n,v){printf("%.*d",atoi(1[p=v]),0);}
```
[Try it online!](https://tio.run/##S9ZNT07@/1@rwDo3MTNPI0@nTLO6oCgzryRNQ0lVTytFSSexJD9TwzC6wLYsVlPHQNO69v///yb/ktNyEtOL/@vmGhsBAA "C (gcc) ‚Äì Try It Online")
[Answer]
# [><> (Fish)](https://esolangs.org/wiki/Fish), 10 bytes
```
![i](https://$ "read a character")![:](https://$ "Duplicate the top item on the stack")![?](https://$ "Pop 1 value of the stack, if it's 0 skip the next instruction and move forward 2 spaces.")![!](https://$ "Skip the next instruction, moving 2 spaces instead of 1")![;](https://$ "Halt")![1](https://$ "Push the number (0-9)")![-](https://$ "Pop 2 values of the stack then perform the given operation.")![1](https://$ "Push the number (0-9)")![n](https://$ "output a number in decimal")![!](https://$ "Skip the next instruction, moving 2 spaces instead of 1")
```
Hover over any symbol to see what it does
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiaTo/ITsxLTFuISIsImlucHV0IjoiMTIiLCJzdGFjayI6IiIsInN0YWNrX2Zvcm1hdCI6Im51bWJlcnMiLCJpbnB1dF9mb3JtYXQiOiJudW1iZXJzIn0=)
[Answer]
# [Arturo](https://arturo-lang.io), 15 bytes
```
$=>[repeat"1"&]
```
[Try it!](http://arturo-lang.io/playground?OMx7fz)
[Answer]
## Pascal, 96 characters
```
program u(input,output);var i:integer;begin read(i);while i>0 do begin write('ùç∑');i‚âîi‚àí1 end end.
```
Necessary implementation characteristics:
The value of `maxInt` must be ‚â• 2000000000.
[Answer]
# [Alice](https://github.com/m-ender/alice), 15 bytes
```
/ M \1*.n$@9ot
```
[Try it online!](https://tio.run/##S8zJTE79/19fwVchxlBLL0/FwTK/hOv///9GBgYA "Alice ‚Äì Try It Online")
The new line at the end of the code is required  
Uses tab as the output character
```
/ M \1*.n$@9ot    # Full program
/ M \1*           # Reads one argument as a string and multiply it by 1, this is our loop counter
       .n$@       # Stop if the counter is down to 0
           9o     # Output a <tab>
             t    # Decrement the counter
                  # Goes back to the beginning of the line
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
$√ó
```
Uses character `1`.
[Try it online.](https://tio.run/##yy9OTMpM/f9f5fD0//8NjQE)
```
√é√ó
```
Uses character `0`.
[Try it online.](https://tio.run/##yy9OTMpM/f//cN/h6f//GxoDAA)
```
¬∞¬¶
```
Uses character `0` as well.
[Try it online.](https://tio.run/##yy9OTMpM/f//0IZDy/7/NzQGAA)
```
√µ√∫
```
Uses a space as character.
[Try it online.](https://tio.run/##yy9OTMpM/f//8NbDu/7/NzQGAA)
If different multiple output-characters would have been allowed, it could be 1 [byte](https://github.com/Adriandmen/05AB1E/wiki/Codepage) with:
```
‚àç
```
[Try it online.](https://tio.run/##yy9OTMpM/f//UUfv//@GxgA)
**Explanation:**
```
$   # Push 1 and the input-integer
 √ó  # Repeat the 1 the input amount of times as string
    # (which is output implicitly as result)
√é   # Push 0 and the input-integer
 √ó  # Repeat the 0 the input amount of times as string
    # (which is output implicitly as result)
¬∞   # Push 10 to the power of the (implicit) input-integer
 ¬¶  # Remove the leading 1 so only the 0s remain
    # (which is output implicitly as result)
√µ   # Push an empty string ""
 √∫  # Pad it with the (implicit) input-integer amount of leading spaces
    # (which is output implicitly as result)
‚àç   # Extend/shorten the (implicit) input to a length of the (implicit) input-integer
    # (which is output implicitly as result)
```
[Answer]
# [Java (JDK)](http://jdk.java.net/), 11 bytes
```
"1"::repeat
```
[Try it online!](https://tio.run/##ZY7BSsRADIbvfYqwpynowJ6EretREPTUo3iI3VjSnabDTLrbRfbZ6xSnKphL8idfkr/DE952h@PMvR@CQpe0HZWdrRsUoVAV/yYfozTKg9jHXFRF4cd3xw00DmOEF2SBzwJS5H5U1JROAx@gT1NTa2BpX98AQxvLDC@x3rx/EqWWwg18ow@wvIX9vNludrtAnlDn6mctu4UIexA6r9rUl6jUW5byl2VRmBKXP1iPIVISJlqhSZ9ZyJR/@HxjGNX6ZEWdmMWLRe/dxUwrei2u890X "Java (JDK) ‚Äì Try It Online")
[Answer]
# x86 / x86-64 machine-code, 7 bytes, as fast as memset
Just a function, not a full program, so we only need to `memset(buf, '1', n)` + append a terminating 0 to make an implicit-length C-style string in the buffer the caller supplies, of size `n+1` or larger.
This could be called from C in the x86-64 System V calling convention as `void to_unary(char *dst, int dummy, int dummy, size_t n)`. Size is limited only by address-space limits.
```
machine code | NASM source
              ; RDI or ES:EDI = output buffer of size n
              ; RCX or ECX = n
              to_unary:
 B031           mov al, '1'
 F3AA           rep stosb
 880F           mov byte [rdi], cl    ; RCX was zeroed by rep stos
 C3             ret
```
[`stos` stores and *then* increments](https://www.felixcloutier.com/x86/stos:stosb:stosw:stosd:stosq), so it leaves RDI pointing after the last byte it stored. We depend on the calling convention for DF=0 (increment not decrement), as is normal for all mainstream 32 and 64-bit calling conventions.
The same machine code bytes will do the same thing in 32-bit mode.
At first I was going to use `dec eax` / `stosb` for the terminator, with `1` instead of `'1'` as the unary digit "character". This would be 2 bytes in 32-bit mode only. But then I realized a `mov` store wouldn't need a displacement in the addressing mode, and that we had `cl`=0.
---
For an explicit-length-string version using separate pointer+length, we could return the input length after filling the input buffer (also leaving a pointer to the end in RDI). This would take the same total machine-code size: `push rcx` to start, `pop rax` at the end, instead of `mov [rdi], cl`.
---
**If the buffer is large and aligned, speed on typical modern CPUs, especially with the [ERMSB feature](https://stackoverflow.com/questions/43343231/enhanced-rep-movsb-for-memcpy), is basically as fast as typical libc memset, at least on Intel maybe not AMD.**
On a typical desktop, single-core memory bandwidth is usually close to maxing out the memory controllers. ([Much lower per-core bandwidth on many-core Xeons](https://stackoverflow.com/questions/39260020/why-is-skylake-so-much-better-than-broadwell-e-for-single-threaded-memory-throug).) Slower with page faults on the first access to newly allocated RAM, but this runs about as fast as it's possible for a single thread to go (for large aligned buffers), except by playing virtual memory tricks to map a range of virtual pages to the same memsetted page of '1's. With a misaligned buffer it's still probably under a second to fill 2GB. For small `n`, [microcode startup overhead](https://stackoverflow.com/questions/33902068/what-setup-does-rep-do) dominates, even on CPUs with the "fast-short-rep" feature. AMD CPUs may have slower `rep stos`, but even storing 1 byte per clock cycle would be way faster than the 4 hour requirement needs.
[Answer]
## Bash, 13 bytes (with calling other programs)
```
yes|head -n$1
```
##### Explanation
`yes` prints lines with the content `yes`. `head -n` will filter for the first n lines, n is given with `$1`.
The line with `yes` is used as digit.
## Pure Bash, 29 ~~34~~ bytes
```
for((i=$1;0<i;i--));do [;done
```
##### Explanation
The `for((i=$1;0<i;i--))` will do the commands between `do` and `done` `$1` times. `[` is a builtin bash command that expects a test and a `]`, which isn't provided, so it prints a error message every time. The error message is used as digit.
I tried also this one:
```
$1||pwd;$1||0 $(($1-1))
```
Which works almost when the script is named 0 and in the current `$PATH`. But it fails with large inputs, so not a working solution.
##### Explanation
The `||` means, if that on the left side fails, try that on the right side instead (till the end of the line or `;`). If it doesn't fail ignore the part on the right side. If there is nothing on the left side, the right is also ignored.
This tries to call program `$1`, i.e. the first parameter provided. Since the script is named `0`, it will work with the input `0`. so it calls itself without any argument. And then, when it runs without an argument, `$1` will expands to nothing, which means do nothing and ignore the part right of `||`.
If the parameter `$1` is a `number>0`, it will fail to execute a program because there is no program with that name. This means a error message is printed to `stderr`, which we ignore, and then the right side of `||` is executed.
The `$1||pwd;` part means: If program `$1` is not valid, i.e. `$1` is a number above `0`, it calls `pwd`. `pwd` outputs something to `stdout` and it shouldn't change. So we can use it as a non-changing digit. The `$1||0 $(($1-1))` part means: If program `$1` is not valid, call `0` / itself with the parameter `$(($1-1))`. `$(($1-1))` means 1 subtracted from `$1`.
It fails with large input because it recursively calls itself and so a new process starts. But i can't create 2'000'000'000 processes on my PC.
[Answer]
# [jot(1)](https://man.freebsd.org/cgi/man.cgi?jot(1)), 10 bytes
```
jot -b1 $1
```
[Try it online!](https://tio.run/##qyrO@J@moVn9Pyu/REE3yVBBxfB/LVeagqlCjUJRsYJuugGQY2yEzDM1MDAA8suTFXRzuJTTFIwMYAAm@h8A "Zsh ‚Äì Try It Online")
Outputs a stream of `1`s separated by newlines. TIO times out doing the 2 billion case, but it takes just 4 minutes on my Intel Mac
```
$ time jot -b 1 2000000000|wc -l
 2000000000
jot -b 1 2000000000  243.40s user 0.52s system 99% cpu 4:04.24 total
wc -l  2.61s user 1.70s system 1% cpu 4:04.24 total
```
[Answer]
# [JavaScript](https://nodejs.org), 15 bytes
```
n=>"".padEnd(n)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1k5JSa8gMcU1L0UjT/N/cn5ecX5Oql5OfrpGmoappuZ/AA "JavaScript (Node.js) ‚Äì Try It Online")
Returns the string. Uses a space as the character.
This might not be allowed, but for **9 bytes**
```
"".padEnd
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@19JSa8gMcU1L@V/cn5ecX5Oql5OfrpGml5yYk6OhpKSjoKppuZ/AA "JavaScript (Node.js) ‚Äì Try It Online")
*-1 from both thanks to @Arnauld*
# [JavaScript](https://nodejs.org), 22 bytes
```
n=>print("".padEnd(n))
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifZvs/z9auoCgzr0RDSUmvIDHFNS9FI09T83@ahqnmfwA "JavaScript (V8) ‚Äì Try It Online")
Prints the string.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 49 bytes
*Full program, takes 1 argument*
```
main(a,v)int**v;{for(a=atoi(v[1]);a--;puts(*v));}
```
[Try it online!](https://tio.run/##S9ZNT07@/z83MTNPI1GnTDMzr0RLq8y6Oi2/SCPRNrEkP1OjLNowVtM6UVfXuqC0pFhDq0xT07r2////hgYA "C (gcc) ‚Äì Try It Online")
[Answer]
# Swift, 31 bytes
```
{.init(repeating:"1",count:$0)}
```
[Try it online!](https://tio.run/##Ky7PTCsx@Z@TWqKQZqWg4ZlXoqmga6cQXFKUmZeuYPu/Wi8zL7NEoyi1IDWxBChkpWSopJOcX5pXYqVioFn7vwCorkQjTcPIQFPzPwA) A bit more verbose than some, but hopefully clear enough.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 9 bytes
```
->n{?1*n}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhYrde3yqu0NtfJqIfxVBaUlxQpu0YZGsRCBBQsgNAA)
[Answer]
# [jq](https://stedolan.github.io/jq/), 8 bytes
```
"1"*.+""
```
[Try it online!](https://tio.run/##yyr8/1/JUElLT1tJ6f9/AwA "jq ‚Äì Try It Online")
[Answer]
**As a whole program:**
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), 66 bytes
```
[<EntryPoint>]let m a=[for _ in 1..(int(Seq.head a))->printf"1"];0
```
[Try it online!](https://tio.run/##SyvWTc4vSv3/P9rGNa@kqDIgPzOvxC42J7VEIVch0TY6Lb9IIV4hM0/BUE9PAyilEZxaqJeRmpiikKipqWtXUAQUS1MyVIq1Nvj//7@hEQA "F# (.NET Core) ‚Äì Try It Online")
---
**As a function:**
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), 33 bytes
```
fun a->[for _ in 1..a->printf"1"]
```
[Try it online!](https://tio.run/##SyvWTc4vSv1vaMRVY/c/rTRPIVHXLjotv0ghXiEzT8FQTw/ILyjKzCtJUzJUiv3/HwA "F# (.NET Core) ‚Äì Try It Online")
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93), 9 ~~15~~ ~~17~~ bytes
```
<,7_@#:+&
```
[Try it online!](https://tio.run/##S0pNK81LT/3/30bHPN5B2Upb7f9/I0NzAA "Befunge-93 ‚Äì Try It Online")
This program is pretty simple. It gets a number as input, then it decrements it by adding `-1`. `-1` is the value returned when there is no input left, so I'm able to just use one `&` symbol to get the numbers I need and just continue adding the current value and `-1` to decrement. Each time the number is decremented, the program checks if it is `0`, and if it is, it quits. I did this by using a bridge (`#`) to skip over the stop command (`@`) and the go backward to the `@` if the value is `0` using a horizontal if `_`. Previous versions of my program weren't linear, but rather 2d, so the control was taking up a lot of space. The bridge command allowed me to keep control linear. The program starts with a `<` to make the program go backwards, this is because the horizontal if statement `_` goes right if `0`, but I need it to go left, so I reversed the whole program because that's easier than reversing it's input.
[Answer]
# [Matlab], 9 bytes
```
ones(1,n)
```
ones generates mxn matrixes of 1s
---
# [Matlab], 16 bytes
second version upon remarks in the comments
```
s=@(n) ones(1,n)
```
anonymous function that generates mxn matrixes of 1s
[Answer]
## Batch, 26 bytes
```
@for/l %i in (1,1,%1)do cd
```
The `@` is needed to prevent unwanted echo of the `for` command, but echo of the `cd` command is per-iteration anyway so no `@` is needed. The four spaces are needed so that the code will parse correctly.
]