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

114 Answers 114

3
\$\begingroup\$

W 5 4 3 bytes

@π┐

Uncompressed:

$*9N

Repeat 1..9 N times.

Explanation

     M % Map in the range
9      % From 1 to 9
  a$   % Stringify the current counter
 a  *  % Repeat that string by the current counter
\$\endgroup\$
5
  • \$\begingroup\$ Just curious, why do you have the meta link to the command line flags answer? Is that related to your implementation? \$\endgroup\$
    – ouflak
    Mar 17, 2020 at 11:29
  • \$\begingroup\$ @ouflak No,that's was part of the copy-pasted template. \$\endgroup\$
    – user92069
    Mar 17, 2020 at 11:30
  • \$\begingroup\$ @ouflak Why is this accepted? The 05AB1E solution is posted before this answer. You should accept that instead. \$\endgroup\$
    – user92069
    Mar 24, 2020 at 12:10
  • \$\begingroup\$ Both were 3 bytes. I just flipped a coin. I can swap them.... \$\endgroup\$
    – ouflak
    Mar 24, 2020 at 12:41
  • \$\begingroup\$ @ouflak The general consensus is that you shouldn‘t accept an answer anyway. (Appreciate I‘m a few months late, and that you can do as you please, just spreading the consensus view) \$\endgroup\$ Jun 23, 2020 at 23:47
3
\$\begingroup\$

JavaScript (ES8), 33 bytes

f=n=>n>9?'':''.padEnd(n,n)+f(-~n)

Try it online!

Commented

f = n =>            // n = counter, initially undefined
  n > 9 ?           // if n is greater than 9:
    ''              //   stop recursion
  :                 // else:
    ''.padEnd(n, n) //   pad an empty string with n digits n
                    //   this leaves the empty string unchanged for n undefined
    + f(-~n)        //   add the result of a recursive call with n + 1

Building in reverse order (38 bytes)

A somewhat funny alternate method is to build the string from \$n=9\$ to \$n=1\$ and pad the recursive call instead of an empty string.

By doing it this way, the required padding length is:

$$L_n=\left\lfloor\frac{n^2}{2}+1\right\rfloor$$

f=(n=9)=>n?f(n-1).padEnd(n*n/2+1,n):''

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Erlang (escript), 49 bytes

f()->[X*(math:pow(10,X)-1)/9||X<-lists:seq(1,9)].

Try it online!

\$\endgroup\$
3
\$\begingroup\$

C (gcc), 50 bytes

n;f(i){for(i=0;i++<9;)for(n=i;n--;)putchar(48+i);}

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Japt, 4 bytes

AÇîZ

Try it

NaN
\$\endgroup\$
3
\$\begingroup\$

This is my dumbest code golf submission ever, but here it goes

SQLite, 53 bytes

SELECT'122333444455555666666777777788888888999999999'

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Stax, 5 bytes

╜├ìíy

Try it online or try it online unpacked (6 bytes).

Explanation (of the unpacked version):

Vd      # Push constant "0123456789"
  A     # Push 10
   r    # Pop and push a list in the range [0, 10)
    :B  # Repeat the characters in the string the integer amount of times:
        #  "122333444455555666666777777788888888999999999"
        # (after which the top of the stack is output implicitly as result)
\$\endgroup\$
3
\$\begingroup\$

Japt -P, 5 4 bytes

AÇçZ

Test it

\$\endgroup\$
3
\$\begingroup\$

[VBA] 58 bytes

i=1:While i<0:For x=1 to i:Debug.Print i:Next x:i=i+1:wend

Can be ran in Immediate

\$\endgroup\$
3
  • \$\begingroup\$ you appear to have a typo in your code (while i<0->while i<10) \$\endgroup\$ Jun 6, 2020 at 16:20
  • \$\begingroup\$ You can get your code down quite a bit by using nested for loops and by using ? in place of debug.print - For i=1To 9:For j=1To i:?i:Next j,i for 35 bytes \$\endgroup\$ Jun 6, 2020 at 16:22
  • \$\begingroup\$ Oh - or better yet, if we use an approach similar to that of Mitchell Spector's we can get it down to 32 bytes as For i=1to 45:?(3.1*i^.48)\2:Next (or 33 bytes as For i=1to 45:?(3.1*i ^.48)\2:Next for 64-bit installs) \$\endgroup\$ Jun 6, 2020 at 17:11
3
\$\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\$
1
  • \$\begingroup\$ 46 bytes \$\endgroup\$
    – c--
    Sep 11, 2022 at 23:15
3
\$\begingroup\$

COW, 75 bytes

MoOMoOMoOMoOMoOMoOMoOMoOMoOMOOmoOMoOMMMmoOMMMMOOmOoOOMmoOMOomoomOomOoMOomoo

