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

2
\$\begingroup\$

Batch, 74 bytes

@set s=
@for /l %%i in (1,1,9)do @call set s=%%s%%0&call echo %%s:0=%%i%%

Outputs on separate lines. Extends the string length by 1 and replaces the character with the current digit for each output.

The call commands are required so that the variable s is processed inside the loop instead of before parsing the loop.

answered Mar 17, 2020 at 20:35
\$\endgroup\$
2
\$\begingroup\$

naz, 36 bytes

1a1o1a2o1a3o1a4o1a5o1a6o1a7o1a8o1a9o

Outputs all the numbers with no extra delimiter, using the same functionality described in this answer.

answered Mar 18, 2020 at 0:52
\$\endgroup\$
2
\$\begingroup\$

Zsh, 30 bytes

repeat 9 echo ${(pl[++i][$i])}

Try it online!

The (l[width][fill]) flag does the heavy lifting.

answered Mar 18, 2020 at 6:19
\$\endgroup\$
2
\$\begingroup\$

Red, 30 bytes

repeat a 9[repeat b a[prin a]]

Try it online!

Well, the most obvious way to do it is the shortest in Red.

answered Mar 18, 2020 at 7:11
\$\endgroup\$
2
\$\begingroup\$

IBM/Lotus Notes Formula Language, 56 bytes

@For(x:=1;x<10;x:=x+1;@Set("o";o:@Repeat(@Text(x);x)));o

enter image description here

Formula in a multi value form field, once again showing that the only real use for @For in Notes is Code Golf!

answered Mar 18, 2020 at 9:19
\$\endgroup\$
2
\$\begingroup\$

PHP, (削除) 37 (削除ここまで) (削除) 36 (削除ここまで) 35 bytes

for(;10>$j=++$i;)for(;$j--;)echo$i;

Try it online!

-1 byte thanks to @Night2

answered Mar 17, 2020 at 11:17
\$\endgroup\$
4
  • \$\begingroup\$ Do you need the input? \$\endgroup\$ Commented Mar 17, 2020 at 11:19
  • 1
    \$\begingroup\$ Nope, removed thanks. I'm so used to using the -F option, I did it without thinking. \$\endgroup\$ Commented Mar 17, 2020 at 11:21
  • \$\begingroup\$ 35 bytes \$\endgroup\$ Commented Mar 18, 2020 at 9:26
  • \$\begingroup\$ Interesting lesson in precedence rules. \$\endgroup\$ Commented Mar 18, 2020 at 12:55
2
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 47 bytes

O OUTPUT =DUPL(X,X)
 X =LT(X,9) X + 1 :S(O)
END

Try it online!

Prints with a leading newline.

answered Mar 18, 2020 at 13:10
\$\endgroup\$
2
\$\begingroup\$

Factor, (削除) 42 (削除ここまで) 39 bytes

9 [1,b] [ dup 1array swap cycle ] map .

Try it online!

Displays a list ot lists

answered Mar 18, 2020 at 7:55
\$\endgroup\$
2
\$\begingroup\$

Batch, 85 Bytes

