39
\$\begingroup\$

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

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

122 Answers 122

1
2 3 4 5
31
\$\begingroup\$

Google Sheets, 35 bytes

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

results

answered Mar 17, 2020 at 12:34
\$\endgroup\$
2
  • \$\begingroup\$ I've run out of votes. \$\endgroup\$ Commented Mar 17, 2020 at 12:37
  • \$\begingroup\$ @ouflak Darn... \$\endgroup\$ Commented Mar 17, 2020 at 13:18
16
\$\begingroup\$

05AB1E, 3 bytes

×ばつ

Try it online!

9L Build a list from 1 to 9 {1, 2, 3, 4, 5, 6, 7, 8, ×ばつ copy each number that many times
answered Mar 17, 2020 at 8:58
\$\endgroup\$
0
16
\$\begingroup\$

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.

answered Mar 17, 2020 at 7:47
\$\endgroup\$
0
11
\$\begingroup\$

Python 2, 28 bytes

i=1;exec"print`i`*i;i+=1;"*9

Try it online!

answered Mar 17, 2020 at 7:24
\$\endgroup\$
0
10
\$\begingroup\$

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.

answered Mar 17, 2020 at 8:18
\$\endgroup\$
5
  • \$\begingroup\$ Hmm, I may be out of date but isn't the usual ruling that it needs cat() or equivalent to print the output? \$\endgroup\$ Commented Mar 17, 2020 at 16:44
  • 1
    \$\begingroup\$ @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)" \$\endgroup\$ Commented Mar 17, 2020 at 18:44
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Mar 17, 2020 at 19:33
  • \$\begingroup\$ Beat you with a string-only approach! :-) \$\endgroup\$ Commented Mar 18, 2020 at 19:07
  • \$\begingroup\$ @Giuseppe Ooh, nice! \$\endgroup\$ Commented Mar 18, 2020 at 19:16
9
\$\begingroup\$

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)

answered Mar 17, 2020 at 7:21
\$\endgroup\$
2
  • \$\begingroup\$ 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! \$\endgroup\$ Commented Mar 19, 2020 at 0:58
  • \$\begingroup\$ @AviF.S. It wasn't clear that this was a permitted format, but now that OP has clarified, you have my upvote. \$\endgroup\$ Commented Mar 19, 2020 at 6:52
9
\$\begingroup\$

Kotlin, 30 bytes

{(1..9).map{"$it".repeat(it)}}

Try it online!

answered Mar 17, 2020 at 7:51
\$\endgroup\$
7
\$\begingroup\$

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
answered Mar 18, 2020 at 5:24
\$\endgroup\$
1
  • \$\begingroup\$ Feedback: I'd use /⍨⍳9 as it is simpler. / is really "replicate" while \ is the more complex "expand". \$\endgroup\$ Commented Mar 19, 2020 at 6:53
6
\$\begingroup\$

Perl 5, 18 bytes

map{say$_ x$_}1..9

Try it online!

answered Mar 17, 2020 at 8:41
\$\endgroup\$
6
\$\begingroup\$

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
]
answered Mar 17, 2020 at 9:11
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$ Commented Mar 17, 2020 at 9:22
  • 2
    \$\begingroup\$ Thank you. Your code is so different from mine, you should post it as a separate answer. \$\endgroup\$ Commented Mar 17, 2020 at 13:27
6
\$\begingroup\$

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.

answered Mar 17, 2020 at 10:55
\$\endgroup\$
1
  • \$\begingroup\$ The leading _ is absolutely acceptable. \$\endgroup\$ Commented Mar 17, 2020 at 11:31
6
\$\begingroup\$

Haskell, (削除) 30 (削除ここまで) 29 bytes

(<$)<*>g<$>g '9'
g c=['1'..c]

Try it online!

answered Mar 17, 2020 at 13:53
\$\endgroup\$
5
\$\begingroup\$

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
answered Mar 17, 2020 at 7:20
\$\endgroup\$
5
\$\begingroup\$

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.

answered Mar 17, 2020 at 16:57
\$\endgroup\$
5
\$\begingroup\$

Husk, 5 bytes

d ́Ṙḣ9

Try it online!

Output: 122333444455555666666777777788888888999999999.

answered Sep 8, 2022 at 13:33
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf! \$\endgroup\$ Commented Sep 8, 2022 at 13:34
  • \$\begingroup\$ Thank you a lot! :) \$\endgroup\$ Commented Sep 9, 2022 at 11:57
