g | x | w | all
Bytes Lang Time Link
007Raku Perl 6 rakudo250424T143903Zxrs
006SAKO250328T063844ZAcrimori
071Bespoke250328T082612ZJosiah W
021AWK241205T191218Zxrs
010YASEPL240507T184129Zmadeforl
005Scala 3240305T172936Zmovatica
033Swift230723T203040ZmacOSist
024C gcc O3230718T163322Zc--
006PowerShell230724T194600Zstackpro
nanPiet + asciipiet230724T190156ZSanguine
006ForWhile C version230724T173847Zbsoelch
016Haskell230719T024153ZSuperSto
007Perl 5 p230724T074021ZNahuel F
003Dyalog APL230724T070615ZRubenVer
043D230722T060459ZThe Zip
015JavaScript230718T161855ZThe Thon
010jot1230721T163919Zroblogic
021Thue230721T161303ZDadsdy
013Bash230720T124608Z12431234
021C# Visual C# Interactive Compiler230721T131248ZKeizerHa
007x86 / x8664 machinecode230721T055024ZPeter Co
017simply230720T170733ZIsmael M
026Batch230720T074853ZNeil
009[Matlab]230719T123352ZFerro Lu
005Retina 0.8.2230718T183416ZNeil
012Hexagony230719T152354ZCursorCo
011Java JDK230718T172134ZDavid Co
062TypeScript’s Type System230718T155817Znoodle p
012Rust230719T122322Zmousetai
009Befunge93230718T162219ZJoe
00205AB1E230719T071058ZKevin Cr
nan230719T034537ZLSM07
004J230719T031220Zsouth
015Alice230718T230650ZJulian
021Lua230718T225926Zbluswimm
096Pascal230718T224855ZKai Burg
008jq230718T222629Zc--
004Raku230718T193603Zbb94
015Arturo230718T191731Zchunes
009Ruby230718T191341ZJordan
031Swift230718T190148ZBbrk24
001Charcoal230718T183304ZNeil
049C gcc230718T172054ZSaladin
063Python 3230718T171153ZDileep
011Python 3230718T161131ZThe Thon
010><> Fish230718T155847Zmousetai
001Thunno 2230718T155148ZThe Thon

Raku (Perl 6) (rakudo), 7 bytes

{1 x$_}

Attempt This Online!

{1     # string of one(s) 
x      # times
$_     # input
}      # implicit return

SAKO, 6 bytes

SPACJI

Well, this luckily is something that SAKO has a built-in for. Takes an integer. The unary digits are spaces.

Full programme version, 36 bytes

1)CZYTAJ:N
SPACJIENT(N)
STOP1
KONIEC

Reads a number from STDIN.

Bespoke, 71 bytes

UNARY
I do some looping until zero
I repeat a specific quantity of ones

1 is used as the "digit".

AWK, 21 bytes

{printf("%0*d",$1,0)}

Prints a 0s: 5 -> 00000

Attempt This Online!

24 bytes

{for(;i++<$1;)printf"1"}

Prints 1s: 5 -> 11111

Attempt This Online!

39 bytes

$0=gensub(0,1,"g",sprintf("%0*d",$1,0))

Modifies the shorter one to print 1s.

Attempt This Online!

YASEPL, 10 bytes

=i';"1",i<

Scala 3, 5 bytes

"1"*_

Attempt This Online!

Swift, 33 bytes

let u={for _ in 1...$0{print(0)}}

The "grouping separator" here is a newline after every digit.

C (gcc) -O3, 24 bytes

-1 byte thanks to @12431234123412341234123

f(n){n&&puts(f)+f(n-1);}

Try it online!


C (gcc), 42 bytes

Full program, input from stdin

main(n){printf("%.*d",n,!scanf("%d",&n));}

Try it online!


C (gcc) -m32, 44 bytes

Full program, input as command line argument

*p;main(n,v){printf("%.*d",atoi(1[p=v]),0);}

Try it online!

PowerShell, 6 bytes

'1'*$n

Try it online!

Piet + ascii-piet, 22 bytes (2×11=22 codels)

tabrjcdskcK  a?kqak kk

Try Piet online!


Explanation:

Prints 1 a total of n times.

Trace

ForWhile (C version), 6 bytes

