# Beginners 10x10 multiplication matrix [duplicate]

I was looking for a very easy task to look how short of a code can be produced on a beginners exercise.

The goal is to produce a simple table that looks like this common java/c# code is about 4 lines. So get your golfing-languages ready ;) Try to align the matrix in any way it is readable.

1 2 3    .. 10

2 4 6    .. 20

3 6 9    .. 30

. . .    .. .

10 20 30 .. 100


EDIT: The first answer below shows a propper alignment and solution

## marked as duplicate by user202729, Sriotchilism O'Zaic code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); May 28 '18 at 12:33

• Looks like a simplified version of Print this Multiplication Table and Addition/Multiplication table generator. Not much challenging. Though occasionally the extremely simple questions' popularity is much higher. Unless closed. So I suggest to specify whether input will be provided, output must be text or formatted array is fine and whether the numbers need some kind of alignment. – manatwork May 28 '18 at 8:23
• Nice first challenge, but you would be wise to specify more clearly what exactly is required. E.g. may we return a list of ten lists? Don't use the word "Try"; either require it or say it isn't required. Etc. – Adám May 28 '18 at 8:28
• If you do require alignment, which alignments are acceptable (left, right, all columns same width, single/multiple space separating columns, additional white space left and/or right, etc.)? – Adám May 28 '18 at 8:29
• Please give one or more complete correct outputs. One might think that the output actually needs all the dots. – Adám May 28 '18 at 8:30
• I don't think anybody has mentioned this yet, but welcome to PPCG! – Giuseppe May 28 '18 at 11:31

# MATL, 5 bytes

10:&*


Try it online!

10:    % Range: [1,2,3,4,5,6,7,8,9,10]
&*  % Multiply the range by itself transposed, with broadcasting.


Outputs:

 1   2   3   4   5   6   7   8   9  10
2   4   6   8  10  12  14  16  18  20
3   6   9  12  15  18  21  24  27  30
4   8  12  16  20  24  28  32  36  40
5  10  15  20  25  30  35  40  45  50
6  12  18  24  30  36  42  48  54  60
7  14  21  28  35  42  49  56  63  70
8  16  24  32  40  48  56  64  72  80
9  18  27  36  45  54  63  72  81  90
10  20  30  40  50  60  70  80  90 100


# Ruby, 48 45 44 bytes

1.upto(10){|x|puts"%4d"*10%[*x.step(100,x)]}


Try it online!

-3 bytes thanks to manatwork then -1 thanks to Kirill L.

But I still think there must be a better way.

• You not need the parenthesis around the "%4d"*10. And instead of x*10 you can write just 100 then the placeholders in the format string will limit it to 10. – manatwork May 28 '18 at 10:40
• Now, when there are no parentheses, you don't need the space after puts either. As for a better way, it looks not so easy, e.g. an alternative approach gives still the same 44 bytes – Kirill L. May 28 '18 at 13:11

# Jelly, 5 bytes

⁵×þG


Try it online!

Prints the following text:

  1   2   3   4   5   6   7   8   9  10
2   4   6   8  10  12  14  16  18  20
3   6   9  12  15  18  21  24  27  30
4   8  12  16  20  24  28  32  36  40
5  10  15  20  25  30  35  40  45  50
6  12  18  24  30  36  42  48  54  60
7  14  21  28  35  42  49  56  63  70
8  16  24  32  40  48  56  64  72  80
9  18  27  36  45  54  63  72  81  90
10  20  30  40  50  60  70  80  90 100

• I'm so fascinated by those languages like Jelly, Brainfuck etc.... But I think I will never understand how to write code with these. Is there any 'tutorial' you can recommend? – Comann Silvan May 28 '18 at 8:39
• For Jelly, I can recommend its dedicated wiki. However, I suggest not accepting an answer this early, and in fact not accepting an answer at all because that doesn't encourage competition. – Mr. Xcoder May 28 '18 at 8:41

# Octave, 18 17 bytes

1 byte saved thanks to @StewieGriffin

