32
\$\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
    Mar 17, 2020 at 17:16
  • \$\begingroup\$ @AdHocGarfHunter, No. Good catch. Edit: Actually, I think '0' should be acceptable. \$\endgroup\$
    – ouflak
    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
    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
    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
    Mar 19, 2020 at 1:01

95 Answers 95

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
    Jan 1 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\$
1
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
    Apr 22, 2020 at 9:38
  • \$\begingroup\$ @maxb Ah, nice golf. Out of curiosity, why doesn't it work when the Ä is {? \$\endgroup\$ Apr 22, 2020 at 9:46
  • \$\begingroup\$ @maxb It does seem to work if I add two trailing }: try 9{î{í}} online. \$\endgroup\$ 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
    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
    May 4, 2020 at 15:44
  • \$\begingroup\$ 67 bytes \$\endgroup\$
    – ceilingcat
    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
    Mar 22, 2020 at 12:59
2
\$\begingroup\$

C (gcc), 47 bytes

k;main(i){for(;9>printf("%d",i*++k);i=i*10+1);}

Try it online!

C (gcc), 49 bytes

main(i){for(;9>printf("%lX",(i*1L<<4*i++)/15););}

Try it online!

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

Canvas, 6 bytes

9{:ŗ×]

Try it here!

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

Wolfram Language (Mathematica), 17 bytes

Table[,{,9},{a,}]

Try it online!

thanks @att

\$\endgroup\$
2
  • \$\begingroup\$ 18 bytes (list of lists of digits, which based on comments should be fine) \$\endgroup\$
    – att
    Oct 9, 2020 at 6:15
  • \$\begingroup\$ 17 bytes \$\endgroup\$
    – att
    Dec 19, 2021 at 3:14
2
\$\begingroup\$

APOL, 21 bytes

ⅎ(9 p(*(t(∈) ∈)))

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

Pip, 5 bytes

,tX,t

Attempt This Online!

Explanation

,t     Range(10)
  X    String-repeat (itemwise)
   ,t  Range(10)

That is, for each number in [0; 1; 2; 3; 4; 5; 6; 7; 8; 9], repeat it a number of times equal to itself. The result is the list [""; 1; 22; 333; 4444; 55555; 666666; 7777777; 88888888; 999999999], which is by default concatenated together and printed.

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

Excel, 29 24 bytes

Saved 5 bytes thanks to Taylor Raine

=REPT(ROW(1:9),ROW(1:9))

ROW(1:9) returns an array of the numbers 1 through 9 so the REPT() function repeats each of those numbers itself-many times.

Screenshot

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can make this shorter by dropping the Let and using Row(1:9) instead - =REPT(ROW(1:9),ROW(1:9)) \$\endgroup\$ Jan 10 at 15:32
1
\$\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
    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
    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
    Oct 8, 2020 at 19:59
1
\$\begingroup\$

mlochbaum/BQN, 7 bytes

⥊˜¨1+↕9

Try it!

Explanation

⥊˜¨1+↕9
     ↕9 range from 0 to 8
   1+   add 1 to each
  ¨     for each element n,
⥊˜      replicate n times
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Alternative 7 bytes (with different format): ∾⥊˜¨↕10. Also, ⥊˜¨↕10 (6 bytes) could be used if a leading empty list is fine (it probably is). \$\endgroup\$ Dec 23, 2020 at 16:45
1
\$\begingroup\$

AWK, 32 or 37 bytes

This code needs an EOF at the prompt, or a file with an empty line.

{for(;++i<10;)print(10^i-1)/9*i}

Try it online!

To substitute the input, one can use the BEGIN pattern, adding 5 more bytes to the code.

BEGIN{for(;++i<10;)print(10^i-1)/9*i}
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 50 bytes

_=>{for(i=0;++i<10;)console.log((''+i).repeat(i))}
\$\endgroup\$
1
\$\begingroup\$

Factor, 29 bytes

9 [1,b] [ dup <array> ] map .

Try it online!

\$\endgroup\$
1
\$\begingroup\$

A0A0, 46 bytes

O122333444455555666666777777788888888999999999

Literally prints the example output. I'd be very surprised if you can get something smaller in A0A0. The first O outputs the number following it and the number following it is the output. The language specification does not state any restriction on the size of the number, just "signed integer", so this works. (Although an interpreter may not handle this correctly, because this is a 147 bit number and not every language may support numbers that large.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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