# Numbers by Position

## Numbers by Position

Challenge

Print the numbers:

1
22
333
4444
55555
666666
7777777
88888888
999999999


In that order.

I/O

Takes no input. The numbers can have any delimiters desired (or none). That includes lists, cell arrays, etc.... Example outputs:

122333444455555666666777777788888888999999999

[1,22,333,4444,55555,666666,7777777,88888888,999999999]

etc....


Code Example

This is an un-golfed example that may perhaps act as algorithm guide (or maybe not):

# Turing Machine Code, 535 bytes

0 * 1 r L
L * _ r 2
2 * 2 r a
a * 2 r M
M * _ r 3
3 * 3 r b
b * 3 r c
c * 3 r N
N * _ r 4
4 * 4 r d
d * 4 r e
e * 4 r f
f * 4 r O
O * _ r 5
5 * 5 r g
g * 5 r h
h * 5 r i
i * 5 r j
j * 5 r P
P * _ r 6
6 * 6 r k
k * 6 r l
l * 6 r m
m * 6 r n
n * 6 r o
o * 6 r Q
Q * _ r 7
7 * 7 r p
p * 7 r q
q * 7 r r
r * 7 r s
s * 7 r t
t * 7 r u
u * 7 r R
R * _ r 8
8 * 8 r v
v * 8 r w
w * 8 r x
x * 8 r y
y * 8 r z
z * 8 r A
A * 8 r B
B * 8 r S
S * _ r 9
9 * 9 r C
C * 9 r D
D * 9 r E
E * 9 r F
F * 9 r G
G * 9 r H
H * 9 r I
I * 9 r J
J * 9 r halt


Try it online!

This prints out the numbers with a space delimiter:

1 22 333 4444 55555 666666 7777777 88888888 999999999


Challenge Type

, so shortest answer in bytes (by language) wins.

Based on a submission in the sandbox.

• Can the delimeters be numbers? – Ad Hoc Garf Hunter Mar 17 at 17:16
• @AdHocGarfHunter, No. Good catch. Edit: Actually, I think '0' should be acceptable. – ouflak Mar 17 at 17:17
• Could you verify that they "strange delimiters" version of this answer, is valid? It definitely seems cheaty. – Ad Hoc Garf Hunter Mar 17 at 17:32
• Honestly I think it's a clever 'outside-of-the-box' solution. I'd upvote, but I'm out of votes until tomorrow. – ouflak Mar 17 at 17:35
• @ouflak Thanks for the algorithm guide! How did you know I always write my prototypes with Turing Machines :p – Avi F. S. Mar 19 at 1:01

# 05AB1E, 3 bytes

9L×


Try it online!

9L    Build a list from 1 to 9 {1, 2, 3, 4, 5, 6, 7, 8, 9}
×     copy each number that many times


