38
\$\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.

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Can the delimeters be numbers? \$\endgroup\$
    – Wheat Wizard
    Commented Mar 17, 2020 at 17:16
  • \$\begingroup\$ @AdHocGarfHunter, No. Good catch. Edit: Actually, I think '0' should be acceptable. \$\endgroup\$
    – ouflak
    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\$
    – Wheat Wizard
    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\$
    – ouflak
    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\$
    – AviFS
    Commented Mar 19, 2020 at 1:01

120 Answers 120

2
\$\begingroup\$

naz, 36 bytes

1a1o1a2o1a3o1a4o1a5o1a6o1a7o1a8o1a9o

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

\$\endgroup\$
2
\$\begingroup\$

Ruby, 30 25 bytes

1.upto(9){|i|p 10**i/9*i}

Try it online!

10**i/9 gives a number with i digits, all 1s. Multiply by i for the required output.

\$\endgroup\$
1
  • \$\begingroup\$ 21 bytes: 1.upto(9){|i|p [i]*i}. Going by the comments on the OP I think the output this gives is acceptable. \$\endgroup\$
    – Dingus
    Commented Apr 19, 2020 at 11:00
2
\$\begingroup\$

Zsh, 30 bytes

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

Try it online!

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

\$\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.

\$\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!

\$\endgroup\$
2
\$\begingroup\$

PHP, 37 36 35 bytes

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

Try it online!

-1 byte thanks to @Night2

\$\endgroup\$
4
  • \$\begingroup\$ Do you need the input? \$\endgroup\$
    – ouflak
    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\$
    – Night2
    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.

\$\endgroup\$
2
\$\begingroup\$

Factor, 42 39 bytes

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

Try it online!

Displays a list ot lists

\$\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

\$\endgroup\$
1
  • \$\begingroup\$ even longer than hardcode @echo 122333444455555666666777777788888888999999999 \$\endgroup\$
    – l4m2
    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

\$\endgroup\$
1
  • \$\begingroup\$ I'm still mulling over some kind of challenge that involves an index.... \$\endgroup\$
    – ouflak
    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
\$\endgroup\$
2
\$\begingroup\$

Javascript, 48 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ You can save 2 bytes with : for(x=0;x++<9;){console.log((x+'').repeat(x))} \$\endgroup\$
    – Hedi
    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...

\$\endgroup\$
3
  • \$\begingroup\$ 60 bytes \$\endgroup\$
    – ceilingcat
    Commented Apr 18, 2020 at 3:05
  • \$\begingroup\$ 51 and 59 bytes \$\endgroup\$
    – c--
    Commented Sep 11, 2022 at 23:00
  • \$\begingroup\$ 50 bytes \$\endgroup\$
    – vengy
    Commented Jan 17 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

\$\endgroup\$
2
\$\begingroup\$

dc, 25 24 22 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Pure Bash, 41 37 bytes

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

Try it online!

\$\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)
\$\endgroup\$
4
  • \$\begingroup\$ Without a separator, you could do 9{îÄí, where í pushes the loop limit within a for loop. \$\endgroup\$
    – maxb
    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\$
    – maxb
    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 :)

\$\endgroup\$
2
  • \$\begingroup\$ @ceilingcat so all the imports and func names must be in the code? Thanks for pointing this out! \$\endgroup\$
    – Dion
    Commented May 4, 2020 at 15:44
  • \$\begingroup\$ 67 bytes \$\endgroup\$
    – ceilingcat
    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!

\$\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!

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

cQuents, 6 bytes

#9&$D$

Try it online!

Oh cool, another way to use cQuents!

\$\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!

\$\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
\$\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))
\$\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)
\$\endgroup\$
2
\$\begingroup\$

Python 3, 34 bytes

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

Try it online!

\$\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\$
    – ouflak
    Commented Jun 25, 2020 at 16:28
  • \$\begingroup\$ Ok, thanks! I'll remember that. \$\endgroup\$
    – user95943
    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.

\$\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!

\$\endgroup\$
2
\$\begingroup\$

Husk, 7 bytes

mod´Rḣ9

Try it online!

Husk, 7 bytes

mdg´Ṙḣ9

Try it online!

\$\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.

\$\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\$
    – ovs
    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\$
    – ovs
    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\$
    – ouflak
    Commented Oct 8, 2020 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.