| Bytes | Lang | Time | Link |
|---|---|---|---|
| 027 | ☾ | 250414T175314Z | noodle p |
| 077 | Tcl | 170616T011111Z | sergiol |
| 070 | Kotlin | 160726T154124Z | Aaron |
| 060 | Zsh | 250405T030909Z | roblogic |
| 080 | JavaScript Node.js | 250404T162911Z | Fhuvi |
| 058 | AWK | 250304T170236Z | xrs |
| 077 | Swift 6 | 250301T213009Z | macOSist |
| 018 | Vyxal 3 | 250225T181907Z | pacman25 |
| 368 | jBasher2 | 250225T154500Z | madeforl |
| 035 | Uiua | 240620T005034Z | noodle p |
| nan | Pxem | 240623T132634Z | 鳴神裁四点一号 |
| 080 | R | 240619T142701Z | Glory2Uk |
| 020 | Vyxal | 210510T105445Z | SegFault |
| 008 | Stax | 210510T115022Z | Razetime |
| 025 | Pyth | 180215T133226Z | robbie |
| 060 | ConTeXt | 210322T214835Z | J. А. de |
| 082 | Excel VBA | 180131T033658Z | Taylor R |
| nan | Pascal FPC | 160727T125815Z | hdrz |
| 057 | Excel | 170722T210048Z | Taylor R |
| 052 | PowerShell | 200221T055201Z | mazzy |
| 045 | Burlesque | 200221T152907Z | DeathInc |
| 020 | 05AB1E | 200221T100639Z | Kevin Cr |
| 070 | JavaScript | 170806T220652Z | Tomas La |
| 023 | Japt | 180130T151511Z | Shaggy |
| 101 | Yabasic | 180131T192416Z | Taylor R |
| 068 | Python 3.6 | 170709T210527Z | Gareth |
| 105 | MYBASIC | 180131T193252Z | Taylor R |
| 087 | uBASIC | 180131T033759Z | Taylor R |
| 051 | Perl 5 | 170925T025449Z | Xcali |
| 082 | Haskell | 170923T230900Z | ბიმო |
| 262 | /// | 170710T042307Z | Conor O& |
| 098 | Tcl | 130415T201039Z | Johannes |
| 073 | PHP | 170616T144343Z | Jör |
| 094 | Racket | 161012T031739Z | rnso |
| nan | Fourier | 160919T221854Z | Oliver N |
| 016 | Pyke | 160726T115810Z | Blue |
| 063 | Julia 236 Bytes | 160920T161325Z | Magic Oc |
| 095 | C | 160920T153238Z | user5898 |
| 079 | C | 160920T144308Z | user5898 |
| 091 | Excel | 160723T214717Z | GuitarPi |
| 098 | C++ | 160723T193647Z | FoxyZ |
| 049 | golflua | 160727T125940Z | manatwor |
| 060 | Groovy | 160726T160945Z | manatwor |
| 190 | Javascript | 160726T221420Z | steenber |
| 075 | D | 130415T185718Z | ratchet |
| 091 | Python 2 | 160723T213154Z | eaydin |
| 076 | x86_64 machine code linux | 160726T070253Z | davey |
| 074 | Javascript using external library | 160726T153412Z | applejac |
| 090 | JAVA | 160726T095831Z | user9023 |
| 268 | /// | 160726T135640Z | Erik the |
| 050 | ><> | 160726T132500Z | Aaron |
| 142 | c# | 160726T113323Z | supermee |
| 027 | Convex | 160723T235414Z | GamrCorp |
| 202 | LOLCODE | 160723T212842Z | AAM111 |
| 064 | Maple | 160723T210940Z | DSkoog |
| 118 | VBA | 160723T180444Z | Joffan |
| 084 | C | 160723T084730Z | user5634 |
| 063 | k | 160723T110829Z | skeevey |
| 665 | Javascript | 150705T191049Z | Afonso M |
| 045 | Mathematica | 130513T112421Z | Mr.Wizar |
| 072 | Python 2 | 130512T225238Z | flornqua |
| 126 | C++ | 130512T220855Z | Cisplati |
| 077 | Ruby | 130419T153314Z | manatwor |
| 099 | Erlang escript | 130421T213845Z | Hynek -P |
| 028 | APL Dyalog | 130421T121322Z | TwiN |
| 054 | Perl | 130420T080804Z | user7486 |
| 075 | Python | 130419T150036Z | Daniel |
| nan | 130419T123202Z | Automate | |
| 059 | Ruby | 130415T111316Z | manatwor |
Tcl, 77 bytes
time {time {lappend L [incr j]x$i=[expr $j*$i]} [incr i]
puts $L
unset L j} 9
Kotlin, 73 70 bytes
for(i in 1..10){(1..i).forEach{x->print("${x}×$i=${x*i} ")};println()}
3 bytes saved thanks to lukas.j.
Kotlin is the latest JVM language and I mainly wanted to try my hand at it.
You can try it on their online interpreter.
Zsh, 69 60 bytes
for i ({1..9})echo&&for j ({1..$i})printf %-7s $i×$j=$[i*j]
-9 bytes and a correction thanks to @Fhuvi
JavaScript (Node.js), 80 bytes
Classic solution using recursion, with trailing spaces on each line.
f=(x=1,y=1)=>x+`x${y}=${x*y} `+(x*y>9?"":" ")+(x-y?f(x+1,y):y>8?"":`
`+f(1,y+1))
If not respecting column alignment: 65 bytes
f=(x=1,y=1)=>x+`x${y}=${x*y} `+(x-y?f(x+1,y):y>8?"":`
`+f(1,y+1))
Swift 6, 77 bytes
for l in 1...9{(1...l).map{print(terminator:"\(l)x\($0)=\(l*$0) ")}
print()}
Vyxal 3, 18 bytes
9ƛ∥YɾZƛΠJᏜ×=I“6»]'
Vyxal 3 really wants the vectorized pair here that v1 uses, and also RIP flags again smh
9ƛ∥YɾZƛΠJᏜ×=I“6»]'
9ƛ # map over 1-9
∥ Z # Zip after applying in parallel
Y # n repeated n times in a list, implicitly
ɾ # range (1,n+1)
ƛ ] # for each pair...
ΠJ # append the product to the list
Ꮬ×=I“ # interleave with ×= and join on empty string
6» # append spaces to make it length 6
' # join on spaces and then newlines
💎
Created with the help of Luminespire.
jBasher2, 368 bytes
create i with type number
create j with type number
create m with type number
set 1 to i
while i < 10
set 1 to j
while j <= i
output inline j
output inline "×
output inline i
output inline "=
multiply i by j
set that to m
output inline m
if m < 10
output inline " "
endif
output inline " "
add 1 by j
set that to j
endwhile
output ""
add 1 by i
set that to i
endwhile
this language is the worst for golfing
Pxem, 0 + 74 = 74 bytes
Filename (every \1 needs to be replaced by 0x01)
ab\1.z.tBA\1.y.m.nx.o.c.n=.o.c.m.!.c.n
.y .oXX.a .o\1.+.c.m\1.+.a
.o.m\1.+.c
.a
How it works
ab\1.z Push 1 (as outer loop index I). Loop while pop != pop:
.t Pop I to register
BA\1.y Push 1 (as inner loop index J). Loop while pop > pop:
.m.n Push register (I). Print it.
x.o Print letter x.
.c.n Print J
=.o Print equal sign.
.c.m.!.c.n Multiply I and J to duplicate. Print (which is popped once)
\n.y If 10 > pop:
.o Print space
XX.a
.o Print space
\1.+ Increment J
.c.m\1.+ Dup J, Push I, add 1 (to do J < I + 1)
.a End loop.
\n.o Print newline.
.m\1.+ Push I, add 1
.c\n Duplicate, push 10 (to do 10 > I)
.a End loop.
R, 89 80 bytes
- -6 bytes golfed by pajonk and further -3 bytes by following the pajonk's hint
o=outer(x<-1:9,x,\(a,b)paste0(a,"×",b,"=",a*b))
o[lower.tri(o)]=""
write(o,1,9)
Try it online! (smartphone-friendly output)
Despite R having almost a built-in multiplication table (the matrix of the products is as simple as 1:9%o%1:9), and dedicated functions to select the upper/lower triangular matrix, pasting and formatting takes a great deal of space...
Vyxal, 359 20 bytes, -j flag
9ƛɾMƛ\×j\=+nΠ+9↲7Ẏ;∑
Finally, I'm done, and to round up LoTM, more forward-slashes. (Edit 1: the \s are gone)
Stax, 18 bytes, (17 chars, UTF-8)
9mc{b"`n×` =`*"mJ
can't be compressed due to the unicode requirement. a 16 may be possible if I can find a way to compress it. 14 if using x is allowed.
Excel VBA, 82 Bytes
Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window.
For y=1To 9:For x=1To 9:?IIf(x>y,"",Left(x &"x"&y &"=" &x*y &" ",7));:Next:?:Next
Pascal (FPC), 128 125 138 bytes
One recursive procedure takes care of everything. Call with m(9,9).
procedure m(i,j:int8);begin if i<1then Exit;if i=j then begin m(i-1,j-1);writeln;end;m(i-1,j);write(i,'x',j,'=',i*j,' ':2-i*j div 10);end;
Ungolfed:
procedure m(i, j: int8);
begin
if i<1 then
Exit;
if i=j then
begin
m(i-1, j-1);
writeln;
end;
m(i-1, j);
write(i,'x',j,'=',i*j,' ':2-i*j div 10);
end;
The reason for the byte count going up: the output was not aligned correctly. It is fixed now.
Excel, 57 bytes
Requires Excel 365 / 2019 version 2007 or newer
An excel worksheet function that defines the contextual arrays c and r then outputs an 9x9 array containg the output.
=Let(c,Column(A:I),r,Row(1:9),If(c>r,"",r&"x"&c&"="&r*c))
Excel VBA Version, 64 Bytes
Anonymous VBE Immediate window function that takes no input and outputs to range [A1:I9] on the ActiveSheet object
[1:9]="=Let(c,Column(),r,Row(),If(c>r,"""",r&""x""&c&""=""&r*c))
Output
Burlesque, 45 bytes
9roJcp:SOm{Jpdjimup"x="**j_+}{-]j-]==}gb)wduN
I'm almost positive there're multiple cuts that can be made here, but I just can't get them...
9ro # Range [1,9]
J # Duplicate
cp # Cartesian product
:SO # Filter for sorted-reversed
m{ # Map
J # Duplicate
pd # Product
jimup # Convert the two numbers into a string ({1 1} => "11")
"x="** # Riffle in x= ("11""x=" => "1x1=")
j_+ # Append the result
}
{
-]j-] # Heads of both
== # Are equal
}gb # Group by first digit being the same
)wd # Separate each internal list by spaces
uN # Separate main list by newline and prettify
05AB1E, 22 20 bytes
9LεLyâε'×ý'=yPðJ6∍]»
-2 bytes thanks to @Grimmy.
Explanation:
9L # Push a list in the range [1,9]
ε # Map over each value `y`:
L # Push a list in the range [1,y]
yâ # Pair each value in this list with `y`
# i.e. [1,2,3] and 3 → [[1,3],[2,3],[3,3]]
ε # Map over each pair:
'×ý '# Join the pair with "×" delimiter
'= '# Push a "="
yP # Push the pair again, and pop and push it's product
ð # Push a space " "
J # Join all three values on the stack together
6∍ # And then shorten the string to size 6
] # Close both the maps
» # Join each inner list by spaces, and then each string by newlines
# (after which the result is output implicitly)
JavaScript, 70 characters
for(s=i='';i++<9;s+='\n')for(j=0;j++<i;s+=j+'×'+i+'='+j*i+' ');alert(s)
Respecting alignment, 83 characters:
for(s=i='';i++<9;s+='\n')for(j=0;j++<i;s+=j+'×'+i+'='+j*i+(j*i>9?' ':' '));alert(s)
Japt, 23 bytes
9õÈõ_[X'×Z'=X*Z]¬ú6ø÷
Explanation
9õ :Range [1,9]
È Ã :Pass each integer X through a function
õ : Range [1,X]
_ Ã : Pass each integer Z through a function
[X'×Z'=X*Z] : Array [X,"×",Z,"=",X*Z]
¬ : Join to a string
ú6 : Pad end with spaces to length 6
¸ : Join with spaces
· :Join with newlines
Yabasic, 101 bytes
Anonymous function that takes no input and prints a multiplication table to the console.
For y=1To 9
For x=1To 9
If(x<=y)Then
?Left$(Str$(x)+"x"+Str$(y)+"="+Str$(x*y)+" ",7);
Fi
Next
?
Next
-3 bytes for the use of Fi over EndIf
Python 3.6, 70 68 bytes
r=range(1,10)
for b in r:print(*[f"{a}x{b}={a*b:<2}"for a in r[:b]])
MY-BASIC, 105 bytes
Anonymous function that takes no input and prints a multiplication table to the console.
Str(...) conversions are costly in this solution.
For Y=1 To 9
For X=1 To 9
If x<=y Then Print Left(Str(x)+"x"+Str(y)+"="+Str(x*y)+" ",7)
Next
Print;
Next
uBASIC, 87 bytes
Anonymous function that takes no input and outputs to the console.
0ForY=1To9:ForX=1To9:z=x*y:Ifx<=yThen?x;"x";y;"=";z;" ";:Ifz<10Then?" ";
2NextX:?:NextY
Haskell, 84 82 bytes
putStr$init$unlines[unwords[s i++'×':s j++'=':s(i*j)|i<-[1..j]]|j<-[1..9]]
s=show
-2 thanks to @Laikoni!
///, 262 bytes
/;/=4//:/x\/\///-/ 6:,/=2//'/ 5:&/=1//%/ 4:#/ 3:"/
1:!/ 2x/1x1&"2,!2;"3=3!3=6 #3=9"4;!4=8 #4&2%4&6"5=5!5&0#5&5%5,0'5,5"6=6!6&2#6&8%6,4'6=30-6=36"7=7!7&4#7,1%7,8'7=35-7;2 7x7;9"8=8!8&6#8,4%8=32'8;0-8;8 7x8=56 8x8=64"9=9!9&8#9,7%9=36'9;5-9=54 7x9=63 8x9=72 9x9=81
Tcl 98 chars
while {[incr a]<10} {set b 0;while {[incr b]<=$a} {puts -nonewline "$a×$b=[expr $a*$b] "};puts ""}
PHP, 73 bytes
for(;$m++<9;print"
")for($n=0;$n++<$m;)printf("%d×%d=%-3d",$n,$m,$n*$m);
Racket 94 bytes
(for((n(range 1 10)))(for((i(range 1(add1 n))))(printf "~ax~a=~a "i n(* i n)))(displayln""))
Ungolfed:
(define (f)
(for ((n (range 1 10)))
(for ((i (range 1 (add1 n))))
(printf "~ax~a=~a " i n (* i n)))
(displayln ""))
)
Testing:
(f)
Output:
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
Fourier, 756 632 bytes
Thanks @BetaDecay for 124 bytes!
1o120~Ea1o61a1o10~Na1oEa2o61a2o32~Saa2oEa2o61a4oNa1oEa3o61a3oSaa2oEa3o61a6oSaa3oEa3o61a9o^a1oEa4o61a4oSaa2oEa4o61a8oSaa3oEa4o61a12oSa4oEa4o61a16oNa1oEa5o61a5oSaa2oEa5o61aNoSa3oEa5o61a15oSa4oEa5o61a20oSa5oEa5o61a25oNa1oEa6o61a6oSaa2oEa6o61a12oSa3oEa6o61a18oSa4oEa6o61a24oSa5oEa6o61a30oSa6oEa6o61a36oNa1oEa7o61a7oSaa2oEa7o61a14oSa3oEa7o61a21oSa4oEa7o61a28oSa5oEa7o61a35oSa6oEa7o61a42oSa7oEa7o61a49oNa1oEa8o61a8oSaa2oEa8o61a16oSa3oEa8o61a24oSa4oEa8o61aSoa5oEa8o61a40oSa6oEa8o61a48oSa7oEa8o61a56oSa8oEa8o61a64oNa1oEa9o61a9oSaa2oEa9o61a18oSa3oEa9o61a27oSa4oEa9o61a36oSa5oEa9o61a45oSa6oEa9o61a54oSa7oEa9o61a63oSa8oEa9o61a72oSa9oEa9o61a81o
Pyke, 17 16 bytes (noncompeting)
Pyke was created after this question was asked
TFjSF\xj\=ij*s(P
TFj ( - for j in range(10):
SF ( - for i in range(1,j+1):
\xj\=ij*s - sum(i,"x",j,"=",i*j)
P - pretty_print(^)
Julia (236 Bytes, potentially 63) - Could use help.
A=[1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9;1 2 3 4 5 6 7 8 9]
map(x->x>0?print(x,"x",x,"=",x*x,"\t"):println(),triu!(A'))
Someone put in the comments "Who's going to do anything but use 2 loops?"
This guy is!
I don't know how to instantiate matrices easily in Julia, anyone who could help me do the instantiation of the matrix better I will be grateful. I can only get it to make a 2D array, and triu doesn't work on that.
How it works:
A = [...]creates a 9x9 matrix with 1-9 in each vector (someone please teach me to do this right without accidentally creating a 2D array... I want to learn this language better, but I'm confused on the typing differences and a lot of the documentation is pretty terse for matrices.triu!(A')takes the inverse of the upper triangle of the matrix.map(x->x?0...:...,A)mapping function that differentiates on x=0, printing a newline when needed.
Output:
1×1=1
1×2=2 2×2=4
1×3=3 2×3=6 3×3=9
1×4=4 2×4=8 3×4=12 4×4=16
1×5=5 2×5=10 3×5=15 4×5=20 5×5=25
1×6=6 2×6=12 3×6=18 4×6=24 5×6=30 6×6=36
1×7=7 2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49
1×8=8 2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64
1×9=9 2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81
C 95 bytes
i=1,j=1;f(){printf("%dx%d=%d %c",j,i,i*j,i!=2||j>4?:32);++i>j?++j,i=1,j<=9?puts(""),f():0:f();}
they want this table:
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
C 79 bytes
i=1,j=1;f(){printf("%dx%d=%d ",j,i,i*j);++i>j?++j,i=1,j<=9?puts(""),f():0:f();}
the main
main(){f();}
the table
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
Excel, 92 91 Bytes
From the VBA editor's immediate window, run the following command:
Range("A1:I9").Formula="=IF(ROW()<COLUMN(),"""",COLUMN()&""×""&ROW()&""=""&COLUMN()*ROW())"
The output is directly on the active worksheet.

I golfed an extra byte by swapping the order of an if to change >= to <. I didn't update the screenshot, but it only affects the formula at the top, not the output.
C++, 106 98 bytes
I used two loops and a few tricks.
#import <cstdio>
main(){for(int i,j;i++-9;j=0)while(j++-i)printf("%dx%d=%d%c",j,i,i*j,j<i?32:10);}
golflua, 54 49 characters
~@i=1,9~@j=1,i I.w(S.q(i.."x%d=%-3d",j,i*j))$w()$
Sample run:
bash-4.3$ golflua -e '~@i=1,9~@j=1,i I.w(S.q(i.."x%d=%-3d",j,i*j))$w()$'
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
Groovy, 65 60 characters
1.upto(9){x->1.upto(x){printf(x+"x$it=%-3d",x*it)}println()}
Sample run:
bash-4.3$ groovy -e '1.upto(9){x->1.upto(x){printf(x+"x$it=%-3d",x*it)}println()}'
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
Javascript, 190 bytes
Late to the party, but I was piqued by @jdstankosky 's comment and decided to take a different approach. Here's a Javascript entry that mauls a template and evals itself along the way.
t="a*b=c ";u="";r=u;for(i=1;i<10;i++){a=0;u=u+t;r+=u.split(' ').map(x=>x.replace('a',++a).replace('b',i)).map(x=>x.replace('*','x').replace('c',eval(x.substr(0,3)))).join(' ')+'\n'}alert(r);
Un-golfed version (slightly older version in which a function returns the table instead of a script alerting it, but the same principles apply):
function f()
{
t="a*b=c "; // template for our multiplication table
u="";r=""; // tmp- and return values
for(i=1;i<10;i++)
{
a=0; // is auto-incremented in MAP
u=u+t;// extend the template once per iteration
v=u.split(' '); // Smash the template to pieces
w=v.map(x=>x.replace('a', ++a).replace('b', i)) // MAP replaces the A and B's with the correct numbers
w=w.map(x=>x.replace('*', 'x').replace('c', eval(x.substring(0,3)))).join(' '); // second map evals that and replaces c with the answer, makes the asteriks into an X
r=r+w+'\n' // results get concatenated
}
return r;
}
D, 75 chars
foreach(i,1..10){foreach(j,1..i+1){writef("%dx%d=%d ",i,j,i*j);}writeln();}
you just said code not function or full program
Python 2, 91 characters
for k in[" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]:print k
Or, if each line as string like '1x2=2 2x2=4' is acceptable, this is 85 characters:
for k in[" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]:k
This one is slightly varied, resulting 93 characters:
print("\n".join([" ".join(["%ix%i=%i"%(j,i,j*i)for j in range(1,i+1)])for i in range(1,10)]))
x86_64 machine code (linux), 175 99 76 bytes
0000000000400080 <_start>:
400080: 66 bf 09 00 mov $0x9,%di
0000000000400084 <_table.L2>:
400084: 6a 0a pushq $0xa
400086: 89 fe mov %edi,%esi
0000000000400088 <_table.L3>:
400088: 89 f0 mov %esi,%eax
40008a: f7 e7 mul %edi
000000000040008c <_printInteger>:
40008c: 6a 20 pushq $0x20
40008e: 3c 0a cmp $0xa,%al
400090: 7d 02 jge 400094 <_printInteger.L1>
400092: 6a 20 pushq $0x20
0000000000400094 <_printInteger.L1>:
400094: 66 31 d2 xor %dx,%dx
400097: b3 0a mov $0xa,%bl
400099: 66 f7 f3 div %bx
40009c: 83 c2 30 add $0x30,%edx
40009f: 52 push %rdx
4000a0: 66 85 c0 test %ax,%ax
4000a3: 75 ef jne 400094 <_printInteger.L1>
4000a5: 6a 3d pushq $0x3d
4000a7: 66 57 push %di
4000a9: 80 04 24 30 addb $0x30,(%rsp)
4000ad: 6a 78 pushq $0x78
4000af: 66 56 push %si
4000b1: 80 04 24 30 addb $0x30,(%rsp)
4000b5: ff ce dec %esi
4000b7: 75 cf jne 400088 <_table.L3>
4000b9: ff cf dec %edi
4000bb: 75 c7 jne 400084 <_table.L2>
00000000004000bd <_printChars>:
4000bd: 66 ba 00 08 mov $0x800,%dx
4000c1: b0 01 mov $0x1,%al
4000c3: 66 bf 01 00 mov $0x1,%di
4000c7: 48 89 e6 mov %rsp,%rsi
4000ca: 0f 05 syscall
This is a dump of the binary file, and all of this is 175 bytes. It basically does the same two loops that all the answers do, but printing to the console is a bit harder and basically requires pushing the characters to print onto the stack in reverse, and then making a (linux specific) syscall to actually put those chars into stdout.
I've now optimized this so that only 1 write operation is performed (faster!) and has magic numbers (wow!) and by pushing the entire result onto the stack backwards before making the syscall. I also took out the exit routine because who needs proper exit code?
Here's a link to my first and second attempts, in their original nasm syntax.
I welcome anyone who has any other suggestions on how it can be improved. I can also explain the logic in more detail if anyone is curious.
(Also, it doesn't print the extra spaces to make all the columns aligned, but if that's required I can put the logic in at the cost of a few more bytes).
EDIT: Now prints extra spaces and is golfed down even more! It's doing some pretty crazy stuff with the registers, and is probably unstable if this program were to be expanded.
Javascript (using external library) (74 bytes)
n=>_.Range(1,9).WriteLine(v=>_.Range(1,v).Write(" ",x=>v+"x"+x+"="+(v*x)))
Link to lib: https://github.com/mvegh1/Enumerable
Code explanation: Create a range starting from 1, for 9 elements. For each integer in the range, write a line according to the predicate accepting the current value as the input param.
Each line in WriteLine will create a range from 1 to v, and write a space delimited string where each integer in the 1 to v sequence is mapped to the multiplication equation
JAVA, 103 94 92 90 bytes
Using JShell from Java 9 SDK allows me to save large amount of space
for(int i=0,j;i++<9;)for(j=1;j<=i;)System.out.print(i+"*"+j+"="+i*j+"\t"+(j++<i?"":"\n"))
Following Kevin's suggestion I reduced solution by 2 bytes.
Thanks to cliffroot, I was able to reduce it by another 1 byte
///, 268 bytes
/_/\/\///x/×_N/x9=_E/x8=_V/x7=_S/x6=_F/x5=_R/x4=_O/
1_t/ 2_h/ 3/1x1=1Ox2=2tx2=4Ox3=3tx3=6 hx3=9OR4tR8 hR12 4R16OF5tF10hF15 4F20 5F25OS6tS12hS18 4S24 5S30 6S36OV7tV14hV21 4V28 5V35 6V42 7V49OE8tE16hE24 4E32 5E40 6E48 7E56 8E64ON9tN18hN27 4N36 5N45 6N54 7N63 8N72 9N81
><>, 50 bytes
1v
1
?\::n"x"o{::n"="o}*n" "o1+:{:})
\~1+:a=?;ao
You can try it on the online interpreter.
Note that there is trailing spaces on each lines, which might make it incorrect (OP hasn't stated on this point as of this answer).
c#, 142 bytes
Enumerable.Range(1,9).ToList().ForEach(i =>Enumerable.Range(1,i).ToList().ForEach(j=>Console.Write("{0}x{1}={2}{3}",j,i,j*i,j==i?"\n":"\t")));
And not a for in sight...
Convex, 27 bytes
9´{_´f{æ*'×@@'=\_s,¿)S*}N}%
Use the following version if only a single space is required between each equation:
Convex, 21 bytes
9´{_´f{æ*'×@@'=\S}N}%
LOLCODE, 202 bytes
IM IN YR o UPPIN YR b TIL BOTH SAEM b AN 10
c R ""
IM IN YR i UPPIN YR a TIL BOTH SAEM a AN SUM OF b AN 1
c R SMOOSH c SMOOSH a "x" b "=" PRODUKT OF a AN b " " MKAY
IM OUTTA YR i
VISIBLE c
IM OUTTA YR o
Ungolfed:
HAI 1.3 BTW Unnecessary in current implementations
IM IN YR outer UPPIN YR multiplicand TIL BOTH SAEM multiplicand AN 10
I HAS A output ITZ ""
IM IN YR inner UPPIN YR multiplier TIL BOTH SAEM multiplier AN SUM OF multiplicand AN 1
output R SMOOSH output AN SMOOSH multiplier AN "x" AN multiplicand AN "=" AN PRODUCKT OF multiplicand AN multiplier AN " " MKAY MKAY BTW AN is optional to separate arguments, a linebreak is an implicit MKAY.
IM OUTTA YR inner
VISIBLE output
IM OUTTA YR outer
KTHXBYE BTW Unnecessary in current implementations
Pythonated for non-leetspeakers:
for multiplicand in range(1, 10):
output = ""
for multiplier in range(1, multiplicand + 1):
output = output + (multiplier + "x" + multiplicand + "=" + str(multiplicand * multiplier) + " ")
print(output)
Maple, 64
seq(printf(seq(printf("%ax%a=%a ",j,i,i*j),j=1..i),"\n"),i=1..9)
VBA, 118 bytes
Sub M()
While B<9
B=1-B*(B<>A)
A=A-(B=1)
S=S &B &"x"&A &"="&A*B &IIf(A=B,vbLf,Space(2+(A*B>9)))
Wend
MsgBox S
End Sub
No for loops :-) and only one while loop.
And no If statements, so I could potentially one-line it and get the automatic "End Sub" for 8 fewer bytes if pushed; but I'm not that close to the leaderboard :-)
Sub M():While B<9:B=1-B*(B<>A):A=A-(B=1):S=S &B &"x"&A &"="&A*B &IIf(A=B,vbLf,Space(2+(A*B>9))):Wend:MsgBox S
C, 86 85 84 bytes
i;m(j){for(;i++^9;puts(""))for(j=0;j++^i;printf("%d×%d=%d %c",j,i,j*i,j*i>9?:32));}
k (63 characters)
Prints the output to stdout.
-1@`/:" "/:'{7$x,"×",y,"=",z}.''$v,''(*).''v:(1+!:'t),''t:1+!9;
Example
k)-1@`/:" "/:'{7$x,"×",y,"=",z}.''$v,''(*).''v:(1+!:'t),''t:1+!9;
1×1=1
1×2=2 2×2=4
1×3=3 2×3=6 3×3=9
1×4=4 2×4=8 3×4=12 4×4=16
1×5=5 2×5=10 3×5=15 4×5=20 5×5=25
1×6=6 2×6=12 3×6=18 4×6=24 5×6=30 6×6=36
1×7=7 2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49
1×8=8 2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64
1×9=9 2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81
Javascript, ES6 65
for(i=0,r='';++i<10;r+='\n')for(e=0;e++<i;r+=i+'x'+e+'='+i*e+' ');
It was pretty fun to make!
Mathematica, 45
Pretty boring, but I guess it serves as a syntax comparison:
Grid@Table[Row@{a, "x", b, "=", a b}, {a, 9}, {b, a}]
Python 2, 72
i=1;exec"j=1;exec'print\"%sx%s=%-2s\"%(j,i,j*i),;j+=1;'*i;print;i+=1;"*9
Output:
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
C++, 126 characters
I took the expected approach.
#include <iostream>
int main(){for(int i=1,j;i<10;i++){for(j=1;j<=i;j++)std::cout<<i<<"x"<<j<<"="<<i*j<<" ";std::cout<<std::endl;}}
Ruby: 79 77 characters (without loops)
m=->i,j{"%dx%d=%-3d"%[i,j,i*j]+(i<j ?m[i+1,j]:j<9?$/+m[1,j+1]:$/)};$><<m[1,1]
Sample run:
bash-4.2$ ruby -e 'm=->i,j{"%dx%d=%-3d"%[i,j,i*j]+(i<j ?m[i+1,j]:j<9?$/+m[1,j+1]:$/)};$><<m[1,1]'
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
Erlang escript 99
$ cat multi
main(_)->[[[io:format("~bx~b=~-3b",[B,A,A*B])||B<-s(A)],io:nl()]||A<-s(9)].
s(X)->lists:seq(1,X).
and run
$ escript multi
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
APL (Dyalog), 28
↑{⍵{⍕⍵,'×',⍺,'=',⍺×⍵}¨⍳⍵}¨⍳9
Analogous to a double loop in other languages
{⍵{...}¨⍳⍵}¨⍳9 sets up the double loop
⍕⍵,'×',⍺,'=',⍺×⍵ creates the string for each pair
↑ Convert array of array of strings to a matrix of stings
Output
1 × 1 = 1
1 × 2 = 2 2 × 2 = 4
1 × 3 = 3 2 × 3 = 6 3 × 3 = 9
1 × 4 = 4 2 × 4 = 8 3 × 4 = 12 4 × 4 = 16
1 × 5 = 5 2 × 5 = 10 3 × 5 = 15 4 × 5 = 20 5 × 5 = 25
1 × 6 = 6 2 × 6 = 12 3 × 6 = 18 4 × 6 = 24 5 × 6 = 30 6 × 6 = 36
1 × 7 = 7 2 × 7 = 14 3 × 7 = 21 4 × 7 = 28 5 × 7 = 35 6 × 7 = 42 7 × 7 = 49
1 × 8 = 8 2 × 8 = 16 3 × 8 = 24 4 × 8 = 32 5 × 8 = 40 6 × 8 = 48 7 × 8 = 56 8 × 8 = 64
1 × 9 = 9 2 × 9 = 18 3 × 9 = 27 4 × 9 = 36 5 × 9 = 45 6 × 9 = 54 7 × 9 = 63 8 × 9 = 72 9 × 9 = 81
Perl, 54 Characters
printf"%dx$?=%-3d"x$?.$/,map{$_,$_*$?}1..$?while$?++<9
Python (75)
r=range(1,10)
for i in r:print''.join('%sx%s=%-3s'%(j,i,i*j)for j in r[:i])
a little better golfed than the other two Python versions.
VBScript (133); without loops.
g=""
sub m(x,y)
g=x&"x"&y&"="&x*y&vbTab&g
if x>1 then
m x-1,y
elseif y>1 then
g=vbLf&g
m y-1,y-1
end if
end sub
m 9,9
wscript.echo g
On request of the challenger: no loops. This code uses recursive subroutine calls.
Ruby: 60 59 characters
1.upto(9){|i|puts (1..i).map{|j|"%dx%d=%-3d"%[j,i,i*j]}*""}
Sample run:
bash-4.2$ ruby -e '1.upto(9){|i|puts (1..i).map{|j|"%dx%d=%-3d"%[j,i,i*j]}*""}'
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81