disp((x=1:10)'*x)


Try it online!

Or, as @maxb points out: more readable, same length:

x=1:10;disp(x'*x)

• You could simply do x=1:10;disp(x'*x). Same amount of bytes, and more readable. – maxb May 28 '18 at 10:56
• @maxb Good idea; updated – Luis Mendo May 28 '18 at 10:59
• ... and more readable. That's almost a reason to not update the answer! – Stewie Griffin May 28 '18 at 21:47

# R, 32 bytes

write(format((x=1:10)%o%x),1,10)


Try it online!

• write(format(1:10%o%1:10),1,10) is shorter by one byte. – JayCe May 28 '18 at 15:45

# Python 2, 64 55 bytes

i=1
exec"print'%4d'*10%tuple(range(i,11*i,i));i+=1;"*10


Try it online!

# APL+WIN, 9 bytes

n∘.×n←⍳10


Try it online! Courtesy of Dyalog Classic

Outer product multiplication of a vector of integers 1 to 10

• on Dyalog you can get 7 bytes – dzaima May 28 '18 at 9:53
• @dzaima Unfortunately I am running an ancient version of APL+WIN which does not have the ⍨ operator ;( – Graham May 28 '18 at 10:15

# Brainfuck, 1147 bytes

++[[<+++>-->----<]>]<<<<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.<<+.>>++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.>.<---.+++++.>.<-----.+++++++.>.<------.--.<<.>>+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.<<.>>++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.<<.>>+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.<<.>>++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.<<.>>+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.<<.>>++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.<<.>>+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.<<.>>+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..


Try it online!

Thanks for Jo King for this solution !

+++++[>+++++[>++>+<<-]>>+>++<<<<-]>>-->++<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.>>.<<++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.<.>---.+++++.<.>-----.+++++++.<.>------.--.>>.<<+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.>>.<<++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.>>.<<+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.>>.<<++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.>>.<<+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.>>.<<++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.>>.<<+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.>>.<<+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..


Try it online!

Oh god, this ended up way longer than I expected.

Here is how i did it :

Store values 48 ('0'), 32 (space) and 10 (new line)
+++++[>+++++[>++>+<<-]>>+>++<<<<-]>>-->++<
Print 1st line
+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<+.>..<--------.-.>>.<<
Print 2nd line
++.>..<++.>..<++.>..<++.>..<-------.-.>.<+.+.>.<-.+++.<.>---.+++++.<.>-----.+++++++.<.>------.--.>>.<<
Etc.
+++.>..<+++.>..<+++.>..<--------.+.>.<-.++++.>.<----.+++++++.>.<------.-.>.<+.++.>.<--.+++++.>.<----.---.>>.<< Etc.
++++.>..<++++.>..<-------.+.>.<-.+++++.>.<----.--.>.<++.++.>.<--.++++++.>.<-----.-.>.<+.+++.>.<--.----.>>.<<
+++++.>..<----.-.>.<+.++++.>.<---.--.>.<++.+++.>.<--.---.>.<+++.++.>.<-.----.>.<++++.+.>.<.-----.>>.<<
++++++.>..<-----.+.>.<-.+++++++.>.<------.++.>.<-.---.>.<+++.+++.>.<--.--.>.<++.++++.>.<---.-.>.<++.------.>>.<<
+++++++.>..<------.+++.>.<--.-.>.<+.++++++.>.<-----.++.>.<-.--.>.<++.+++++.>.<----.+.>.<.---.>.<++++.-------.>>.<<
++++++++.>..<-------.+++++.>.<----.++.>.<-.-.>.<++.----.>.<++++.++++.>.<---.+.>.<.--.>.<+++.-----.>.<++++++.--------.>>.<<
+++++++++.>..<--------.+++++++.>.<------.+++++.>.<----.+++.>.<--.+.>.<.-.>.<++.---.>.<++++.-----.>.<++++++.-------.>.<++++++++.---------.>>.<<
+.-.>.<++.--.>.<+++.---.>.<++++.----.>.<+++++.-----.>.<++++++.------.>.<+++++++.-------.>.<++++++++.--------.>.<+++++++++.---------.>.<+.-..

• 1147 bytes. You were printing null bytes on the second line – Jo King May 28 '18 at 9:12
• There's got to be an algorithmic way of printing the numbers instead of kolmogorov'ing it – Jo King May 28 '18 at 9:13

## Batch, 177 bytes

@echo off
for /l %%i in (1,1,10)do call:r %%i
exit/b
:r
set s=
for /l %%j in (1,1,10)do set/an=%1*%%j&call:c
echo %s%
:c
set n= %n%
if "%n:~3%"=="" goto c
set s=%s%%n%


# J, 9 bytes

*/~1+i.10


Try it online!

# Red, 56 bytes

repeat n 10[repeat m 10[prin pad rejoin[n * m]4]print""]


Try it online!

# CJam, 24 23 bytes

A,:)_m*{:*"%4d"e%}%A/:n


Try it online!

Alternative without pretty printing:

A,:)_m*{:*}%A/:p


# JavaScript (Node.js), 79 bytes

(_=[...".........."])=>_.map((a,i)=>Array.from({length:10},(v,k)=>(k+1)*(i+1)))
`

Try it online!