=ArrayFormula(Rept(Row(1:9),Row(1:9


Sheets will automatically add three trailing parentheses when you exit the cell. Output is one line per row.

• I've run out of votes. – ouflak Mar 17 at 12:37
• @ouflak Darn... – S.S. Anne Mar 17 at 13:18

# Bash + Core utilities, 27, 25 bytes

seq -f8d%f*7-v1+2/n 45|dc


Try it online!

Changed seq formatting from %0.f to %f for a 2-byte savings.

Modified to print on one line, with no delimiters, instead of having a newline after each number, just because I like that better. Same number of bytes.

This uses the formula $$\left\lfloor\frac{\big\lfloor\sqrt{8n-7}\big\rfloor+1}2\right\rfloor$$

for the $$\n^{th}\$$ digit, where $$\n\$$ goes from 1 to 45.

# Python 2, 28 bytes

i=1;exec"printi*i;i+=1;"*9


Try it online!

# R, 18 bytes

a=1:9;(10^a-1)/9*a


Try it online!

Use the formula $$\\frac{10^n-1}{9}\times n\$$ for the $$\n\$$th number.

• Hmm, I may be out of date but isn't the usual ruling that it needs cat() or equivalent to print the output? – user2390246 Mar 17 at 16:44
• @user2390246 yeah, the consensus was changed...a while ago? Late 2017 by my quick search of meta. This is probably what you're aware of but taking that approach with this meta post on compiler flags basically means all R answers are just "R invoked with source(...,echo=TRUE)" – Giuseppe Mar 17 at 18:44
• @Giuseppe thanks for the clarification, I've not been around for a while! Seems like the trend for cat()-type answers ended up being quite a short phase then. – user2390246 Mar 17 at 19:33
• Beat you with a string-only approach! :-) – Giuseppe Mar 18 at 19:07
• @Giuseppe Ooh, nice! – Robin Ryder Mar 18 at 19:16

# APL (dzaima/APL), 6 bytes

Full program, requiring ⎕IO←0.

⍋⍛⌿⍨⎕D


Try it online!

⎕D on the string "0123456789",

⍛⌿⍨ replicate the characters by

⍋ their grade (0, 1, 2, …, 9)

• Isn't \⍨⍳9 at 4 bytes sufficient? I've added it as my own answer, though it doesn't seem to be gaining any traction. Would love feedback! – Avi F. S. Mar 19 at 0:58
• @AviF.S. It wasn't clear that this was a permitted format, but now that OP has clarified, you have my upvote. – Adám Mar 19 at 6:52

# Kotlin, 30 bytes

{(1..9).map{"$it".repeat(it)}}  Try it online! # brainfuck, 56 bytes +++++++[>+++++++<-]+++++++++[<+[>>.<<-<+>]<[>+<-]>>>+<-]  Try it online! +++++++[>+++++++<-] 49 (ASCII "1") +++++++++[ do 9 times <+ add 1 to output counter [ do that many times >>.<< print character -<+> move value of output counter to temp ] <[>+<-] move value of temp back to output counter >>>+ increment character <- decrement loop counter ]  • 50 bytes – Jo King Mar 17 at 9:22 • Thank you. Your code is so different from mine, you should post it as a separate answer. – Dorian Mar 17 at 13:27 # Retina, 12 bytes  9*$.*$.  Try it online! Outputs a leading _ to each number, which appears to be acceptable (would cost 2 bytes to fix if not). Explanation:  9*  Insert 9 _s. $.*$.  Around each _, insert its position repeated appropriately. • The leading _ is absolutely acceptable. – ouflak Mar 17 at 11:31 # APL (Dyalog Unicode), 7 bytesSBCS ⎕D/⍨⍳10  Try it online! Uses ⎕IO←0. ### How it works ⎕D/⍨⍳10 ⎕D ⍝ The string '0123456789' /⍨ ⍝ Replicate each of them the following times... ⍳10 ⍝ 0..9  # Brain-Flak, 90 82 bytes ([(()()())({}){}]){((({})()<([{}]((((()()()){}){}){}){})>)<{({}()<(({}))>)}{}>)}{}  Try it online! ## Explanation: Compare this with the output of JoKing's autogolfer # Brain-Flak, 142 bytes (((((((((((((((((((((((((((((((((((((((((((((((((()()()){}){}){}){}())()))())))()))))())))))()))))))())))))))()))))))))()))))))))){({}<>)<>}<>  Try it online! # Strange delimiters, 78 bytes ([(()()())({}){}]){((({})()<([{}]((((()()()){}){}){}){})>)<{({}()<(({}))>)}>)}  Try it online! If we decide to play around with our delimiters a bit, we can shave off 4 bytes. This version outputs the correct stuff but with two leading null bytes and null bytes between the chunks: This is a tiny bit cheaty but it meets the specs of the challenge. And for posterity here is the old super cheaty version that has been made obsolete by my golfs. # APL (Dyalog Unicode), 4 bytes \⍨⍳9  Try it online! ### How it works ⍳9 ⍝ Integers 1..9 ⍨ ⍝ Duplicate argument on each side \ ⍝ Replicate each element *n* times  ### Examples Index Generator: ⍳5 = 1 2 3 4 5 Expand: 2 3 \ 1 4 = 1 1 4 4 4 Commute: +⍨4 = 4 + 4 = 8  • Feedback: I'd use /⍨⍳9 as it is simpler. / is really "replicate" while \ is the more complex "expand". – Adám Mar 19 at 6:53 # Icon, 27 bytes write(1(i:=1to 9,1to i))&\z  Try it online! # Perl 5, 18 bytes map{say$_ x$_}1..9  Try it online! # Haskell, 30 29 bytes (<$)<*>g<$>g '9' g c=['1'..c]  Try it online! # R, 15 bytes strrep(1:9,1:9)  Try it online! # [Java 11 (JDK)], 60 59 bytes Not sure if thats the shortest approach but couldnt make it shorter even without System.out.print. Output is without delimiters. -1 byte thanks to Kevin Cruijssen v->{for(int i=0;i++<9;System.out.print((i+"").repeat(i)));}  Try it online! • You can save 1 byte changing the ()-> to v->, by taking an empty unused (Void null) argument, which is allowed when it's completely unused. – Kevin Cruijssen Mar 18 at 10:04 • @Kevin Cruijssen Thanks for the suggestion, didn't know about that. I now use an Object as parameter and pass null, is this the intended way or can you actually do it with Void? – greinet Mar 18 at 10:26 • Object null is fine as well. As long as the argument isn't used in any way, not even for static calls, it's ok. That's why I personally use Void, since it has no available static calls anyway. :) – Kevin Cruijssen Mar 18 at 10:27 • Well thats awkward, could've sworn that it just didn't compile with type Void, changed it again and now it works, thanks. – greinet Mar 18 at 10:32 # J, 18 bytes echo u:(#48+])i.10  Try it online! # K (oK), 11 10 bytes -1 byte thanks to ngn! ,/${x}#!10


Try it online!

• ,/${x}#!10 - using filter ({ }#) for replication – ngn Mar 25 at 19:23 • @ngn Thanks, of course! – Galen Ivanov Mar 25 at 19:28 # Keg, 45119 8 bytes 9Ï^⑷:⅍*⑸  Try it online! # PowerShell, 15 bytes 1..9|%{"$_"*$_}  Try it online! # Pure Bash, 41 bytes for k in {1..9};{ echo$[k*(10**k-1)/9];}


Try it online!

# T-SQL, 69 bytes

SELECT top 9replicate(1+number,1+number)FROM spt_values WHERE'p'=type


Try it online

# Jelly, 5 bytes

9ẋ€Ḍ


Try it online!

A niladic link returning a list of integers. If a program printing the numbers is preferred, subsitute Y for Ḍ.

## Explanation

9     | Literal 9
ẋ€  | Repeat each that many times
Ḍ | Convert from decimal digits to integer

• You can drop the trailing Ḍ, based on the comments below the challenge description between xnor and OP. – Kevin Cruijssen Mar 18 at 15:37

# jq (-nr), 20 characters

range(1;10)|"\(.)"*.


Sample run:

bash-5.0$jq -nr 'range(1;10)|"\(.)"*.' 1 22 333 4444 55555 666666 7777777 88888888 999999999  Try it online! # Charcoal, 5 bytes ⭆χ⭆ιι  Try it online! Link is to verbose version of code. Outputs without separators. The first StringMap could be changed into a for statement for the same byte count. Explanation:  χ Predefined variable 10 ⭆ Map over implicit range and join ι Current index ⭆ Map over implicit range and join ι Outer index Implicitly print  # C (gcc), 54 53 bytes i;j;f(){for(i=0;9/++i;)for(j=0;j++<i;)putchar(48+i);}  Try it online! No delimiters between the numbers. # Perl 6, 13 bytes {1..9 Zx^9+1}  Try it online! Anonymous code block that returns a list of strings by zip string multiplying the range 1 to 9 with itself. # W54 3 bytes @π┐  Uncompressed: $*9N


Repeat 1..9 N times.

# Explanation

     M % Map in the range
9      % From 1 to 9
a\$   % Stringify the current counter
a  *  % Repeat that string by the current counter

• Just curious, why do you have the meta link to the command line flags answer? Is that related to your implementation? – ouflak Mar 17 at 11:29
• @ouflak No,that's was part of the copy-pasted template. – petStorm Mar 17 at 11:30
• @ouflak Why is this accepted? The 05AB1E solution is posted before this answer. You should accept that instead. – petStorm Mar 24 at 12:10
• Both were 3 bytes. I just flipped a coin. I can swap them.... – ouflak Mar 24 at 12:41

# JavaScript (ES8), 33 bytes

f=n=>n>9?'':''.padEnd(n,n)+f(-~n)


Try it online!

### Commented

f = n =>            // n = counter, initially undefined
n > 9 ?           // if n is greater than 9:
''              //   stop recursion
:                 // else:
//   this leaves the empty string unchanged for n undefined
+ f(-~n)        //   add the result of a recursive call with n + 1


### Building in reverse order (38 bytes)

A somewhat funny alternate method is to build the string from $$\n=9\$$ to $$\n=1\$$ and pad the recursive call instead of an empty string.

By doing it this way, the required padding length is:

$$L_n=\left\lfloor\frac{n^2}{2}+1\right\rfloor$$

f=(n=9)=>n?f(n-1).padEnd(n*n/2+1,n):''


Try it online!

# Erlang (escript), 49 bytes

f()->[X*(math:pow(10,X)-1)/9||X<-lists:seq(1,9)].
`

Try it online!