{[9#)}

prints n tabs

Running the program with input 2000000000 takes a bit over 2 minutes and consumes about 150kBit of memory (when using the debug build of the interpreter) so the program is well withing the time and memory limits.

Interpreter

online interpreter Note that the online interpreter does not satisfy the efficiency requirements

Explanation

{    } anonymous procedure
 [  )  repeat n times
  9#   print tab

calling the procedure

{[9#)} 1$  store procedure at address 1
2000000000 1@? call procedure with argument `2000000000`

ForWhile, 26 bytes

99[_48-:0<!:[.'2*+1]).[9#)

Full program, reads binary integer from standard input

99[                 )       \ repeat up to 99 times
   _                        \ get a byte from standard input
    48-                     \ subtract char-code of 0
       :0<!:[      ]        \ if value is non-negative
             .    1         \ temporarily remove condition from stack
              '2*+          \ duplicate current value and add new bit
                    ).      \ break loop if last character was less than 48
                      [9#)  \ print tab n times

Haskell, 18 16 bytes

-2 bytes thanks to Bubbler

(`replicate`'a')

Attempt This Online!

On my machine, it finished in 48.68 seconds and had a max RSS of 4656 kb, well under the time and memory limits.

Perl 5 (-p), 7 bytes

$_=1x$_

Try it online!

Dyalog APL, 3 bytes

⍴∘0

This reshapes 0 to have the same length as the argument to the function, effectively repeating it input times.

For the same length, there's also /∘0 and ⌿∘0.

D, 43 bytes

(int x){import std;return"1".replicate(x);}

not sure if I can make it much shorter. I can't just do a short lambda (x=>...) because it requires replicate from std.array. I tried doing some stuff with iota and map but that resulted in 4 bytes longer than this simpler solution.

JavaScript, 15 bytes

n=>"".padEnd(n)

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!

-1 from both thanks to @Arnauld

JavaScript, 22 bytes

n=>print("".padEnd(n))

Try it online!

Prints the string.

jot(1), 10 bytes

jot -b1 $1

Try it online!

Outputs a stream of 1s 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

Thue, 21 Bytes

0::=x
1::=x*
*x::=x**

Input is on the state and in binary, output is some number of xs (can be ignored) and the output number of asterisks on the state at the end.

Is this allowed?

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.

C# (Visual C# Interactive Compiler), 21 bytes

x=>new String('a',x);

Try it online!

My first time writing an answer here!

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

simply, 17 bytes

This creates an anonymous anonymous function that returns the expected result:

fn($x)=>&tb($x,1)

This is a full program that does the same thing, but outputs it (also 17 bytes):

out&tb($argv[0]1)

How does it work?

This runs the function &tb, which is an alias to &tobase.

It takes the number and the base.
It relies on JavaScript's Number.prototype.toString(radix) with a special case to handle unary (where it just outputs 1s).


Ungolfed

Ungolfing both versions at the same time.

All examples here are executable on their own, and take a JSON array as input, with the value you wish.
This isn't a limitation of the program at all - it's just how you pass values to the compiler to populate the $argv variable.

All examples will be written with &tobase for clarity.

Code-like

// Anonymous function - assigned to $fn
$fn = fn($x) => &tobase($x, 1);
// Calls the function and outputs the result
echo call $fn(argv[0], 1);


// Full program
echo &tobase($argv[0], 1);

Plain-English-like

// Anonymous function - assigned to $fn
Set the variable $fn to an anonymous function with argument $x
Begin.
    Return the result of calling the function &tobase with the arguments $x, 1.
End.

// Calls the function and outputs the result
Display the result of calling the variable $fn with the arguments $argv[0], 1.


// Full program
Display the result of calling the function &tobase with the arguments $argv[0], 1.

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.

[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

Retina 0.8.2, 5 bytes

.+
$*

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.

Hexagony, 14 12 bytes

(}?@_.)<!>*'

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

Java (JDK), 11 bytes

"1"::repeat

Try it online!

TypeScript’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!

Type definition taking a generic integer type and recursively appending 1 to a tuple type until its length is the integer type.

Rust, 12 bytes

|a|vec![0;a]

Attempt This Online!

Befunge-93, 9 15 17 bytes

<,7_@#:+&

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.

05AB1E, 2 bytes

Uses character 1.

Try it online.

Î×

Uses character 0.

Try it online.

°¦

Uses character 0 as well.

Try it online.

õú

Uses a space as character.

Try it online.

If different multiple output-characters would have been allowed, it could be 1 byte with:

Try it online.

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)

As a whole program:

F# (.NET Core), 66 bytes

[<EntryPoint>]let m a=[for _ in 1..(int(Seq.head a))->printf"1"];0

Try it online!


As a function:

F# (.NET Core), 33 bytes

fun a->[for _ in 1..a->printf"1"]

Try it online!

J, 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!

#&LF
#     NB. copy
 &LF  NB. bond LF as the right argument

Alice, 15 bytes

/ M \1*.n$@9ot

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

Lua, 21 bytes

print(('0'):rep(...))

Try it online!

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.

jq, 8 bytes

"1"*.+""

Try it online!

Raku, 4 bytes

1 x*

Try it online!

Arturo, 15 bytes

$=>[repeat"1"&]

Try it!

Ruby, 9 bytes

->n{?1*n}

Attempt This Online!

Swift, 31 bytes

{.init(repeating:"1",count:$0)}

Try it online! A bit more verbose than some, but hopefully clear enough.

Charcoal, 1 byte

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.

C (gcc), 49 bytes

Full program, takes 1 argument

main(a,v)int**v;{for(a=atoi(v[1]);a--;puts(*v));}

Try it online!

Python 3, 63 bytes

import sys

n = int(sys.argv[1])
output = '1' * n
print(output)

Python 3, 11 bytes

'0'.__mul__

Try it online!

Note: 0 could be any other character. Function returning a string.

Python 3, 21 bytes

def f(n):print('0'*n)

Try it online!

Function which prints the string.

><> (Fish), 10 bytes

i:?!;1-1n!

Hover over any symbol to see what it does

Try it

Thunno 2, 1 byte

Try it online!

Uses a space as the character.

Vyxal, 1 byte

I

Try it Online!

Same as above.