Try it online!

Uncowed

moo ]    mOo <    MOo -    oom o
MOO [    moO >    MoO +    MMM =

+++++++++[>+=>=[<o>-]<<-]
\$\endgroup\$
3
\$\begingroup\$

Brainetry, 451 bytes

This is the golfed version, ungolfed version below.

a b c d
a b c d e f g h
a b c d e f g h
a b c
a b c d
a b
a b c d e
a b
a b c d
a b c d
a b c d
a b c d
a b c d
a b c
a b c d e f g h i
a b
a b c d
a b c d e f g h i
a b c
a b c
a b c d e
a b c d e
a b c
a b c d e
a b c d e f g h
a b
a b
a b c d
a b c d e f g h
a b c
a b c d e f g
a b
a b c d e
a b
a b c d
a b c
a b c d e f g h i
a b
a b c d e f g h
a b c
a b c d
a b
a b c d e
a b c d e f g h i
a b c
a b c
a b c d
a b c
a b c d e
a b c d e f g h i

To try this online, follow this link and paste the code in the btry/replit.btry file, then hit the green "Run" button.

Golfed version of the program below:

Let me explain what
is going on with this brainetry program: this
program will print the digits one to nine
and each of
those is going to
be repeated
as many times as its
own value.
Makes sense, doesn't it?
To achieve such result
we have to play
around with some nice
values in our tape.
That, and we
also have to play smart with our program pointer.
Of course
I would be delighted
to actually explain the algorithm used by this program.
The only problem
is I really
have no idea whatsoever about
what is actually going on.
Let me explain:
brainetry's instructions are a superset
of brainfuck, which means any brainfuck program can
be translated
to brainetry
and it will work.
So this is what I did, I found
a brainfuck program
that completed this task I described and
I just
translated it from brainfuck to
brainetry. Probably
there are simpler approaches
if we take
into consideration the extended operations that brainetry provides ...
However, brainetry
is still in its early stages of development
and I am
still trying to figure
out exactly
what operations to add to
brainetry. Once that set of operations becomes more well-defined
it will be
easier to harness
brainetry's power to write
computer programs. And
once that is finally done,
I will not have to steal random brainfuck programs.

This brainetry answer built on top of this answer

\$\endgroup\$
3
\$\begingroup\$

jq (-nr), 20 19 characters

range(9)+1|"\(.)"*.

Thanks to:

  • 2x-1 for pointing out that range() does not produce array, so operators will see separate numbers.

Sample run:

bash-5.0$ jq -nr 'range(9)+1|"\(.)"*.'
1
22
333
4444
55555
666666
7777777
88888888
999999999

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ range(9)+1 is one byte shorter. \$\endgroup\$
    – user99151
    Jan 2, 2021 at 4:01
  • 2
    \$\begingroup\$ Wow! Thank you, @2x-1. I was never aware that parsing rules lead to that behavior. \$\endgroup\$
    – manatwork
    Jan 2, 2021 at 4:08
3
\$\begingroup\$

Scala, 35 26 bytes

-9 bytes thanks to user!

()=>1 to 9 map(i=>s"$i"*i)

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ This challenges allows you to return a list, so you can do this. Also, you don't need a for loop \$\endgroup\$
    – user
    Jan 3, 2021 at 21:01
3
\$\begingroup\$

Vyxal j, 3 bytes

9ƛẋ

Try it Online!

-1 thanks to lyxal

\$\endgroup\$
2
  • \$\begingroup\$ 3 bytes \$\endgroup\$
    – lyxal
    Jun 12, 2021 at 12:29
  • \$\begingroup\$ @lyxal I frogot it worked like that :p \$\endgroup\$
    – emanresu A
    Jun 12, 2021 at 12:29
3
+50
\$\begingroup\$

Add++ -i, 14 13 bytes

L,9Rdz£XbUBvn

Try it online!

This is making me cry. A fun feature of like 99% of stack commands is that it applies to the whole stack rather than the top of the stack. Very very helpful.

-1 thanks to caird which kinda makes up for the suffering of this

Explained

L,9Rdz£XbUBvn
L,              # Start a lambda which is called implicitly by the -i flag
  9R            # Push the range [1...9]
    dz          # and zip it with itself, giving [[1, 1], [2, 2] ... [9, 9]]
      £X        # repeat x[0] by x[1] times for each x in that
        bU      # dump the contents of that onto the stack. This is a very important part because as I said, 99% of lambda stack commands map over to the whole stack, even when using quicks and stuff.
          Bv    # join each item (on the stack...) into a single integer
            n   # and join (the stack...) on newlines
\$\endgroup\$
1
3
\$\begingroup\$

Malbolge, 175 bytes

(C%;_#"~[}43WVxwuRt+*NMLmlljGig}CBAc?=vNtLr[v64m321/RzP+Ncha&&Gc#EDBX|{zx=vv:bs6p^]nllk/iVgfdvD'`N#?\\6YY3WUwvvQtPOqLo,JIHGihfCddcx>=<;:9[Y6XVl210/.-O+MLJ`&HG\[!~}|{z>=wv998rp

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Regenerate -a, 15 bytes

([1-9])$1{$1-1}

Outputs 1 through 999999999 on separate lines. Attempt This Online!

Explanation

The -a flag outputs all possible matches on separate lines.

([1-9])$1{$1-1}
 [1-9]           Pick a digit 1 thru 9
(     )          Store it in group 1
       $1        Match group 1 again
         {    }  this many times:
          $1       Group 1 contents
            -1     minus 1

Alternate -a solution, also 15 bytes:

([1-9])(){1,$1}

Outputs digits on separate lines. Attempt This Online!

([1-9])(){1,$1}
 [1-9]           Pick a digit 1 thru 9
(     )          Store it in group 1
       ()        Match empty string
         {    }  this many times:
          1,       Minimum of once
            $1     Maximum of (group 1 contents) times
\$\endgroup\$
3
\$\begingroup\$

Nibbles, 4 bytes (8 nibbles)

,9^$`p
,9^$`p
        # implicitly map over
,9      # integers from 1 to 9      
  ^     # replicating
   `p   # the character of each 
        # by itself times

enter image description here

\$\endgroup\$
3
\$\begingroup\$

Julia, 24/21 bytes

w/o

(a=1:9).*(10 .^a.-1).÷9

and w/ macro:

a=1:9;@.a*(10^a-1)÷9
  • array of numbers, nothing new
\$\endgroup\$
4
  • 1
    \$\begingroup\$ shouldn't the answer also include a print statement? \$\endgroup\$
    – amelies
    Sep 9, 2022 at 15:05
  • \$\begingroup\$ maybe :-) when i got the the numbers as in the decription, i took it solved... \$\endgroup\$ Sep 9, 2022 at 20:25
  • \$\begingroup\$ actually evaluating it in the REPL or running w/ julia -E you get what you want. (i focused to get numbers not strings as You) \$\endgroup\$ Sep 9, 2022 at 20:31
  • 1
    \$\begingroup\$ Using the repl is considered as a separate language codegolf.meta.stackexchange.com/a/7844/98541 and the same applies when using a flag codegolf.meta.stackexchange.com/a/14339/98541 \$\endgroup\$
    – MarcMush
    Sep 13, 2022 at 21:10
3
\$\begingroup\$

Deadfish~, 61 54 bytes

ioiooioooiooooioooooiooooooioooooooiooooooooiooooooooo

Try it online!

-7 bytes thanks to Bubbler.

Separating by zeros:

Deadfish~, 128 bytes

{iiiii}dcdciiccddciiicccdddciiiiccccddddciiiiicccccdddddciiiiiiccccccddddddc{i}dddccccccc{d}iiic{i}ddcccccccc{d}iic{i}dccccccccc

Try it online!

By spaces:

Deadfish~, 159 bytes

{iiiii}dc{dd}iiic{ii}ddcc{dd}iic{ii}dccc{dd}ic{ii}cccc{dd}c{ii}iccccc{dd}dc{ii}iicccccc{dd}ddc{ii}iiiccccccc{dd}dddc{ii}iiiicccccccc{dd}ddddc{ii}iiiiiccccccccc

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 60 using shorter sequence to get to 49, and incidentally it also works in plain Deadfish. Also there's 54 using o. \$\endgroup\$
    – Bubbler
    Sep 13, 2022 at 2:20
3
\$\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
\$\endgroup\$
3
\$\begingroup\$

Knight (v2.0-alpha), 21 bytes

;=i@W>10=i+1iO*+""i i

Try it online!

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

Keg, 45 11 9 8 bytes

9Ï^⑷:⅍*⑸

Try it online!

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

Io, 38 bytes

Range 1 to(9)map(i,i*(10**i-1)/9)print

Try it online!

Io, 47 bytes

Range 1 to(9)map(i,i asString repeated(i))print

Try it online!

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

Python 3.8, 34 bytes

i=0
while i<9:print(str(i:=i+1)*i)

Try it online!

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

Bubblegum, 23 bytes

00000000: 3334 3232 3636 3601 0253 1030 0303 7308  3422666..S.0..s.
00000010: b080 024b 1800 00                        ...K...

Try it online!

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

Python 2, 32 bytes

print[i*`i`for i in range(1,10)]

Try it online!

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

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

naz, 36 bytes

1a1o1a2o1a3o1a4o1a5o1a6o1a7o1a8o1a9o

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

\$\endgroup\$

Your Answer

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

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