4
\$\begingroup\$

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
answered Mar 17, 2020 at 9:56
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can drop the trailing , based on the comments below the challenge description between xnor and OP. \$\endgroup\$ Commented Mar 18, 2020 at 15:37
4
\$\begingroup\$

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.

answered Mar 17, 2020 at 11:57
\$\endgroup\$
4
\$\begingroup\$

R, 15 bytes

strrep(1:9,1:9)

Try it online!

answered Mar 17, 2020 at 23:37
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Just rep(1:9,1:9) is shorter (and gives exactly the output of the first example)? \$\endgroup\$ Commented Jun 24, 2020 at 22:50
4
\$\begingroup\$

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!

answered Mar 17, 2020 at 8:12
\$\endgroup\$
3
  • 1
    \$\begingroup\$ ,/${x}#!10 - using filter ({ }#) for replication \$\endgroup\$ Commented Mar 25, 2020 at 19:23
  • \$\begingroup\$ @ngn Thanks, of course! \$\endgroup\$ Commented Mar 25, 2020 at 19:28
  • 1
    \$\begingroup\$ I think echo#~1+i.10 is ok too since any delimiter is allowed. \$\endgroup\$ Commented Jan 3, 2022 at 4:50
4
\$\begingroup\$

C (gcc), 46 bytes

s;main(n){n>9||main(puts(memset(&s,n+48,n)));}

Try it online!

answered Mar 17, 2020 at 16:42
\$\endgroup\$
2
  • \$\begingroup\$ can't be called twice \$\endgroup\$ Commented Apr 22, 2020 at 16:13
  • \$\begingroup\$ Thanks for catching that :) \$\endgroup\$ Commented Apr 22, 2020 at 16:18
4
\$\begingroup\$

x86-16 machine code, IBM PC DOS, (削除) 18 (削除ここまで) 16 bytes

Binary:

00000000: b839 0ab2 09b1 2dcd 1048 2aca 4a75 f8c3 .9....-..H*.Ju..

Listing:

B8 0A39 MOV AX, 0A39H ; AH = 0AH, AL = '9'
B2 0A MOV DL, 10 ; DL as counter value
B1 2D MOV CL, 1+2+3+4+5+6+7+8+9 ; start digit repeat 45 times
 NLOOP:
CD 10 INT 10H ; call BIOS - write digit * CX times
48 DEC AX ; decrement ASCII digit
4A DEC DX ; decrement counter value
2A CA SUB CL, DL ; reduce digit repeat value by counter
75 F8 JNZ NLOOP ; loop until 0 
C3 RET ; return to DOS

Try it online!

Explanation:

This uses the PC BIOS API's INT 10H / 0AH function to write the ASCII char in AL to the screen CX number of times. However, this function does not update the cursor position to the end of the output -- it just stays where it started. In other words, the next call simply overstrikes existing characters writing over them. Making a BIOS call to advance the cursor is expensive byte-wise.

Since going forward isn't going to work, we go backwards starting from '9'. It writes '9' 45 times, then '8' 36 times, '7' 28 times, etc -- each time starting from the first column overwriting like so:

999999999999999999999999999999999999999999999
888888888888888888888888888888888888999999999
777777777777777777777777777788888888999999999
666666666666666666666777777788888888999999999
555555555555555666666777777788888888999999999
444444444455555666666777777788888888999999999
333333444455555666666777777788888888999999999
222333444455555666666777777788888888999999999
122333444455555666666777777788888888999999999

Output:

enter image description here

answered Jun 24, 2020 at 13:52
\$\endgroup\$
4
\$\begingroup\$

Java 11 (JDK), (削除) 60 (削除ここまで) 59 bytes