@for /L %%A in (1 1 9)do @For /L %%B in (1 1 %%A)do @Call Set O=%%O%%%%A @Echo(%O%

TIO not available.

enter image description here

answered Mar 21, 2020 at 5:21
\$\endgroup\$
1
  • \$\begingroup\$ even longer than hardcode @echo 122333444455555666666777777788888888999999999 \$\endgroup\$ Commented Apr 22, 2020 at 8:36
2
\$\begingroup\$

Whitespace, 109 bytes

[S S S T S S T N
_Push_9][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][N
S S S N
_Create_Label_INNER_LOOP][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate_top][N
T S T N
_If_0_Jump_to_Label_DONE_INNER_LOOP][S T S S T N
_Copy_0-based_1st][S N
T _Swap_top_two][N
S N
S N
_Jump_to_Label_INNER_LOOP][N
S S T N
_Create_Label_DONE_INNER_LOOP][S N
N
_Discard_top][S N
S _Duplicate_top][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate_top][N
T S S S N
_If_0_Jump_to_Label_DONE_LOOP][N
S N
N
_Jump_to_Label_LOOP][N
S S S S N
_Create_Label_DONE_LOOP][S N
N
_Discard_top][N
S S S T N
_Create_Label_PRINT_LOOP][T N
S T _Print_top_as_integer][N
S N
S T N
_Jump_to_Label_PRINT_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Push n=9
Start LOOP:
 Duplicate top (Integer i = n)
 Start INNER_LOOP
 i = i - 1
 if(i == 0):
 Jump to DONE_INNER_LOOP
 Copy n (0-based index 1)
 Swap
 Go to next iteration of INNER_LOOP
 DONE_INNER_LOOP:
 Discard i
 n = n - 1
 if(n == 0):
 Jump to DONE_LOOP
 Go to next iteration of LOOP
DONE_LOOP:
 Discard n
 Start PRINT_LOOP:
 Print top as integer
 Go to next iteration of PRINT_LOOP

Funny thing is, is that outputting with the additional single leading 0 as the challenge in the Sandbox initially had, this could have been 11 bytes shorter: try it online. xD

answered Mar 19, 2020 at 15:49
\$\endgroup\$
1
  • \$\begingroup\$ I'm still mulling over some kind of challenge that involves an index.... \$\endgroup\$ Commented Mar 19, 2020 at 15:51
2
\$\begingroup\$

Gol><>, 8 bytes

aFLRL|D;

Try it online!

aF | For Loop, from 0 to 10 excluding 10
 L Push the current loop iteration to the stack
 RL Pop the current iteration and repeat pushing the loopiterator value so many times
 D; Print the entire stack content as numeric values with the debug operation and halt
answered Mar 28, 2020 at 16:45
\$\endgroup\$
2
\$\begingroup\$

Javascript, 48 bytes

for(x=1;x<=9;x++){console.log((x+'').repeat(x))}

Try it online!

answered Apr 17, 2020 at 23:28
\$\endgroup\$
1
  • \$\begingroup\$ You can save 2 bytes with : for(x=0;x++<9;){console.log((x+'').repeat(x))} \$\endgroup\$ Commented Jan 1, 2022 at 11:45
2
\$\begingroup\$

C++ (gcc), (削除) 93 (削除ここまで), 65 bytes

int a;void n(){int b=a;while(b){std::cout<<a;b--;}if(a++!=9)n();}

Try it online!

The loop work is essentially the same as the previous version, but instead its own function.

It sets the starting digit -> 1 -> counter then it prints digits until the counter reaches 0. At that point it increments the digit and recalls the function until 9.

C++ (gcc), 93 bytes

int main(int n){static int a=1;int b=a;if(b>9)return 0;while(b){std::cout<<a;b--;}main(a++);}

Try it online!

Don't mind the main...

answered Apr 18, 2020 at 2:11
\$\endgroup\$
3
  • \$\begingroup\$ 60 bytes \$\endgroup\$ Commented Apr 18, 2020 at 3:05
  • \$\begingroup\$ 51 and 59 bytes \$\endgroup\$ Commented Sep 11, 2022 at 23:00
  • \$\begingroup\$ 50 bytes \$\endgroup\$ Commented Jan 17, 2024 at 20:37
2
\$\begingroup\$

vJASS, 126 bytes

//! zinc
library q{function onInit(){integer x,y;string s="";for(1<=x<10){for(0<=y<x){s+=I2S(x);}}BJDebugMsg(s);}}
//! endzinc

enter image description here

answered Apr 17, 2020 at 1:48
\$\endgroup\$
2
\$\begingroup\$

dc, (削除) 25 (削除ここまで) (削除) 24 (削除ここまで) 22 bytes

1[ddIr^9/*n1+dA>m]dsmx

Try it online!

answered Apr 22, 2020 at 6:23
\$\endgroup\$
2
\$\begingroup\$

Pure Bash, (削除) 41 (削除ここまで) 37 bytes

for k in {1..9};{ echo $[10**k/9*k];}

Try it online!

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

MathGolf, (削除) 6 (削除ここまで) 5 bytes

9{îÄí

-1 byte thanks to @maxb.

Try it online.

Explanation:

9{ # Loop 9 times:
 î # Push the 1-based loop index
 Ä # Do an inner loop that many times, using a single command:
 í # Push the total number iterations of the outer loop
 # (after the loops, the entire stack is joined together and output implicitly)
answered Mar 19, 2020 at 8:58
\$\endgroup\$
4
  • \$\begingroup\$ Without a separator, you could do 9{îÄí, where í pushes the loop limit within a for loop. \$\endgroup\$ Commented Apr 22, 2020 at 9:38
  • \$\begingroup\$ @maxb Ah, nice golf. Out of curiosity, why doesn't it work when the Ä is {? \$\endgroup\$ Commented Apr 22, 2020 at 9:46
  • \$\begingroup\$ @maxb It does seem to work if I add two trailing }: try 9{î{í}} online. \$\endgroup\$ Commented Apr 22, 2020 at 9:52
  • \$\begingroup\$ There are some issues with implicit block closure with nested loops. you can omit the last } at the end of the script if you have a single loop, but not if you have two or more nested loop blocks which are opened by {. \$\endgroup\$ Commented Apr 22, 2020 at 11:53
2
\$\begingroup\$

Python 3, 38 bytes

print([str(x)*x for x in range(1,10)])

Try it online!

C++ (gcc), 59 bytes

for(int i=1;i<10;++i){for(int x=1;x<=i;++x){std::cout<<i;}}

Try it online!

Started learning c++ an hour ago, tried codegolf :)

answered Apr 3, 2020 at 20:37
\$\endgroup\$
2
  • \$\begingroup\$ @ceilingcat so all the imports and func names must be in the code? Thanks for pointing this out! \$\endgroup\$ Commented May 4, 2020 at 15:44
  • \$\begingroup\$ 67 bytes \$\endgroup\$ Commented May 4, 2020 at 16:43
2
\$\begingroup\$

Common Lisp, 50 bytes

(loop for x from 1 to 9 do(dotimes(n x)(write x)))

Try it online!

answered May 6, 2020 at 8:18
\$\endgroup\$
2
\$\begingroup\$

Fortran (GFortran), (削除) 38 (削除ここまで) 28 bytes

print*,(10**i/9*i,i=1,9)
end

Try it online!

Edit: Turns out the program statement is optional, saving 10 bytes!

answered Mar 22, 2020 at 12:50
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'm glad somebody did a Fortran answer. \$\endgroup\$ Commented Mar 22, 2020 at 12:59
2
\$\begingroup\$

cQuents, 6 bytes

#9&$D$

Try it online!

Oh cool, another way to use cQuents!

answered May 26, 2020 at 9:46
\$\endgroup\$
2
\$\begingroup\$

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

for(int j,i=0;i++<9;)for(j=i;j-->0;Write(i));

Try it online!

answered Jun 22, 2020 at 10:02
\$\endgroup\$
2
\$\begingroup\$

MAWP 0.1, (削除) 22 (削除ここまで) 20 bytes

[![~!:~1A]%!9A?.%1M]

Explanation:

[ start of loop
! duplicates top of stack
[ start of loop
~!:~ prints bottom stack value
1A subtracts 1
] end of loop
% removes top of stack (0 from the counter in the previous loop)
!9A diffeence between top value and 9
?. if top 0, then terminate program
% removes top value
1M adds 1 to top value
] end of loop
answered Jun 22, 2020 at 9:25
\$\endgroup\$
2
\$\begingroup\$

Clojure, 32 bytes

(for[i(range 1 10)](repeat i i))

This results in a lists of numbers:

((1) (2 2) (3 3 3) (4 4 4 4) (5 5 5 5 5) (6 6 6 6 6 6) (7 7 7 7 7 7 7) (8 8 8 8 8 8 8 8) (9 9 9 9 9 9 9 9 9))
answered Jun 22, 2020 at 18:08
\$\endgroup\$
2
\$\begingroup\$

International Phonetic Esoteric Language, 21 bytes

{A}1ɑee0ɑbue1søɒe1søɒ

Prints 122333444455555666666777777788888888999999999.

Explanation:

{A}1ɑee0ɑbue1søɒe1søɒ
{A}1 (push loop bounds, 1 to 10)
 ɑ (start loop)
 e (push the current index)
 e0 (push loop bounds for current digit, 0 to index)
 ɑ (start loop)
 bu (DUP and CPRINT current digit)
 e1sø (increment index)
 ɒ (end loop)
 e1sø (increment index)
 ɒ (end loop)
answered Jun 23, 2020 at 17:14
\$\endgroup\$
2
\$\begingroup\$

Python 3, 34 bytes

for i in range(10):print(str(i)*i)

Try it online!

caird coinheringaahing
50.9k11 gold badges133 silver badges364 bronze badges
answered Jun 25, 2020 at 13:15
\$\endgroup\$
2
  • \$\begingroup\$ You can get your answer formatted in the standard format used on this site, over here. Just put your code in and click on the link symbol above. That will take you to another page where you will find the Code Golf format option (pasted into your clipboard). You can then just paste that into your answer. \$\endgroup\$ Commented Jun 25, 2020 at 16:28
  • \$\begingroup\$ Ok, thanks! I'll remember that. \$\endgroup\$ Commented Jun 25, 2020 at 19:44
2
\$\begingroup\$

brainfuck, 50 bytes

+[>+<+++++]+++++++++[>-->+[<.>>+<-]>[<+>-]<<+++<-]

Try it online!

Assumes byte cells; does not go out of bounds to left.

lyxal
35.6k2 gold badges69 silver badges148 bronze badges
answered Oct 9, 2020 at 0:59
\$\endgroup\$
2
\$\begingroup\$

Poetic, 222 bytes

THE NUMERICAL I/O RULES
i saw a digit,o yes
o,again,i saw a number;too many
i do the I/O rules,i get a repeat
i now count to zeros
o,from one right to nine,i do digits,e.t.c
seldom a newline,since i know i am swayed not to

Try it online!

answered Oct 9, 2020 at 1:20
\$\endgroup\$
2
\$\begingroup\$

Husk, 7 bytes

mod ́Rḣ9

Try it online!

Husk, 7 bytes

mdg ́Ṙḣ9

Try it online!

answered Oct 9, 2020 at 5:39
\$\endgroup\$
2
\$\begingroup\$

Rust, (削除) 77 (削除ここまで) (削除) 75 (削除ここまで) (削除) 73 (削除ここまで) (削除) 72 (削除ここまで) (削除) 57 (削除ここまで) 56 bytes

fn main(){for k in 1..10{for j in 0..k{print!("{}",k)}}}

Try it online!

And I thought Lua was verbose!

Thanks to ovs for saving 15 bytes.

answered Oct 8, 2020 at 19:17
\$\endgroup\$
3
  • \$\begingroup\$ You don't need i, 0..k and println!("{}",i) works just fine. Then you can use a closure instead of a full program like this: ||for i in 1..10{for j in 0..k{println!("{}",k)}}. \$\endgroup\$ Commented Oct 8, 2020 at 19:54
  • 1
    \$\begingroup\$ And returning an iterator instead of printing the result is a little shorter: tio.run/… \$\endgroup\$ Commented Oct 8, 2020 at 19:57
  • \$\begingroup\$ @ovs, Wow. This is the first time I've coded anything in Rust (we've just adopted it at my workplace), so it's clear I've got a lot to learn. I'm still trying to wrap my head around how the closures work. I'm using print! instead. That seems to work. \$\endgroup\$ Commented Oct 8, 2020 at 19:59

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.