29
\$\begingroup\$

Numbers by Position

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

83 Answers 83

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

J, 18 bytes

echo u:(#48+])i.10

Try it online!

K (oK), 11 10 bytes

-1 byte thanks to ngn!

,/${x}#!10

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ ,/${x}#!10 - using filter ({ }#) for replication \$\endgroup\$ – ngn Mar 25 '20 at 19:23
  • \$\begingroup\$ @ngn Thanks, of course! \$\endgroup\$ – Galen Ivanov Mar 25 '20 at 19:28
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\$ – Taylor Scott Jun 6 '20 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\$ – Taylor Scott Jun 6 '20 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\$ – Taylor Scott Jun 6 '20 at 17:11
3
\$\begingroup\$

C (gcc), 46 bytes

s;main(n){n>9||main(puts(memset(&s,n+48,n)));}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ can't be called twice \$\endgroup\$ – l4m2 Apr 22 '20 at 16:13
  • \$\begingroup\$ Thanks for catching that :) \$\endgroup\$ – dingledooper Apr 22 '20 at 16:18
3
\$\begingroup\$

COW, 75 bytes

MoOMoOMoOMoOMoOMoOMoOMoOMoOMOOmoOMoOMMMmoOMMMMOOmOoOOMmoOMOomoomOomOoMOomoo

Try it online!

Uncowed

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

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

x86-16 machine code, IBM PC DOS, 18 16 bytes

Binary:

00000000: b839 0ab2 09b1 2dcd 1048 2aca 4a75 f8c3  .9....-..H*.Ju..

Listing:

B8 0A39     MOV  AX, 0A39H              ; AH = 0AH, AL = '9'
B2 0A       MOV  DL, 10                 ; DL as counter value
B1 2D       MOV  CL, 1+2+3+4+5+6+7+8+9  ; start digit repeat 45 times
        NLOOP:
CD 10       INT  10H                    ; call BIOS - write digit * CX times
48          DEC  AX                     ; decrement ASCII digit
4A          DEC  DX                     ; decrement counter value
2A CA       SUB  CL, DL                 ; reduce digit repeat value by counter
75 F8       JNZ  NLOOP                  ; loop until 0 
C3          RET                         ; return to DOS

Try it online!

Explanation:

This uses the PC BIOS API's INT 10H / 0AH function to write the ASCII char in AL to the screen CX number of times. However, this function does not update the cursor position to the end of the output -- it just stays where it started. In other words, the next call simply overstrikes existing characters writing over them. Making a BIOS call to advance the cursor is expensive byte-wise.

Since going forward isn't going to work, we go backwards starting from '9'. It writes '9' 45 times, then '8' 36 times, '7' 28 times, etc -- each time starting from the first column overwriting like so:

999999999999999999999999999999999999999999999
888888888888888888888888888888888888999999999
777777777777777777777777777788888888999999999
666666666666666666666777777788888888999999999
555555555555555666666777777788888888999999999
444444444455555666666777777788888888999999999
333333444455555666666777777788888888999999999
222333444455555666666777777788888888999999999
122333444455555666666777777788888888999999999

Output:

enter image description here

\$\endgroup\$
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 at 21:01
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\$

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\$
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\$
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 Apr 19 '20 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 Mar 17 '20 at 11:19
  • 1
    \$\begingroup\$ Nope, removed thanks. I'm so used to using the -F option, I did it without thinking. \$\endgroup\$ – Guillermo Phillips Mar 17 '20 at 11:21
  • \$\begingroup\$ 35 bytes \$\endgroup\$ – Night2 Mar 18 '20 at 9:26
  • \$\begingroup\$ Interesting lesson in precedence rules. \$\endgroup\$ – Guillermo Phillips Mar 18 '20 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 Apr 22 '20 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 Mar 19 '20 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\$
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\$

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.