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.

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

122 Answers 122

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
    Commented Oct 9, 2020 at 6:15
  • \$\begingroup\$ 17 bytes \$\endgroup\$
    – att
    Commented 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
  • 2
    \$\begingroup\$ You can make this shorter by dropping the Let and using Row(1:9) instead - =REPT(ROW(1:9),ROW(1:9)) \$\endgroup\$ Commented Jan 10, 2022 at 15:32
2
\$\begingroup\$

Desmos, 21 bytes

l=[1...9]
l10^l/9-l/9

Try It On Desmos!

Try It On Desmos! - Prettified

Uses the following formula for the \$n\$th number: $$\frac{10^n-1}9\times n$$ [1,22,333,4444,55555,666666,7777777,88888888,999999999] is the value of the list in the second line.

Made it look "obfuscated" for fun but it's really just the same as:

l=[1...9]
l(10^l-1)/9

which is also 21 bytes.

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

Regenerate, 15 bytes

(#1{#1} ! ){10}

Outputs space-separated runs of digits, with a leading and a trailing space. Attempt This Online!

Explanation

Spaces are replaced with underscores for clarity.

(#1{#1}_!_){10}
           {10}  Repeat 10 times
(         )      and store as group 1 after each match:
 #1                Length of previous match of group 1
   {#1}            repeated (length of previous match of group 1) times
       _           followed by a space
        !          Or, if that failed because there was no previous match of group 1,
         _         just a space

The first match of group 1 is a space, which has length 1, so the second match is one 1 followed by a space, which has length 2, so the third match is two 2's followed by a space, and so forth.

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

Prolog (SWI), 43 bytes

:-between(1,9,N),between(1,N,_),\+write(N).

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ -1 byte \$\endgroup\$
    – Jo King
    Commented Sep 12, 2022 at 4:15
2
\$\begingroup\$

Headass, 31 bytes

+^{{D^(]<)PN][}:(+++[]]]>)N^-[}

Try It Online!

Beats the naive solution (+P+PP+PPP... and so on for 54 bytes) by 23 bytes.

Outputs individual digits separated by newlines

Breakdown:

+^{{D^(]<)PN][}:(+++[]]]>)N^-[}  full program

+^                               initialize r1 to be 1
                                 r2 is already initialized to 0
  {                           }  repeat
    D^(  )     :(        )       until r1
                 +++[]]]>        fails to be less than 9
   {          }                    repeat
    D^(  )                         until r1
       ]<                          fails to be more than r2
    D     P                          print r1
           N][                       increment r2
                                   end repeat
                          N^       increment r1
                          N -[     set r2 to 0
                                 end repeat
\$\endgroup\$
1
  • \$\begingroup\$ this 25 byter takes n and outputs the number n*(n 1s in a row): U({D+^-)DD]P:]]]]]]]]]][}. I don't think I can iterate from 1-9 with just 5 bytes though... \$\endgroup\$ Commented Sep 10, 2023 at 1:00
2
\$\begingroup\$

yup, 43 41 bytes

