| Bytes | Lang | Time | Link |
|---|---|---|---|
| 009 | How dare you fuck the brain | 241003T184211Z | Gleb |
| 049 | C gcc | 240409T153657Z | Mukundan |
| 003 | Uiua | 240922T150419Z | janMakos |
| 098 | Rust | 240412T123009Z | user9403 |
| 004 | Japt R | 240814T131130Z | Shaggy |
| 015 | Trilangle | 240519T223233Z | Bbrk24 |
| 027 | AWK | 240519T212442Z | C K |
| 005 | Ly | 240505T044121Z | cnamejj |
| 026 | Scala 3 | 240504T111720Z | 138 Aspe |
| 065 | Acc!! | 240417T035406Z | Mukundan |
| 038 | sed | 240414T102022Z | guest430 |
| 028 | !@#$%^&*_+ | 240418T161106Z | Aiden Ch |
| 082 | Acc!! | 240418T051908Z | DLosc |
| 110 | In Floop | 240416T232716Z | emanresu |
| 252 | Thue | 240417T012727Z | DLosc |
| 008 | TacO | 240416T231633Z | ATaco |
| 033 | tinylisp | 240416T203147Z | DLosc |
| 007 | Regenerate | 240416T194113Z | DLosc |
| 008 | Ouroboros | 240416T033821Z | DLosc |
| 006 | BQN | 240416T025344Z | DLosc |
| 069 | 99 | 240415T193033Z | Aiden Ch |
| 006 | Minkolang | 240415T183750Z | Aiden Ch |
| 028 | MarioLANG | 240415T183538Z | Aiden Ch |
| 015 | PingPong | 240415T174720Z | Aiden Ch |
| 018 | Python | 240414T183040Z | user9403 |
| 020 | Python 2 | 240409T132525Z | Mukundan |
| 002 | Vyxal | 240409T124319Z | lyxal |
| 003 | Uiua 0.10.0 | 240409T131144Z | Tbw |
| 009 | jq | 240413T044546Z | GammaFun |
| 019 | Zsh | 240413T044202Z | GammaFun |
| 010 | TIBASIC TI84+CE | 240411T182720Z | Sylveste |
| 002 | Nekomata | 240412T100240Z | alephalp |
| 012 | PARI/GP | 240412T023256Z | alephalp |
| 012 | Ruby | 240412T054737Z | G B |
| 013 | PowerShell Core | 240411T213246Z | Julian |
| 010 | BitCycle u | 240411T074512Z | Aiden Ch |
| 004 | Brachylog | 240411T144815Z | Fatalize |
| nan | Piet + asciipiet | 240411T074853Z | Aiden Ch |
| 054 | FreePascal | 240409T220002Z | Kai Burg |
| 019 | Octave / MATLAB | 240410T144650Z | Luis Men |
| 689 | C++ | 240409T145117Z | Someone |
| 010 | *><> | 240410T153439Z | Bee H. |
| 025 | JavaScript Node.js | 240410T002259Z | 2pichar |
| 025 | Brainfuck | 240409T141233Z | matteo_c |
| 002 | 05AB1E | 240409T124407Z | Kevin Cr |
| 055 | Whitespace | 240410T085109Z | Kevin Cr |
| 016 | JavaScript ES11 | 240409T205239Z | Arnauld |
| 041 | F# .NET 6+ | 240410T061011Z | dtanku |
| 037 | Haskell | 240409T141048Z | totallyh |
| 022 | Bash | 240410T042621Z | Mukundan |
| 032 | Quipu | 240409T201940Z | DLosc |
| 031 | SQL Oracle | 240409T200413Z | Ditto |
| 007 | Knight v2 | 240409T192300Z | Aiden Ch |
| 018 | JavaScript Node.js | 240409T175628Z | l4m2 |
| 004 | Charcoal | 240409T165505Z | Neil |
| 007 | Retina 0.8.2 | 240409T165257Z | Neil |
| 013 | Google Sheets | 240409T155609Z | z.. |
| 006 | Pip | 240409T155345Z | Kenzie |
| 009 | Perl 5 p | 240409T150913Z | Xcali |
| 003 | Jelly | 240409T135658Z | Jonathan |
| 011 | Brainfuck+2 | 240409T131959Z | None1 |
| 003 | MathGolf | 240409T125457Z | Kevin Cr |
| 006 | APL+WIN | 240409T124523Z | Graham |
Uiua, 3 bytes
¬°⊚
Explanation
°⊚ # histogram (4 -> [0 0 0 0 1])
¬ # logical not ([0 0 0 0 1] -> [1 1 1 1 0])
```
Rust, 98 bytes
fn main(){print!("{}{}","1".repeat(std::env::args().nth(1).unwrap().parse::<usize>().unwrap()),0)}
Japt -R, 4 bytes
ò@gX
ò@gX :Implicit input of integer U
ò :Range [0,U]
@ :Pass each X through the following function
gX : Sign of difference with U
Trilangle, 15 bytes
?<.>.(),/.!/'1!
Issues warnings (in the online interpreter or with -w set) and exits with an error.
Unfolded:
?
< .
> . (
) , / .
! / ' 1 !
Roughly equivalent to this C code:
extern int get_int(); // Read stdin until an integer is found, then return that
int main() {
int i = get_int();
while (--i >= 0) {
printf("%d\n", 1);
}
printf("%d\n", ++i);
return 1;
}
Trilangle, no errors, 16 bytes
?<.>.(),/.!/'1!@
Same idea as above, but add an exit opcode before it wraps around to the parts that error.
Ly, 5 bytes
R[Lu]
I found 5 different Ly programs that met the challenge in 6 characters. Then I accidentally stumbled onto this one...
R - generate a sequence from 0..N (from STDIN)
[ ] - loop while the top of stack is non-zero
L - "less than" compare top two entries (will be 1)
u - print the top of stack
Acc!!, 65 bytes
Count i while _%11-10 {
_*10+_%11+N%48
}
Write 49)*(_/11
Write 48
Abuses a bug in the official interpreter
Acc!!, 105 88 85 81 bytes
-5 byte thanks to @DLosc
Count i while _%11-10 {
_*10+_%11+N%48
}
Count i while _+1 {
Write 49-10/_
_-11
}
sed, 39 38 bytes
s/.*/echo {0..&}/e #0 to n seperated by spaces
s/[^ ]//g #only keep the spaces
y/ /1/ #spaces to 1s
a0 #append a 0
!@#$%^&*()_+, 28 bytes
>_(>+$!+!!+!+++n_*)+(!#_+)#
Input is a non-negative integer followed by the character "n". This is allowed as per this default I/O method (in this case, the input is actually an array of characters with the sentinel value being the character "n").
The character after the second ( is an ASCII 1 character.
The first loop is a golfed version of the "Input a Decimal Number" algorithm in this Esolangs article, using "n" as a sentinel value instead of a newline.
Acc!!, 87 86 82 bytes
N
Count i while _%96 {
_/96*960+_%48*96+N
}
Count i while _ {
_-960
Write 49-0^_
}
Explanation
Depends on the slightly unofficial behavior of the official interpreter, in which the input always ends with a newline character.
# Accumulator format: value * 96 + next_char
# Read first character
N
# Loop until next_char is EOF (0)
Count i while _%96 {
# _/96*96*10 Multiply previous value by 10
# +_%48*96 Add new digit to it (or 10 if character was newline)
# +N Read next character
_/96*960+_%48*96+N
}
# For an input number X, the accumulator is now equal to (X * 10 + 10) * 96
# which is the same as (X + 1) * 960
# Loop until accumulator reaches 0
Count i while _ {
# Decrement accumulator in steps of 960
_-960
# Output '1' if accumulator is still positive, '0' if it is now 0
Write 49-0^_
}
In Floop, 110 bytes
s+n+@?[s-]n-s[-n@;]s+r[s-]s[s-n@+r+]s+r-[s-]r+s[o++++++++++n@-[s-]s[-r+]]s+r--[s-]r++s[n@+o-[s-]s[-r--n+@-n-]]
Try It Online! This was a massive pain to write. Takes about ten seconds for n=3.
This would be a fairly easy challenge even for a Turing tarpit like In Floop... if there was a print instruction. In Floop only outputs the value of the current variable on termination. So, we have to calculate the output value as a single integer by repeatedly adding 1 and multiplying by 10.
In Floop has four integer variables; n, o, r, and s; in addition to an arbitrarily large array of integers @ which can be indexed into by the variables. Unfortunately, the state machine I came up with for this has five, which I'll call input (@[1]), state (r), inv (s), acc (@[0]) and copy (o).
One other thing I should note is that In Floop can only check if a variable is nonzero, so I'll use the idiom s+r+[s-]s[-...] to check if a variable's zero a lot - Set s to 1, if condition's nonzero set it to 0, if s is nonzero set it to 0 and continue.
s+n+@?[s-]n-s[-n@;] # Termination check / setup
n+@? n- # Try writing input value into input
s+ [s-] s[- ] # If it's zero
n@; # Print acc and terminate
s+r[s-]s[s-n@+r+] # Set up multiplication
s+ [s-]s[s- ] # If
r # State is 0 (start)
n@+ # Increment acc
r+ # State = 1 (multiplying)
s+r-[s-]r+s[o++++++++++n@-[s-]s[-r+]] # Multiply acc by 10
s+ [s-]. s[ ] # If
r- r+ # State is 1 (multiplying)
o++++++++++ # Add 10 to copy
n@- # Decrement acc
[s-]s[- ] # If acc == 0
r+ # State = 2 (copying)
s+r--[s-]r++s[n@+o-[s-]s[-r--n+@-n-]] # Finish loop
s+ [s-] s[ ] # If
r-- r++ # State == 2 (copying)
n@+ # Increment acc
o- # Decrement copy
[s-]s[- ] # If copy is zero
r-- # State = 0 (setup)
n+@-n- # Decrement input
Thue, 252 bytes
N::=:::
9)::=)T9
8)::=)T8
7)::=)T7
6)::=)T6
5)::=)T5
4)::=)T4
3)::=)T3
2)::=)T2
1)::=)T1
0)::=)T
9|::=8|1
8|::=7|1
7|::=6|1
6|::=5|1
5|::=4|1
4|::=3|1
3|::=2|1
2|::=|11
1|::=|1
T|::=|T
1T::=T1111111111
()|::=P
PT::=P
P1::=P!1
!1::=~1
P0::=~0
::=
(N)|0
Try it online! (Note that the newline at the end of the input seems to be mandatory; otherwise, the interpreter doesn't read the last character of the input.)
Explanation
Thue is a non-deterministic string-rewriting language. The program comes in two parts: the top section, above the ::= line, is a list of rewriting rules, and the bottom section, below the ::= line, is the initial state. At every step, a rule that can be applied to the current state is picked at random and applied. Once no rules can be applied, the program halts.
Our initial state is:
(N)|0
to which the only rule that can be applied is the first one:
N::=:::
::: is a special replacement that reads a line of stdin. We now have our decimal input number within the parentheses.
9)::=)T9
...
1)::=)T1
0)::=)T
Move the rightmost digit outside of the parentheses and add a T marker indicating that everything to the left of it needs to be multiplied by 10.
9|::=8|1
...
2|::=|11
1|::=|1
Move the digit through the pipe character, converting to unary.
T|::=|T
1T::=T1111111111
Move T through the pipe character as well; anytime there's a 1 to its left, convert to ten 1s on its right.
()|::=P
PT::=P
Once the whole number has been converted, replace everything before it with P for printing mode.
P1::=P!1
!1::=~1
Any time P is followed by 1, insert ! before the 1; any time ! is followed by 1, remove both and output 1.
P0::=~0
Once all the 1s are gone, output 0.
tinylisp, 33 bytes
(d F(q((N)(i N(c 1(F(s N 1)))(q(0
Defines a function F that takes an integer and returns a list. Try it online!
(d F(q((N)(i N(c 1(F(s N 1)))(q(0))))))
(d F ) ; Define F as
(q( )) ; a function
(N) ; of one parameter, N:
(i N ) ; If N is truthy (nonzero):
(c 1 ) ; Prepend 1 to
(F ) ; the result of a recursive call
(s N 1) ; with argument N-1
; Otherwise:
(q(0)) ; A list containing a single 0
This solution has one major problem, the cardinal sin of lisp functions: it is not tail-recursive. For values of N above about 250, it gives a recursion error. So here is a tail-recursive function in 37 bytes that takes an integer, prints that many 1s, and returns 0:
(d F(q((N)(i N(i(disp 1)0(F(s N 1)))0
(d F(q((N)(i N(i(disp 1)0(F(s N 1)))0))))
(d F ) ; Define F as
(q( )) ; a function
(N) ; of one parameter, N:
(i N ) ; If N is truthy (nonzero):
(disp 1) ; Output 1 (returns nil, which is falsey)
(i ) ; If disp's return value is truthy:
0 ; 0
; Otherwise (which is always the case):
(F(s N 1)) ; Recursive call with N-1
0 ; Otherwise, return 0
And here is a 40-byte tail-recursive anonymous function that returns a list, using some library functions:
(load library
(q((N)(map positive?(to0 N
(q((N)(map positive?(to0 N))))
(q( )) ; A function
(N) ; of one parameter, N:
(to0 N) ; Range from N down to 0
(map positive? ) ; For each, 1 if positive, 0 otherwise
Regenerate, 7 bytes
1{$~0}0
$~0 is the first command-line argument. 1{$~0} repeats 1 that many times, and 0 adds a 0 on the end.
Ouroboros, 9 8 bytes
r+.!.!n(
Try it here! (You'll need to enter the code and input manually.)
Explanation
Due to some convenient coincidences, we can use a single snake for the program. Execution starts at the left end and proceeds to the right before looping back around to the beginning again. When the instruction pointer is on a character that gets swallowed, execution halts.
rreads an integer from input and pushes it to the stack. If there is no input remaining, it pushes -1 instead.+adds the top two items on the stack. Missing items are treated as 0..!duplicates the top of the stack and logically negates it (0 -> 1, anything else -> 0).noutputs the top of the stack as a number.(takes the top of the stack and eats that many characters from the end of the snake. Since execution is on the final character, if a nonzero number of characters is eaten, the program halts.
So: On the first iteration, r+ reads the input number and adds it to 0; on subsequent iterations, it pushes -1 and adds it to the existing number on the stack, decrementing it. .!.! pushes 0, then 1 if the stack number has not yet reached zero; otherwise, it pushes 1, then 0. n outputs the second of these numbers, and ( halts the program if the first is 1.
BQN, 6 bytes
∾⟜0⥊⟜1
Explanation
∾⟜0⥊⟜1
⥊⟜1 # Reshape 1 to a length given by the function argument
# I.e. create a list of (function argument) many 1s
∾⟜0 # Append a 0 to this list
I've tried in vain to find a more interesting approach that's shorter. Most end up being 7 bytes; a few are 6 bytes:
∾⟜0⋈⊐↕ # Get indices of range(𝕩) in ⟨𝕩⟩, then append 0
«0∾⥊⟜1 # Reshape 1, prepend 0, shift left
×0∾˜⥊˜ # Reshape self, append 0, get sign of each
Given N, it's hard to make a list of length N+1 in BQN. The only builtin that does that is ⊔, but it requires its argument to be a list (thus wasting two bytes on ∘⋈), and it returns a list of lists, which is inconvenient to transform into a list of integers.
99, 69 bytes
999
99 9 9
9999 9 99 9
9999 999
9
999 999 9
9 99
9 99
9
This can 100% be golfed but it is very confusing to golf in this language, with all the 9's and all.
The main issue is this: the only way to access loops and conditionals in this language is through its GOTO command, which will conditionally GOTO a specified line. But because variables in 99 can only hold multiples of 9, so the GOTO command can only jump to lines with line numbers that are multiples of 9. That is why there is so much empty space between certain sections of the code: it is to accommodate for the limitations of the GOTO command.
For now, I am using a GOTO for lines 9 and 18, so that the loop starts at line 9, but I feel that there is a way to cut out the GOTO to line 18 and instead have a GOTO to line 0 (making the start of the loop at line 0), I'm just not sure how to go about doing it. The reason why I don't have a GOTO for line 0 is because line 0 is 999, which takes in input and sets it to the variable 999. If the input command was no-op after reading all the input, then I could have a GOTO to line 0, but instead it reads a 0 into the variable, which messes up the entire loop.
I'm also confident that re-arranging the way I assign the variables can also save 2 or 3 bytes, but I don't see anything for now.
PingPong, 15 bytes
;#/=\.@
1-/ \1.
I have another 15 bytes answer below, but I put this one at the top because I felt like this had to most golfing potential. I'm pretty confident the answer below is fully golfed using the strategies it employs.
15 bytes
;=\.@
0]\1.1-00
Python, 18 bytes
lambda x:"1"*x+"0"
Port of my Rust answer to Python.
Python 2, 20 bytes
-3 byte thanks to @Jonathan Allan
print'1'*input()+'0'
Python, 27 bytes
print('1'*int(input())+'0')
Python, 25 bytes
print('1'*int(input()),0)
Uses a less strict output format. Thanks to @ayreguitar and @None1
Vyxal, 2 bytes
ʀ>
Outputs as a list.
Explained
ʀ>ṅ
ʀ # 0..x
> # [x > n for n in ]
ṅ # join into a single string
💎
Created with the help of Luminespire.
Uiua 0.10.0, 3 bytes
0¬⊚
-1 byte thanks to @noodle man
Returns a list of 1s then a 0.
Other solutions
Just to showcase other features in Uiua and different options for output.
0=.⇡
0↯:1
⇌±⇡+1
>⇡+1.
¬⋯ⁿ:2
⇌[@0⍥@1]
0⍥&p‿1
0⍥1 #cannot be bound to a function name
TI-BASIC (TI-84+CE), 13 12 10 bytes
- Removed one byte thanks to @KaiBurghardt.
- Removed two bytes by not specifying the increment (which is an optional argument)
seq(X<Ans,X,0,Ans
This creates a list with the correct number of 1's and 0's. The byte count is subtracting any bytes that are present in an empty program. To find the byte count, I looked at the memory stats on the calculator. See how to score TI-BASIC for more information.
The input is in the form of the Ans variable, which needs to be set before running the program. Here is an example of input and output on the TI-84 Plus CE:
Nekomata, 2 bytes
Ħ¬
Ħ is a new built-in in Nekomata v0.5.1, so I am using the staging version of ATO.
Ħ¬ Take 5 as an example
Ħ Histogram; generate a list where the ith element (0-indexed) is the number of times i appears in the input
5 -> [0,0,0,0,0,1]
¬ Logical NOT
[0,0,0,0,0,1] -> [1,1,1,1,1,0]
PowerShell Core, 13 bytes
,1*"$input"
0
Outputs to stdout and is newline separated
Uses the $input variable to access stdin
,1*"$input" # generate an array of 1 of the size of $input and print it
0 # print a zero
BitCycle -u, 10 bytes
?~
v~v
>!<
This somehow works even though it uses some sketchy undefined behavior. It doesn't work on the Javascript online interpreter though, so it has to be modified for that interpreter:
16 bytes
?~
v~v
>v<
A/
!
Brachylog, 4 bytes
⟦ṡᵐ↔
Unifies the output with a list, e.g. [1,1,1,1,1,0]
Explanation
⟦ Range [0, …, Input]
ṡᵐ Map sign:
The sign of positive integers is 1
Thankfully for this challenge, the sign of 0 is 0
↔ Reverse the list
Piet + ascii-piet, 18 bytes (2×9=18 codels)
tabitkcmA ?cjsc aa
If we didn't have to consider the x=0 case, there is a nice 14 bytes answer:
tkvnM?esuA Q??
FreePascal, 58 B 54 B
Evidently, the output is just \$2^{x+1}-2\$ written to a base of two. This is shorter than producing the desired output iteratively.
var x:word;begin read(x);write(binStr(1<<(x+1)-2,x+1))end.
−4 B: As pointed out by dtanku, \$2^{x+1}-2 = 2^x2^1-2\$ so we pre‑evaluate \$2^1\$ and start exponentiating from \$2\$.
var x:word;begin read(x);write(binStr(2<<x-2,x+1))end.
NB:
The read and its sister procedures accept all integer literals acceptable in FreePascal source code, thus $F is valid input, too.
C++, 68 bytes (-9 by ceilingcat, and -1 yet again by Mukundan314)
#import<iostream>
main(int c){for(std::cin>>c;~c;)putchar(49^!c--);}
I'm…not even going to try to explain this. Ooh, XOR!
C++ (gcc), 78 bytes (-4 thanks to Mukundan314)
#include<iostream>
int main(){int c;for(std::cin>>c;c--;)puts("1");puts("0");}
Similar idea to the original, but using for loops and puts.
C++ (gcc), 82 bytes (OG)
#include<iostream>
int main(){int n;std::cin>>n;std::cout<<std::string(n,'1')<<0;}
C++ syntax highlighting doesn't work. :(
Explanation
#include<iostream>
int main(){int n;std::cin>>n;std::cout<<std::string(n,'1')<<0;}
#include<iostream> # Imports the I/O library (char* haters be mad)
int main(){ } # Initiates the main() function.
int n;std::cin>>n; # Initializes variable n and reads it from STDIN.
std::cout<< # Prints things to STDOUT.
std::string(n,'1') # This constructs a string with the char '1' repeated n times.
<<0; # Appends a 0 and ends the final line.
💎
Created with the help of Luminespire.
*><>, 10 bytes
Uses the -i flag to pass in input.
:?1:n?!;1-
Explanation
: Duplicate the top value on the stack
?1 Add 1 to the stack if the top value isn't zero
: Duplicate the top value of the stack
n Print the top value as a number
?!; Halt execution if the top value is 0
1- Subtract 1 from the top value
JavaScript (Node.js), 25 bytes
-2 bytes thanks to @DLosc
x=>((2<<x)-2).toString(2)
Takes the number as the parameter to the function, then outputs the binary form of \$2^{x+1}-2\$
Brainfuck, 25 bytes (non-competing*)
-[>+<-----]>-->,[<.>-]<-.
*: takes as input as a character-code, e.g. \x20 instead of 32.
05AB1E, 3 4 3 2 bytes
crossed out 4 is still regular 4 ;(
Ý›
+1 byte as bugfix (L results in \$[1,0]\$ for edge-case \$n=0\$)
-1 byte thanks to @lyxal
-1 byte due to a comment of OP ("Any unambiguous output format is allowed"), so it'll output as a list
Explanation:
Ý # Push a list in the range [0, (implicit) input of STDIN]
› # Check for each value whether the (implicit) input is larger
# (after which this list is output implicitly as result to STDOUT)
Whitespace, 55 bytes
[S S S N
_Push_0][S N
S _Duplicate_0][T N
T T _Read_STDIN_as_integer][T T T _Retrieve_input_n][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_n][N
T S T N
_If_0_Jump_to_Label_END][S S S T N
_Push_1][S N
S _Duplicate_1][T N
S T _Print_as_integer_to_STDOUT][T S S T _Subtract_top_two][N
S N
N
_Jump_to_Label_LOOP][N
S S T N
_Create_Label_END][T N
S T _Print_as_integer_to_STDOUT]
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Explanation in pseudo-code:
Integer n = STDIN as integer
Start LOOP:
If (n == 0):
Stop LOOP
Print 1 (as integer to STDOUT)
Go to next iteration of LOOP
Print n (which is 0 at this point) as integer to STDOUT
JavaScript (ES11), 16 bytes
-4 bytes thanks to @Unmitigated
Expects a BigInt and returns a string.
n=>10n**n/9n+"0"
F# (.NET 6+), 41 bytes
printf"%B"((2<<<int(stdin.ReadLine()))-2)
Most online compilers are too old (they can't format as binary), but this compiles on a proper IDE.
Haskell, 42 37 bytes
-5 bytes thanks to Wheat Wizard.
main=do n<-readLn;print$10^n`div`9*10
Not math, 42 bytes
main=interact(\n->('1'<$[1..read n])++"0")
Quipu, 32 bytes
1&0&1&/\
--[]/\
1&3&0&
>===??
\/
Explanation
A Quipu program is composed of threads, vertical 2-character-wide strips that act as code and also as value storage. Threads are, by default, executed one at a time left to right. Each thread's value starts at 0.
Thread 0 stores the current value of the loop counter:
1&
-- # Subtract 1 from the previous value of this thread
1&
>= # If the result is >= 0, jump to thread 1
\/ # Otherwise, read a number and set thread 0's value to that
Thread 1 checks whether the loop counter has hit zero:
0&
[] # Load value of thread 0
3&
== # If the result is == 0, jump to thread 3
Thread 2 is the loop body:
1&
/\ # Output 1
0&
?? # Jump back to thread 0
Thread 3 runs after the loop exits:
/\ # Output this thread's value (0 by default)
SQL (Oracle), 31 bytes
Always fun when we can slip an SQL solution that actual isn't that bad:
select lpad(0,&n+1,1)from dual;
Knight (v2), 7 bytes
O+*,1P0
This answer takes full advantage of Knight's type coercion.
If you look at the code, you may notice that we seem to be multiplying (*) a list (,1) with a string (P), but due to type coercion, the second argument, which is P, is actually coerced to an integer, so this results in a list that consists of P 1's. Then, we seem to be adding the resulting list to an integer 0, but due to type coercion, the integer is coerced into a list, which, in this case, converts the 0 to a singleton list consisting of a 0. This singleton list is then concatenated at the end of the aforementioned list of 1's, resulting in a list of P 1's, followed by a single 0. Finally, O always coerces its input, which is a list, to a string, resulting in the list being joined by newline before being outputted to stdout.
JavaScript (Node.js), 18 bytes
n=>'1'.repeat(n)+0
JavaScript (Node.js), 19 bytes
f=n=>n?1+f(--n):'0'
。
Charcoal, 4 bytes
×1N0
Try it online! Link is to verbose version of code. Explanation: × is the repetition operator, so the string 1 is repeated according to the numeric input, and then the 0 is simply appended. Note that other ways of repeating 1 would cause it to become adjacent to the 0, which would require a separator character.
Retina 0.8.2, 7 bytes
.+
$*10
Try it online! Explanation: $* repeats a single character to its right, so the 0 does not get repeated. By default the repeat count is the entire match, which here is the input, so the input is replaced by the desired output.
Google Sheets, 13 bytes
=REPT(1,A1)&0
Jelly, 3 bytes
>ŻY
A full program that accepts a (non-negative*) integer, \$x\$, and prints \$x\$ ones followed by a zero.
* negative integers will do the same as zero.
How?
>ŻY - Main Link: non-negative integer, X e.g. 0 3
Ż - zero range [0] [0,1,2,3]
> - {X} greater than {that}? [0] [1,1,1,0]
Y - join with newline characters
- implicit, smashing print
Brainfuck+2, 11 bytes
;[>+:-<-]>:
Explanation
; Input x as decimal number (only 0 to 255 are supported)
[ While x is nonzero
>+:-< Print 1
- Decrement x
]
>: Print 0
MathGolf, 3 bytes
Ä10
Explanation:
Ä # Loop the (implicit) input-integer of STDIN amount of times,
# using 1 character as inner code-block:
1 # Push a 1 every iteration
0 # After the loop: push a 0
# (after which the entire stack is joined and output implicitly as result)