Not sure if thats the shortest approach but couldn`t 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!

caird coinheringaahing
50.9k11 gold badges133 silver badges364 bronze badges
answered Mar 17, 2020 at 14:33
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Mar 18, 2020 at 10:04
  • \$\begingroup\$ @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? \$\endgroup\$ Commented Mar 18, 2020 at 10:26
  • \$\begingroup\$ 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. :) \$\endgroup\$ Commented Mar 18, 2020 at 10:27
  • \$\begingroup\$ Well thats awkward, could've sworn that it just didn't compile with type Void, changed it again and now it works, thanks. \$\endgroup\$ Commented Mar 18, 2020 at 10:32
4
\$\begingroup\$

Haskell, 21 bytes

[c<$[1..c]|c<-[1..9]]

Try it online!

A list of lists of numbers.

23 bytes

replicate<*>id=<<[1..9]

Try it online!

A flat list of numbers.

pxeger
25.3k4 gold badges59 silver badges146 bronze badges
answered Mar 17, 2020 at 17:54
\$\endgroup\$
2
  • \$\begingroup\$ I think that the delimiter has to be in between differing digits (e.g. 1 and 2 as opposed to 8 and another 8). \$\endgroup\$ Commented Mar 17, 2020 at 18:06
  • \$\begingroup\$ @AdHocGarfHunter Looking again at the challenge, I'm not clear on this so I asked. I think it would be unfortunate if the flat list in the second version were invalid too. \$\endgroup\$ Commented Mar 17, 2020 at 18:14
4
\$\begingroup\$

Julia, 22 bytes

1:9 .|>i->show("$i"^i)

Attempt This Online!

prints

"1""22""333""4444""55555""666666""7777777""88888888""999999999"

Relying on the repl for printing output we can get to 17 bytes

~i="$i"^i;.~(1:9)
answered Sep 9, 2022 at 15:06
\$\endgroup\$
4
\$\begingroup\$

Fig, \6ドル\log_{256}(96)\approx\$ 4.939 bytes

Mcd'*_

Try it online!

Lyxal tried to outgolf me in my own language again.

Mcd'*_ # Full program
 cd # Digits
M ' # Map each digit string
 * # Repeat the digit
 _ # By the number form of it
answered Sep 8, 2022 at 18:50
\$\endgroup\$
3
\$\begingroup\$

Deadfish~, 194 bytes

{{i}ddddd}dc{d}{d}iiic{i}{i}ddcc{d}{d}iic{i}{i}dccc{d}{d}ic{i}{i}cccc{d}{d}c{i}{i}iccccc{d}{d}dc{i}{i}iicccccc{d}{d}ddc{i}{i}iiiccccccc{d}{d}dddc{i}{i}iiiicccccccc{d}{d}ddddc{i}{i}iiiiiccccccccc

Try it online!

answered Feb 24, 2021 at 9:19
\$\endgroup\$
6
  • \$\begingroup\$ Understandable. \$\endgroup\$ Commented Jun 12, 2021 at 11:38
  • \$\begingroup\$ @lyxal ???? (filler) \$\endgroup\$ Commented Jun 12, 2021 at 11:39
  • \$\begingroup\$ @wasif the reason it was accepted \$\endgroup\$ Commented Jun 12, 2021 at 11:40
  • 1
    \$\begingroup\$ 159 bytes, and 128 separating by zeros. \$\endgroup\$ Commented Sep 8, 2022 at 23:53
  • 1
    \$\begingroup\$ Actually, 61 since delimiters aren't even required. \$\endgroup\$ Commented Sep 8, 2022 at 23:55
3
\$\begingroup\$

PowerShell, 15 bytes

1..9|%{"$_"*$_}

Try it online!

answered Mar 17, 2020 at 7:33
\$\endgroup\$
3
\$\begingroup\$

Icon, 27 bytes

write(1(i:=1to 9,1to i))&\z

Try it online!

answered Mar 17, 2020 at 7:47
\$\endgroup\$
3
\$\begingroup\$

T-SQL, 69 bytes

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

Try it online

answered Mar 17, 2020 at 8:47
\$\endgroup\$
2
  • \$\begingroup\$ Nice code. Sometimes I wonder how well T-SQL would do in these challenges if we had a built-in number table or some equivalent to PostgreSQL's generate-series() function. \$\endgroup\$ Commented May 26, 2020 at 15:48
  • 1
    \$\begingroup\$ @BradC normally SQL will not win in these golfing questions even with improved features. When we use a command like replicate(a,b), some of the other languages can solve problem with fewer characters than the 14 characters(minimum) it takes to call that function. The best we can do it solve the problems using a language which usually isn't optimal, and hope some people are impressed enough to up-vote those solutions. \$\endgroup\$ Commented May 27, 2020 at 11:29
3
\$\begingroup\$

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
answered Mar 17, 2020 at 10:48
\$\endgroup\$
1
2 3 4 5

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.