0e:{~:{~:#~0e-}0e--:0ee00e--|00e--e0e-~-}

Try it online.

Explanation:

0e           # Push 1 (push 0; pop and push exp(0))
  :          # Duplicate it
   {         # Loop while the top of the stack is >0 (without popping):
    ~        #  Swap the top two values on the stack
     :       #  Duplicate the top
      {      #  Inner loop while the top of the stack is >0 (without popping):
       ~     #   Swap the top two values on the stack
        :    #   Duplicate the top
         #   #   Pop and print it as number
       ~     #   Swap the top two values on the stack back
        0e-  #   Decrease it by 1 (push 0; pop and push exp(0); subtract)
      }      #  Stop the inner loop if the top of the stack is <=0 (without popping)
       0e--  #  Increase the current value by 1 (using the 0 that was still on the
             #  stack as: push 0 → exp(0)=1 → 0-1=-1 → --1=+1)
       :     #  Duplicate the top again
        0ee00e--|00e--e0e-
             #  Push 9.107... (see below)
         ~   #  Swap the top two values again
          -  #  Subtract the current value from the 9.107...
   }         # Stop the outer loop if the top of the stack is <=0 (without popping)
             # (which it will be once we've reached 10)

0ee00e--|00e--e0e- # Push 9.107...:
0                  #  Push 0        - STACK: 0
 e                 #  exp(0)        - STACK: 1
  e                #  exp(1)        - STACK: 2.718...
   0               #  Push 0        - STACK: 2.718...,0
    0              #  Push 0        - STACK: 2.718...,0,0
     e             #  exp(0)        - STACK: 2.718...,0,1
      -            #  Subtract      - STACK: 2.718...,-1
       -           #  Subtract      - STACK: 3.718...
        |          #  ln(3.718...)  - STACK: 1.313...
         0         #  Push 0        - STACK: 1.313...,0
          0        #  Push 0        - STACK: 1.313...,0,0
           e       #  exp(0)        - STACK: 1.313...,0,1
            -      #  Subtract      - STACK: 1.313...,-1
             -     #  Subtract      - STACK: 2.313...
              e    #  exp(2.313...) - STACK: 10.107...
               0   #  Push 0        - STACK: 10.107...,0
                e  #  exp(0)        - STACK: 10.107...,1
                 - #  Subtract      - STACK: 9.107...
\$\endgroup\$
2
\$\begingroup\$

Fig, \$7\log_{256}(96)\approx\$ 5.762 bytes

Ma9'*+D

Try it online!

Explained

Ma9'*+D
Ma9'    # To each item n in the range [1, 9]
    *+D # Repeat the stringified n, n times
\$\endgroup\$
2
\$\begingroup\$

F# (.NET Core), 59 58 57 bytes (thanks ouflak!)

for i=1 to 9 do String.replicate i (string i)|>printf"%s"

or

for i=1 to 9 do printf"%s"(String.replicate i (string i))

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf! This is a nice submission. As this is a golfing challenge though, white space is among your first enemies, 58 bytes. It does not matter if the program exits with an error or slew of warnings as long as it meets the criteria of the challenge. \$\endgroup\$
    – ouflak
    Commented Feb 1, 2023 at 7:44
2
\$\begingroup\$

Vyxal 3, 3 bytes

9ƛY

Try it Online!

Edit, the three byter is valid

\$\endgroup\$
3
  • \$\begingroup\$ This is great. Would you provide a link to the 'lists of digits' solution, maybe here in the comments? It might actually meet the conditions of the challenge which are pretty broad as far as the output is concerned. \$\endgroup\$
    – ouflak
    Commented Jan 15 at 7:16
  • \$\begingroup\$ it's just 9ƛY \$\endgroup\$
    – pacman256
    Commented Jan 15 at 17:20
  • \$\begingroup\$ Yes! That's definitely within the output rules. \$\endgroup\$
    – ouflak
    Commented Jan 15 at 18:10
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
  • 2
    \$\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\$
    – Wezl
    Commented 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\$
1
\$\begingroup\$

TI-Basic, 17 bytes

seq(I(₁₀^(I)-1)/9,I,1,9

Output is stored in Ans as a list and displayed.

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

Lua, 37 bytes

for i=1,9 do print((""..i):rep(i))end

Try it online!

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

Pure Zsh, 27 bytes

eval ';s+=1;<<<$[s*'{1..9}]

Attempt This Online!

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

GolfScript, 9 bytes

10,{.`*}/

Explanation

     /  # for each element in...
     10,{ # 0-9
     . # duplicate it
     ` # stringify it
     * # push to the stack the stringified version of the number, repeated that many times
    }  # end block
       # implicitly output the stack

Try it online!

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

><>, 28 bytes

1:\   >~1+:a=?;!
n$>:?!v1-$:

Try it online!

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

Pyt, 6 bytes

ɳąĐƖ*ǰ

Try it online!

ɳ           pushes string containing all digits ("0123456789")
 ą          converts to ąrray of characters
  Đ         Đuplicates on stack
   Ɩ        casts top of stack to array of Ɩntegers
    *       string multiplication
     ǰ      ǰoin with no delimiter; implicit print
\$\endgroup\$
1
\$\begingroup\$

Thunno N, \$ 8 \log_{256}(96) \approx \$ 6.58 bytes

9R1+eDJ*

Attempt This Online!

Explanation

9R        # Push range(0, 9)
  1+      # Add one to each
    e     # To each number:
     D    #  Duplicate
      J   #  Cast to string
       *  #  Repeat that many times
          # N flag joins by newlines
          # Implicit output
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 50 bytes

_=>'122333444455555666666777777788888888999999999' // 50
_=>eval("for(s='',i=0;i<11;s+=''.padEnd(++i,i))s") // 50
n=>eval("for(s='';(n=-~n)<11;s+=''.padEnd(n,n))s") // 50
_=>'123456789'.replace(/(\d)/g,(d,i)=>d.repeat(i)) // 50

Try it:

f1=_=>'122333444455555666666777777788888888999999999' // 50
f2=_=>eval("for(s='',i=0;i<10;s+=''.padEnd(++i,i))s") // 50
f3=n=>eval("for(s='';(n=-~n)<11;s+=''.padEnd(n,n))s") // 50
f4=_=>'123456789'.replace(/(\d)/g,(d,i)=>d.repeat(i)) // 50

console.log(f1());
console.log(f2());
console.log(f3());
console.log(f4());

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

Uiua, 15 bytes

∵(⋕/⊂∵°⋕↯).+1⇡9

Pad

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

TypeScript’s type system, 94 bytes

type F<N extends 1[]=[1],L=N["length"]>=L extends 10?[]:[...{[_ in keyof N]:L},...F<[...N,1]>]

Try it at the TS Playground

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

YASEPL, 24 23 bytes

=a$`1=b)""+a;b,a<!+}4,9

explanation (in pseudocode)

=a$`1=b)""+a;b,a<!+}4,9          packed
=a$                              a = 1
   `1            !+}4,9          for(i = 0; i < 9; i++)
     =b)""+a;b,a<                  print(str(a).repeat(a))                 
\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 35 bytes

f=(x=9)=>x?f(x-1)+''.padEnd(x,x):''

Try it online!

\$\endgroup\$

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.