Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Multiplication Table in Various Programming Languages

4ba2629b4f4c832f479045fc2392be0e?s=47 趙惟倫
September 18, 2018

Multiplication Table in Various Programming Languages

4ba2629b4f4c832f479045fc2392be0e?s=128

趙惟倫

September 18, 2018
Tweet

Transcript

  1. Wei-Lun Chao <bluebat@member.fsf.org> 18 Sep. 2018 Multiplication Table in Various

    Multiplication Table in Various Programming Languages Programming Languages TOSSUG
  2. Beginner's practices Beginner's practices 1st program Hello, World! 2nd program

    Multiplication Table <https://github.com/bluebat/mt9x9> 3rd program Fibonacci Number ? 1x1= 1 2x1= 2 3x1= 3 1x2= 2 2x2= 4 3x2= 6 1x3= 3 2x3= 6 3x3= 9 1x4= 4 2x4= 8 3x4=12 1x5= 5 2x5=10 3x5=15 1x6= 6 2x6=12 3x6=18 1x7= 7 2x7=14 3x7=21 1x8= 8 2x8=16 3x8=24 1x9= 9 2x9=18 3x9=27 4x1= 4 5x1= 5 6x1= 6 4x2= 8 5x2=10 6x2=12 4x3=12 5x3=15 6x3=18 4x4=16 5x4=20 6x4=24 4x5=20 5x5=25 6x5=30 4x6=24 5x6=30 6x6=36 4x7=28 5x7=35 6x7=42 4x8=32 5x8=40 6x8=48 4x9=36 5x9=45 6x9=54 7x1= 7 8x1= 8 9x1= 9 7x2=14 8x2=16 9x2=18 7x3=21 8x3=24 9x3=27 7x4=28 8x4=32 9x4=36 7x5=35 8x5=40 9x5=45 7x6=42 8x6=48 9x6=54 7x7=49 8x7=56 9x7=63 7x8=56 8x8=64 9x8=72 7x9=63 8x9=72 9x9=81
  3. Code to Code Code to Code #!/usr/bin/basica 1 REM ./mt9x9.BAS

    || basica mt9x9.BAS 10 FOR I = 1 TO 9 STEP 3 20 FOR J = 1 TO 9 30 FOR K = I TO I+2 40 PRINT USING "#x#=##"+CHR$(9); K, J, K*J; 50 NEXT 60 PRINT CHR$(10); 70 NEXT 80 PRINT 90 NEXT #!/usr/bin/basica 1 REM ./mt9x9.BAS || basica mt9x9.BAS 10 FOR I = 1 TO 9 STEP 3 20 FOR J = 1 TO 9 30 FOR K = I TO I+2 40 PRINT USING "#x#=##"+CHR$(9); K, J, K*J; 50 NEXT 60 PRINT CHR$(10); 70 NEXT 80 PRINT 90 NEXT #!/usr/bin/bas rem ./mt9x9.bas || bas mt9x9.bas for i% = 1 to 9 step 3 for j% = 1 to 9 for k% = i% to i%+2 print using "#x#=##"+chr$(9); k%, j%, k%*j%; next k% print chr$(10); next j% print next i% #!/usr/bin/bas rem ./mt9x9.bas || bas mt9x9.bas for i% = 1 to 9 step 3 for j% = 1 to 9 for k% = i% to i%+2 print using "#x#=##"+chr$(9); k%, j%, k%*j%; next k% print chr$(10); next j% print next i% QBASIC BASICA
  4. Code to Code Code to Code ‘ oscript mt9x9.vbs For

    i = 1 To 9 Step 3 For j = 1 To 9 s = "" For k = i To i+2 s = s+CStr(k)+"x"+CStr(j)+"=" If k*j < 10 Then s = s+" " End If s = s+CStr(k*j)+vbTab Next Wscript.Echo s Next Wscript.Echo "" Next ‘ oscript mt9x9.vbs For i = 1 To 9 Step 3 For j = 1 To 9 s = "" For k = i To i+2 s = s+CStr(k)+"x"+CStr(j)+"=" If k*j < 10 Then s = s+" " End If s = s+CStr(k*j)+vbTab Next Wscript.Echo s Next Wscript.Echo "" Next Rem vbnc mt9x9.vbn && mono mt9x9.exe Imports System.Console Module mt9x9 Sub Main() Dim i, j, k As Integer For i = 1 to 9 step 3 For j = 1 to 9 For Each k In New Integer() {i, i+1, i+2} Write("{0}x{1}={2,2}{3}", k, j, k*j, vbTab) Next Write(vbLf) Next WriteLine() Next End Sub End Module Rem vbnc mt9x9.vbn && mono mt9x9.exe Imports System.Console Module mt9x9 Sub Main() Dim i, j, k As Integer For i = 1 to 9 step 3 For j = 1 to 9 For Each k In New Integer() {i, i+1, i+2} Write("{0}x{1}={2,2}{3}", k, j, k*j, vbTab) Next Write(vbLf) Next WriteLine() Next End Sub End Module VB.NET VBScript
  5. Code to Code Code to Code -- sacomp mt9x9.sa -o

    mt9x9 && ./mt9x9 class MAIN is main is loop i ::= 1.stepto!(9, 3); loop j ::= 1.upto!(9); k:ARRAY{INT} := |i, i+1, i+2|; loop #OUT+ k.elt!+"x"+j+"="+#FMT("%2d", k.elt!*j)+"\t" end; #OUT+ "\n"; end; #OUT+ "\n"; end end end -- sacomp mt9x9.sa -o mt9x9 && ./mt9x9 class MAIN is main is loop i ::= 1.stepto!(9, 3); loop j ::= 1.upto!(9); k:ARRAY{INT} := |i, i+1, i+2|; loop #OUT+ k.elt!+"x"+j+"="+#FMT("%2d", k.elt!*j)+"\t" end; #OUT+ "\n"; end; #OUT+ "\n"; end end end #!/usr/bin/rexx -- ./mt9x9.rex || rexx mt9x9.rex loop i = 1 to 9 by 3 loop j = 1 to 9 loop k = i to i+2 .output~charout(k"x"j"="format(k*j, 2)"09"x) end .output~charout("0a"x) end say end #!/usr/bin/rexx -- ./mt9x9.rex || rexx mt9x9.rex loop i = 1 to 9 by 3 loop j = 1 to 9 loop k = i to i+2 .output~charout(k"x"j"="format(k*j, 2)"09"x) end .output~charout("0a"x) end say end REXX Sather
  6. Code to Code Code to Code *> cobc -Fx mt9x9.cob

    && ./mt9x9 || cobc -Fxj mt9x9.cob identification division. program-id. mt9x9. data division. working-storage section. 01 i pic 9. 01 j pic 9. 01 k pic 9. 01 l pic 9. 01 kj pic z9. procedure division. perform varying i from 0 by 3 until i greater than 8 perform with test after varying j from 1 by 1 until j equal 9 perform varying l from 1 by 1 until l greater than 3 add i l giving k multiply k by j giving kj display k "x" j "=" kj x"09" with no advancing end-perform display x"0a" with no advancing end-perform display x"00" end-perform stop run. *> cobc -Fx mt9x9.cob && ./mt9x9 || cobc -Fxj mt9x9.cob identification division. program-id. mt9x9. data division. working-storage section. 01 i pic 9. 01 j pic 9. 01 k pic 9. 01 l pic 9. 01 kj pic z9. procedure division. perform varying i from 0 by 3 until i greater than 8 perform with test after varying j from 1 by 1 until j equal 9 perform varying l from 1 by 1 until l greater than 3 add i l giving k multiply k by j giving kj display k "x" j "=" kj x"09" with no advancing end-perform display x"0a" with no advancing end-perform display x"00" end-perform stop run. % gplc mt9x9.prolog && ./mt9x9 :- initialization(main). item(I,J,K) :- K =< I+2 -> ( format('%dx%d=%2d\t',[K,J,K*J]), item(I,J,K+1) ); format('~n',[]). line(I,J) :- J =< 9 -> ( item(I,J,I), line(I,J+1) ); nl. block(I) :- I =< 9 -> ( line(I,1), block(I+3) ); halt. main :- block(1). % gplc mt9x9.prolog && ./mt9x9 :- initialization(main). item(I,J,K) :- K =< I+2 -> ( format('%dx%d=%2d\t',[K,J,K*J]), item(I,J,K+1) ); format('~n',[]). line(I,J) :- J =< 9 -> ( item(I,J,I), line(I,J+1) ); nl. block(I) :- I =< 9 -> ( line(I,1), block(I+3) ); halt. main :- block(1). Prolog COBOL
  7. Code to Code Code to Code comment awe mt9x9.alw -o

    mt9x9 && ./mt9x9 ; begin for i := 1 step 3 until 9 do begin for j := 1 until 9 do begin for k := i, i+1, i+2 do begin writeon(i_w := 1, s_w := 0, k, "x", j, "="); writeon(i_w := 2, s_w := 2, k*j) end k; write(code(0)) end j; write() end i end. comment awe mt9x9.alw -o mt9x9 && ./mt9x9 ; begin for i := 1 step 3 until 9 do begin for j := 1 until 9 do begin for k := i, i+1, i+2 do begin writeon(i_w := 1, s_w := 0, k, "x", j, "="); writeon(i_w := 2, s_w := 2, k*j) end k; write(code(0)) end j; write() end i end. % cim mt9x9.sim && ./mt9x9 Begin Integer i, j, k; For i := 1 Step 3 Until 9 Do Begin For j := 1 Step 1 Until 9 Do Begin For k := i Step 1 Until i+2 Do Begin OutInt(k, 0); OutText("x"); OutInt(j, 0); OutText("="); OutInt(k*j, 2); OutText("!9!") End; OutImage End; OutImage End End % cim mt9x9.sim && ./mt9x9 Begin Integer i, j, k; For i := 1 Step 3 Until 9 Do Begin For j := 1 Step 1 Until 9 Do Begin For k := i Step 1 Until i+2 Do Begin OutInt(k, 0); OutText("x"); OutInt(j, 0); OutText("="); OutInt(k*j, 2); OutText("!9!") End; OutImage End; OutImage End End Simula Algol
  8. Code to Code Code to Code (* obnc mt9x9.obn &&

    ./mt9x9 *) MODULE mt9x9; IMPORT Out; VAR i, j, k : INTEGER; BEGIN FOR i := 1 TO 9 BY 3 DO FOR j := 1 TO 9 DO FOR k := i TO i+2 DO Out.Int(k,1); Out.String("x"); Out.Int(j,1); Out.String("="); Out.Int(k*j,2); Out.Char(09X) END; Out.Char(0AX) END; Out.Ln END END mt9x9. (* obnc mt9x9.obn && ./mt9x9 *) MODULE mt9x9; IMPORT Out; VAR i, j, k : INTEGER; BEGIN FOR i := 1 TO 9 BY 3 DO FOR j := 1 TO 9 DO FOR k := i TO i+2 DO Out.Int(k,1); Out.String("x"); Out.Int(j,1); Out.String("="); Out.Int(k*j,2); Out.Char(09X) END; Out.Char(0AX) END; Out.Ln END END mt9x9. (* m2c -all mt9x9.mod -o mt9x9 && ./mt9x9 *) MODULE mt9x9; IMPORT InOut; VAR i, j, k: CARDINAL; BEGIN FOR i:=1 TO 9 BY 3 DO FOR j:=1 TO 9 DO FOR k:=i TO i+2 DO InOut.WriteInt(k, 1); InOut.Write('x'); InOut.WriteInt(j, 1); InOut.Write('='); InOut.WriteInt(k*j, 2); InOut.Write(11C); END; InOut.Write(12C); END; InOut.WriteLn; END; END mt9x9. (* m2c -all mt9x9.mod -o mt9x9 && ./mt9x9 *) MODULE mt9x9; IMPORT InOut; VAR i, j, k: CARDINAL; BEGIN FOR i:=1 TO 9 BY 3 DO FOR j:=1 TO 9 DO FOR k:=i TO i+2 DO InOut.WriteInt(k, 1); InOut.Write('x'); InOut.WriteInt(j, 1); InOut.Write('='); InOut.WriteInt(k*j, 2); InOut.Write(11C); END; InOut.Write(12C); END; InOut.WriteLn; END; END mt9x9. Modula-2 Oberon
  9. Code to Code Code to Code -- gnat make mt9x9.adb

    && ./mt9x9 with Ada.Text_IO; use Ada.Text_IO; procedure mt9x9 is package IO is new Integer_IO (Integer); use IO; V : array (1..3) of Integer := (1, 4, 7); begin for i of V loop for j in 1..9 loop for k in i..i+2 loop Put (k, Width => 1); Put ("x"); Put (j, Width => 1); Put ("="); Put (k*j, Width => 2); Put (ASCII.HT); end loop; Put_Line (""); end loop; New_Line; end loop; end mt9x9; -- gnat make mt9x9.adb && ./mt9x9 with Ada.Text_IO; use Ada.Text_IO; procedure mt9x9 is package IO is new Integer_IO (Integer); use IO; V : array (1..3) of Integer := (1, 4, 7); begin for i of V loop for j in 1..9 loop for k in i..i+2 loop Put (k, Width => 1); Put ("x"); Put (j, Width => 1); Put ("="); Put (k*j, Width => 2); Put (ASCII.HT); end loop; Put_Line (""); end loop; New_Line; end loop; end mt9x9; #!/usr/bin/spar -- ./mt9x9.sp || spar mt9x9.sp procedure mt9x9 is begin i := 1; while i <= 9 loop for j in 1..9 loop for k in i..i+2 loop put(k, "9"); put("x"); put(j, "9"); put("="); put(k*j, "Z9"); put(ASCII.HT); end loop; put_line(""); end loop; new_line; i := @ + 3; end loop; end mt9x9; #!/usr/bin/spar -- ./mt9x9.sp || spar mt9x9.sp procedure mt9x9 is begin i := 1; while i <= 9 loop for j in 1..9 loop for k in i..i+2 loop put(k, "9"); put("x"); put(j, "9"); put("="); put(k*j, "Z9"); put(ASCII.HT); end loop; put_line(""); end loop; new_line; i := @ + 3; end loop; end mt9x9; AdaScript Ada
  10. Code to Code Code to Code -- se c mt9x9.e

    -clean -o mt9x9 && ./mt9x9 class MT9X9 create {ANY} make feature {ANY} make local i: INTEGER do from i := 1 until i > 9 loop block(i) print("%N") i := i + 3 end end block (i: INTEGER) local j: INTEGER do from j := 1 until j > 9 loop line(i, j) io.put_new_line j := j + 1 end end line (i, j: INTEGER) local k: INTEGER do from k := i until k > i+2 loop io.put_string(k.out + "x" + j.out + "=") io.put_string(if k*j<10 then " " else "" end) io.put_string((k*j).out + "%T") k := k + 1 end end end -- se c mt9x9.e -clean -o mt9x9 && ./mt9x9 class MT9X9 create {ANY} make feature {ANY} make local i: INTEGER do from i := 1 until i > 9 loop block(i) print("%N") i := i + 3 end end block (i: INTEGER) local j: INTEGER do from j := 1 until j > 9 loop line(i, j) io.put_new_line j := j + 1 end end line (i, j: INTEGER) local k: INTEGER do from k := i until k > i+2 loop io.put_string(k.out + "x" + j.out + "=") io.put_string(if k*j<10 then " " else "" end) io.put_string((k*j).out + "%T") k := k + 1 end end end { fpc mt9x9.pas && ./mt9x9 } program mt9x9; uses SysUtils; var i, j, k : Integer; begin for i in [1, 4, 7] do begin for j := 1 to 9 do begin for k := i to i+2 do begin Write(Format('%dx%d=%2d'#9, [k, j, k*j])); end; Write(#10); end; Writeln; end; end. { fpc mt9x9.pas && ./mt9x9 } program mt9x9; uses SysUtils; var i, j, k : Integer; begin for i in [1, 4, 7] do begin for j := 1 to 9 do begin for k := i to i+2 do begin Write(Format('%dx%d=%2d'#9, [k, j, k*j])); end; Write(#10); end; Writeln; end; end. Pascal Eiffel
  11. Code to Code Code to Code #!/usr/bin/mumps ; ./mt9x9.mps ||

    mumps mt9x9.mps mt9x9 for i=1:3:9 do . for j=1:1:9 do .. for k=i,i+1,i+2 do ... write k,"x",j,"=",$justify(k*j,2),$char(9) .. write $char(10) . write ! #!/usr/bin/mumps ; ./mt9x9.mps || mumps mt9x9.mps mt9x9 for i=1:3:9 do . for j=1:1:9 do .. for k=i,i+1,i+2 do ... write k,"x",j,"=",$justify(k*j,2),$char(9) .. write $char(10) . write ! ! gfortran mt9x9.f90 -o mt9x9 && ./mt9x9 program mt9x9 implicit none integer :: i, j, k character(len=24) :: format do i = 1, 9, 3 format = "(3(i1, a, i1, a, i2, a))" write(*,format) ((k, 'x', j, '=', k*j, char(9), k = i, i+2), j = 1, 9) write(*,*) end do end program mt9x9 ! gfortran mt9x9.f90 -o mt9x9 && ./mt9x9 program mt9x9 implicit none integer :: i, j, k character(len=24) :: format do i = 1, 9, 3 format = "(3(i1, a, i1, a, i2, a))" write(*,format) ((k, 'x', j, '=', k*j, char(9), k = i, i+2), j = 1, 9) write(*,*) end do end program mt9x9 Fortran MUMPS
  12. Code to Code Code to Code #!/usr/bin/ocaml (* ./mt9x9.ml ||

    ocaml mt9x9.ml *) for i = 1 to 3 do for j = 1 to 9 do for k = i*3-2 to i*3 do Printf.printf "%dx%d=%2d\t" k j (k*j) done; print_string "\n" done; print_newline() done; #!/usr/bin/ocaml (* ./mt9x9.ml || ocaml mt9x9.ml *) for i = 1 to 3 do for j = 1 to 9 do for k = i*3-2 to i*3 do Printf.printf "%dx%d=%2d\t" k j (k*j) done; print_string "\n" done; print_newline() done; (* mlton mt9x9.sml && ./mt9x9 *) val i = ref 1; val j = ref 1; val k = ref 1; while (!i <= 7) do ( j := 1; while (!j <= 9) do ( k := !i; while (!k <= (!i + 2)) do ( print (Int.toString (!k) ^ "x" ^ Int.toString (!j) ^ "="); print (if (!k * !j) < 10 then " " else ""); print (Int.toString (!k * !j) ^ "\t"); k := !k + 1 ); print "\n"; j := !j + 1 ); print "\n"; i := !i + 3 ); (* mlton mt9x9.sml && ./mt9x9 *) val i = ref 1; val j = ref 1; val k = ref 1; while (!i <= 7) do ( j := 1; while (!j <= 9) do ( k := !i; while (!k <= (!i + 2)) do ( print (Int.toString (!k) ^ "x" ^ Int.toString (!j) ^ "="); print (if (!k * !j) < 10 then " " else ""); print (Int.toString (!k * !j) ^ "\t"); k := !k + 1 ); print "\n"; j := !j + 1 ); print "\n"; i := !i + 3 ); SML Caml
  13. Code to Code Code to Code #!/usr/bin/logo ; ./mt9x9.logo ||

    logo mt9x9.logo for [i 1 9 3] [ for [j 1 9] [ for [k :i :i+2] [ (type :k "x :j "= form :k*:j 2 0 char 9) ] (type char 10) ] (print) ] bye #!/usr/bin/logo ; ./mt9x9.logo || logo mt9x9.logo for [i 1 9 3] [ for [j 1 9] [ for [k :i :i+2] [ (type :k "x :j "= form :k*:j 2 0 char 9) ] (type char 10) ] (print) ] bye #!/usr/bin/rebol -q ; ./mt9x9.r || rebol -q mt9x9.r rebol [] foreach i [1 4 7] [ repeat j 9 [ for k i (i + 2) 1 [ prin rejoin [k "x" j "=" either k * j < 10 [" "] [""] k * j tab] ] prin crlf ] print "" ] #!/usr/bin/rebol -q ; ./mt9x9.r || rebol -q mt9x9.r rebol [] foreach i [1 4 7] [ repeat j 9 [ for k i (i + 2) 1 [ prin rejoin [k "x" j "=" either k * j < 10 [" "] [""] k * j tab] ] prin crlf ] print "" ] REBOL Logo
  14. Code to Code Code to Code #!/usr/bin/dao # ./mt9x9.dao ||

    dao mt9x9.dao for(var i = 1:3:10) { for(var j = 1:10) { for(var k in {i, i+1, i+2}) io.writef("%dx%d=%2d\t", k, j, k*j) io.write("\n") } io.writeln() } #!/usr/bin/dao # ./mt9x9.dao || dao mt9x9.dao for(var i = 1:3:10) { for(var j = 1:10) { for(var k in {i, i+1, i+2}) io.writef("%dx%d=%2d\t", k, j, k*j) io.write("\n") } io.writeln() } #!/usr/bin/boron ; ./mt9x9.b || boron mt9x9.b foreach i [1 4 7] [ foreach j [1 2 3 4 5 6 7 8 9] [ foreach K [0 1 2] [ k: add i K prin rejoin [k 'x' j '=' format [-2] mul k j '^-'] ] prin '^/' ] print "" ] #!/usr/bin/boron ; ./mt9x9.b || boron mt9x9.b foreach i [1 4 7] [ foreach j [1 2 3 4 5 6 7 8 9] [ foreach K [0 1 2] [ k: add i K prin rejoin [k 'x' j '=' format [-2] mul k j '^-'] ] prin '^/' ] print "" ] Boron Dao
  15. Code to Code Code to Code // gcc mt9x9.c -o

    mt9x9 && ./mt9x9 #include <stdio.h> int main(int argc, char *argv[]) { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j); putchar(10); } printf("\n"); } } // gcc mt9x9.c -o mt9x9 && ./mt9x9 #include <stdio.h> int main(int argc, char *argv[]) { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j); putchar(10); } printf("\n"); } } // g++ mt9x9.cpp -o mt9x9 && ./mt9x9 #include <iostream> using namespace std; int main() { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j); printf("\n"); } cout << endl; } } // g++ mt9x9.cpp -o mt9x9 && ./mt9x9 #include <iostream> using namespace std; int main() { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j); printf("\n"); } cout << endl; } } C++ C
  16. Code to Code Code to Code // mcs mt9x9.cs &&

    mono mt9x9.exe using System; class Program { static void Main(string[] args) { int i, j, k; for (i = 1; i <= 9; i += 3) { for (j = 1; j <= 9; j++) { for (k = i; k <= i+2; k++) Console.Write("{0}x{1}={2}\t", k, j, (k*j).ToString().PadLeft(2)); Console.Write("\n"); } Console.WriteLine(); } } } // mcs mt9x9.cs && mono mt9x9.exe using System; class Program { static void Main(string[] args) { int i, j, k; for (i = 1; i <= 9; i += 3) { for (j = 1; j <= 9; j++) { for (k = i; k <= i+2; k++) Console.Write("{0}x{1}={2}\t", k, j, (k*j).ToString().PadLeft(2)); Console.Write("\n"); } Console.WriteLine(); } } } // ldc2 mt9x9.d && ./mt9x9 || ldc2 -run mt9x9.d import std.stdio; void main() { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) writef("%dx%d=%2d\t", k, j, k*j); write(char(10)); } writeln(); } } // ldc2 mt9x9.d && ./mt9x9 || ldc2 -run mt9x9.d import std.stdio; void main() { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) writef("%dx%d=%2d\t", k, j, k*j); write(char(10)); } writeln(); } } D C#
  17. Code to Code Code to Code #!/usr/bin/crystal # crystal build

    mt9x9.cr && ./mt9x9 || ./mt9x9.cr # || crystal mt9x9.cr 1.step(to: 9, by: 3) do |i| 1.upto(9) do |j| [i, i+1, i+2].each do |k| print "#{k}x#{j}=#{k*j<10 ? " " : ""}#{k*j}\t" end puts end puts end #!/usr/bin/crystal # crystal build mt9x9.cr && ./mt9x9 || ./mt9x9.cr # || crystal mt9x9.cr 1.step(to: 9, by: 3) do |i| 1.upto(9) do |j| [i, i+1, i+2].each do |k| print "#{k}x#{j}=#{k*j<10 ? " " : ""}#{k*j}\t" end puts end puts end #!/usr/bin/gjs // ./mt9x9.js || gjs mt9x9.js for(var i = 1; i <= 9; i += 3) { for(var j = 1; j <= 9; j++) print( [i, i+1, i+2].map( k => k+'x'+j+'='+(' '+k*j).slice(-2) ).join('\t') ) print() } #!/usr/bin/gjs // ./mt9x9.js || gjs mt9x9.js for(var i = 1; i <= 9; i += 3) { for(var j = 1; j <= 9; j++) print( [i, i+1, i+2].map( k => k+'x'+j+'='+(' '+k*j).slice(-2) ).join('\t') ) print() } JavaScript Crystal
  18. Code to Code Code to Code // javac mt9x9.java &&

    java mt9x9 public class mt9x9 { public static void main(String args[]) { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) System.out.printf("%dx%d=%2d\t", k, j, k*j); System.out.printf("\n"); } System.out.println(); } } } // javac mt9x9.java && java mt9x9 public class mt9x9 { public static void main(String args[]) { int i, j, k; for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) System.out.printf("%dx%d=%2d\t", k, j, k*j); System.out.printf("\n"); } System.out.println(); } } } #!/usr/bin/fan // ./mt9x9.fan || fan mt9x9.fan class mt9x9 { static Void main() { for(i := 1; i < 9; i += 3) { for(j := 1; j <= 9; j++) { [i, i+1, i+2].each |Int k| { Env.cur.out.print(k.toStr+"x"+j.toStr+"="+ (k*j).toStr.padl(2,' ')+"\t") } Env.cur.out.printLine() } echo() } } } #!/usr/bin/fan // ./mt9x9.fan || fan mt9x9.fan class mt9x9 { static Void main() { for(i := 1; i < 9; i += 3) { for(j := 1; j <= 9; j++) { [i, i+1, i+2].each |Int k| { Env.cur.out.print(k.toStr+"x"+j.toStr+"="+ (k*j).toStr.padl(2,' ')+"\t") } Env.cur.out.printLine() } echo() } } } Fantom Java
  19. Code to Code Code to Code // scalac mt9x9.scala &&

    scala mt9x9 object mt9x9 { def main(args: Array[String]) = { for (i <- 1 to 9 by 3) { for (j <- 1 to 9) { List(i, i+1, i+2).foreach { k => print(k+"x"+j+"="+f"${k*j}%2d"+"\t") } println() } println() } } } // scalac mt9x9.scala && scala mt9x9 object mt9x9 { def main(args: Array[String]) = { for (i <- 1 to 9 by 3) { for (j <- 1 to 9) { List(i, i+1, i+2).foreach { k => print(k+"x"+j+"="+f"${k*j}%2d"+"\t") } println() } println() } } } % ozc -c mt9x9.oz && ozengine mt9x9.ozf functor import System define for I in 1..9;3 do for J in 1..9 do for K in [I I+1 I+2] do {System.printInfo K#"x"#J#"="} if K*J < 10 then {System.printInfo " "} end {System.printInfo K*J#"\t"} end {System.printInfo "\n"} end {System.showInfo ""} end end % ozc -c mt9x9.oz && ozengine mt9x9.ozf functor import System define for I in 1..9;3 do for J in 1..9 do for K in [I I+1 I+2] do {System.printInfo K#"x"#J#"="} if K*J < 10 then {System.printInfo " "} end {System.printInfo K*J#"\t"} end {System.printInfo "\n"} end {System.showInfo ""} end end Oz Scala
  20. Code to Code Code to Code #!/usr/bin/groovy // ./mt9x9.groovy ||

    groovy mt9x9.groovy for(i in (1..9).step(3)) { for(j in 1..9) { for(k in [i, i+1, i+2]) { printf("%dx%d=%2d\t", k, j, k*j) } println() } println "" } #!/usr/bin/groovy // ./mt9x9.groovy || groovy mt9x9.groovy for(i in (1..9).step(3)) { for(j in 1..9) { for(k in [i, i+1, i+2]) { printf("%dx%d=%2d\t", k, j, k*j) } println() } println "" } // ceylon compile --src . mt9x9.ceylon && ceylon run default shared void run() { for(i in (1..9).by(3)) { for(j in 1..9) { for(k in [i, i+1, i+2]) { process.write("``k``x``j``="); process.write("``k*j<10 then " " else ""````k*j``\t"); } print(""); } print(""); } } // ceylon compile --src . mt9x9.ceylon && ceylon run default shared void run() { for(i in (1..9).by(3)) { for(j in 1..9) { for(k in [i, i+1, i+2]) { process.write("``k``x``j``="); process.write("``k*j<10 then " " else ""````k*j``\t"); } print(""); } print(""); } } Ceylon Groovy
  21. Code to Code Code to Code #!/usr/bin/perl # ./mt9x9.pl ||

    perl mt9x9.pl for (my $i = 1; $i <= 9; $i += 3) { for (my $j = 1; $j <= 9; $j++) { foreach my $k ($i..$i+2) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } printf("\n"); } print "\n"; } #!/usr/bin/perl # ./mt9x9.pl || perl mt9x9.pl for (my $i = 1; $i <= 9; $i += 3) { for (my $j = 1; $j <= 9; $j++) { foreach my $k ($i..$i+2) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } printf("\n"); } print "\n"; } #!/usr/bin/rakudo # ./mt9x9.raku || rakudo mt9x9.raku for 1,4,7 -> $i { for 1..9 -> $j { for $i, $i+1, $i+2 -> $k { printf "%dx%d=%2d\t", $k, $j, $k*$j; } print "\n"; } say ""; } #!/usr/bin/rakudo # ./mt9x9.raku || rakudo mt9x9.raku for 1,4,7 -> $i { for 1..9 -> $j { for $i, $i+1, $i+2 -> $k { printf "%dx%d=%2d\t", $k, $j, $k*$j; } print "\n"; } say ""; } Raku Perl
  22. Code to Code Code to Code #!/usr/bin/odo # ./mt9x9.odo ||

    odo mt9x9.odo foreach i : [1, 4, 7] { forange j : 1, 10 { forange k : i, i+3 { write(k, "x", j, "=") if k*j < 10 {write(" ")} write(k*j, "\t") } write("\n") } writeln() } #!/usr/bin/odo # ./mt9x9.odo || odo mt9x9.odo foreach i : [1, 4, 7] { forange j : 1, 10 { forange k : i, i+3 { write(k, "x", j, "=") if k*j < 10 {write(" ")} write(k*j, "\t") } write("\n") } writeln() } #!/usr/bin/aime # ./mt9x9.aime || aime mt9x9.aime integer i, j, k; for (,i in list(1, 4, 7)) { j = 1; while (j <= 9) { for (,k in list(i, i+1, i+2)) { o_(k, "x", j, "="); o_winteger(2, k*j); o_text("\t"); } o_text("\n"); j += 1; } o_newline(); } #!/usr/bin/aime # ./mt9x9.aime || aime mt9x9.aime integer i, j, k; for (,i in list(1, 4, 7)) { j = 1; while (j <= 9) { for (,k in list(i, i+1, i+2)) { o_(k, "x", j, "="); o_winteger(2, k*j); o_text("\t"); } o_text("\n"); j += 1; } o_newline(); } Aime Odo
  23. Code to Code Code to Code #!/usr/bin/slsh % ./mt9x9.sl ||

    slsh mt9x9.sl variable i, j, k; foreach i ([1:9:3]) { foreach j ([1:9]) { foreach k ([i, i+1, i+2]) { printf("%dx%d=%2d\t", k, j, k*j); } fprintf(stdout, "\n"); } fputs("\n", stdout); } #!/usr/bin/slsh % ./mt9x9.sl || slsh mt9x9.sl variable i, j, k; foreach i ([1:9:3]) { foreach j ([1:9]) { foreach k ([i, i+1, i+2]) { printf("%dx%d=%2d\t", k, j, k*j); } fprintf(stdout, "\n"); } fputs("\n", stdout); } #!/usr/bin/lua -- ./mt9x9.lua || lua mt9x9.lua for i = 1,9,3 do for j = 1,9 do for k = i,i+2 do io.write(string.format('%dx%d=%2d\t', k, j, k*j)) end io.write('\n') end print() end #!/usr/bin/lua -- ./mt9x9.lua || lua mt9x9.lua for i = 1,9,3 do for j = 1,9 do for k = i,i+2 do io.write(string.format('%dx%d=%2d\t', k, j, k*j)) end io.write('\n') end print() end Lua S-Lang
  24. Code to Code Code to Code #!/usr/bin/tclsh # ./mt9x9.tcl ||

    tclsh mt9x9.tcl for {set i 1} {$i <= 9} {incr i 3} { for {set j 1} {$j <= 9} {incr j} { for {set k $i} {$k <= $i+2} {incr k} { puts -nonewline [ format "%dx%d=%2d\t" $k $j [expr {$k*$j}] ] } puts -nonewline "\n" } puts "" } #!/usr/bin/tclsh # ./mt9x9.tcl || tclsh mt9x9.tcl for {set i 1} {$i <= 9} {incr i 3} { for {set j 1} {$j <= 9} {incr j} { for {set k $i} {$k <= $i+2} {incr k} { puts -nonewline [ format "%dx%d=%2d\t" $k $j [expr {$k*$j}] ] } puts -nonewline "\n" } puts "" } #!/usr/bin/php <?php // ./mt9x9.php || php mt9x9.php for($i = 1; $i <= 9; $i += 3) { for($j = 1; $j <= 9; $j++) { for($k = $i; $k <= $i+2; $k++) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } printf("\n"); } echo "\n"; } ?> #!/usr/bin/php <?php // ./mt9x9.php || php mt9x9.php for($i = 1; $i <= 9; $i += 3) { for($j = 1; $j <= 9; $j++) { for($k = $i; $k <= $i+2; $k++) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } printf("\n"); } echo "\n"; } ?> PHP TCL
  25. Code to Code Code to Code #!/usr/bin/bash # ./mt9x9.sh ||

    bash mt9x9.sh for i in {1..9..3}; do for j in {1..9}; do for k in $i $((i+1)) $((i+2)); do printf '%dx%d=%2d\t' $k $j $((k*j)) done printf '\n' done echo done #!/usr/bin/bash # ./mt9x9.sh || bash mt9x9.sh for i in {1..9..3}; do for j in {1..9}; do for k in $i $((i+1)) $((i+2)); do printf '%dx%d=%2d\t' $k $j $((k*j)) done printf '\n' done echo done #!/usr/bin/fish # ./mt9x9.fish || fish mt9x9.fish for i in (seq 1 3 9) for j in (seq 9) for k in $i (math $i + 1) (math $i + 2) printf %dx%d=%2d\t $k $j (math "$k * $j") end printf \n end echo end #!/usr/bin/fish # ./mt9x9.fish || fish mt9x9.fish for i in (seq 1 3 9) for j in (seq 9) for k in $i (math $i + 1) (math $i + 2) printf %dx%d=%2d\t $k $j (math "$k * $j") end printf \n end echo end Fish BASH
  26. Code to Code Code to Code #!/usr/bin/bc -q # ./mt9x9.bc

    || bc -q mt9x9.bc for (i = 1; i <= 9; i += 3) { for (j = 1; j <= 9; j++) { for (k = i; k <= i+2; k++) { print k, "x", j, "=" if (k*j < 10) " " print k*j, "\t" } print "\n" } " " } quit #!/usr/bin/bc -q # ./mt9x9.bc || bc -q mt9x9.bc for (i = 1; i <= 9; i += 3) { for (j = 1; j <= 9; j++) { for (k = i; k <= i+2; k++) { print k, "x", j, "=" if (k*j < 10) " " print k*j, "\t" } print "\n" } " " } quit #!/usr/bin/tcsh -f # ./mt9x9.csh || tcsh -f mt9x9.csh foreach i (1 4 7) foreach j (1 2 3 4 5 6 7 8 9) foreach K (0 1 2) @ k = $i + $K echo -n "$k"x"$j"= @ s = $k * $j if ($s < 10) echo -n " " echo -n "$s\t" end echo -n "\n" end echo end #!/usr/bin/tcsh -f # ./mt9x9.csh || tcsh -f mt9x9.csh foreach i (1 4 7) foreach j (1 2 3 4 5 6 7 8 9) foreach K (0 1 2) @ k = $i + $K echo -n "$k"x"$j"= @ s = $k * $j if ($s < 10) echo -n " " echo -n "$s\t" end echo -n "\n" end echo end CSH BC
  27. Code to Code Code to Code #!/usr/bin/pwsh # ./mt9x9.ps1 ||

    pwsh mt9x9.ps1 For ($i = 1; $i -lt 10; $i += 3) { ForEach ($j in 1..9) { ForEach ($k in $i, ($i+1), ($i+2)) { Write-Host -NoNewline ("{0}x{1}={2,2}`t" -f $k, $j, ($k*$j)) } Write-Host } "" } #!/usr/bin/pwsh # ./mt9x9.ps1 || pwsh mt9x9.ps1 For ($i = 1; $i -lt 10; $i += 3) { ForEach ($j in 1..9) { ForEach ($k in $i, ($i+1), ($i+2)) { Write-Host -NoNewline ("{0}x{1}={2,2}`t" -f $k, $j, ($k*$j)) } Write-Host } "" } @echo off rem wine cmd /c mt9x9.bat setlocal enabledelayedexpansion for /l %%i in (1,3,9) do ( for /l %%j in (1,1,9) do ( for /l %%K in (0,1,2) do ( set /a k=%%i+%%K set /a s=!k!*%%j <nul set/p"=!k!x%%j=" if !s! lss 10 (<nul set/p"= ") <nul set/p"=!s! " ) echo. ) echo. ) endlocal @echo off rem wine cmd /c mt9x9.bat setlocal enabledelayedexpansion for /l %%i in (1,3,9) do ( for /l %%j in (1,1,9) do ( for /l %%K in (0,1,2) do ( set /a k=%%i+%%K set /a s=!k!*%%j <nul set/p"=!k!x%%j=" if !s! lss 10 (<nul set/p"= ") <nul set/p"=!s! " ) echo. ) echo. ) endlocal Batch PowerShell
  28. Code to Code Code to Code #!/usr/bin/awk -f # ./mt9x9.awk

    || awk -f mt9x9.awk BEGIN { for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j) printf "\n" } print } } #!/usr/bin/awk -f # ./mt9x9.awk || awk -f mt9x9.awk BEGIN { for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k = i; k <= i+2; k++) printf("%dx%d=%2d\t", k, j, k*j) printf "\n" } print } } AWK #!/usr/bin/make -sf # ./mt9x9.mk || make -sf mt9x9.mk include gmsl $(foreach i, 1 4 7, \ $(foreach j, $(call sequence,1,9), \ $(eval str=) \ $(foreach k, $i $(call plus,$i,1) $(call plus,$i,2), \ $(eval n=$(call multiply,$k,$j)) \ $(eval str=${str} $kx$j=$(if $(call lt,$n,10), ,)$n) \ ) \ $(info ${str}) \ ) \ $(info ) \ ) all: #!/usr/bin/make -sf # ./mt9x9.mk || make -sf mt9x9.mk include gmsl $(foreach i, 1 4 7, \ $(foreach j, $(call sequence,1,9), \ $(eval str=) \ $(foreach k, $i $(call plus,$i,1) $(call plus,$i,2), \ $(eval n=$(call multiply,$k,$j)) \ $(eval str=${str} $kx$j=$(if $(call lt,$n,10), ,)$n) \ ) \ $(info ${str}) \ ) \ $(info ) \ ) all: Make
  29. Code to Code Code to Code // swiftc mt9x9.swift &&

    ./mt9x9 || swift mt9x9.swift import Foundation for i in stride(from: 1, to: 9, by: 3) { for j in 1...9 { for k in [i, i+1, i+2] { print(String(format:"%dx%d=%2d", k, j, k*j), terminator:"\t") } print() } print() } // swiftc mt9x9.swift && ./mt9x9 || swift mt9x9.swift import Foundation for i in stride(from: 1, to: 9, by: 3) { for j in 1...9 { for k in [i, i+1, i+2] { print(String(format:"%dx%d=%2d", k, j, k*j), terminator:"\t") } print() } print() } // go build mt9x9.go && ./mt9x9 || go run mt9x9.go package main import "fmt" func main() { for i := 1; i <= 9; i += 3 { for j := 1; j <= 9; j++ { for _, k := range []int{i, i+1, i+2} { fmt.Printf("%dx%d=%2d\t", k, j, k*j) } fmt.Printf("\n") } println() } } // go build mt9x9.go && ./mt9x9 || go run mt9x9.go package main import "fmt" func main() { for i := 1; i <= 9; i += 3 { for j := 1; j <= 9; j++ { for _, k := range []int{i, i+1, i+2} { fmt.Printf("%dx%d=%2d\t", k, j, k*j) } fmt.Printf("\n") } println() } } Go Swift
  30. Code to Code Code to Code % picat mt9x9.pi main

    => foreach(I in 1..9, I mod 3 == 1) foreach(J in 1..9) foreach(K in [I, I+1, I+2]) writef("%dx%d=%2d\t", K, J, K*J) end, writef("\n") end, print("\n") end. % picat mt9x9.pi main => foreach(I in 1..9, I mod 3 == 1) foreach(J in 1..9) foreach(K in [I, I+1, I+2]) writef("%dx%d=%2d\t", K, J, K*J) end, writef("\n") end, print("\n") end. // ./mt9x9.zkl || zkl mt9x9.zkl foreach i in ([1..9, 3]) { foreach j in (Utils.range(1, 9)) { foreach k in (L(i, i+1, i+2)) { print(k, "x", j, "=", "%2d".fmt(k*j), "\t"); } print("\n"); } println(); } // ./mt9x9.zkl || zkl mt9x9.zkl foreach i in ([1..9, 3]) { foreach j in (Utils.range(1, 9)) { foreach k in (L(i, i+1, i+2)) { print(k, "x", j, "=", "%2d".fmt(k*j), "\t"); } print("\n"); } println(); } ZKL Picat
  31. Code to Code Code to Code // umka mt9x9.um fn

    main() { for i := 1; i <= 9; i += 3 { for j := 1; j <= 9; j++ { for k in [3]int{i, i+1, i+2} { printf("%dx%d=%2d\t", k, j, k*j) } printf("\n") } printf("\n") } } // umka mt9x9.um fn main() { for i := 1; i <= 9; i += 3 { for j := 1; j <= 9; j++ { for k in [3]int{i, i+1, i+2} { printf("%dx%d=%2d\t", k, j, k*j) } printf("\n") } printf("\n") } } #!/usr/bin/phix -- phix mt9x9.ex for i = 1 to 9 by 3 do for j = 1 to 9 do for k = i to i+2 do printf(1, "%dx%d=%2d\t", {k,j,k*j}) end for puts(1, "\n") end for puts(1, "\n") end for #!/usr/bin/phix -- phix mt9x9.ex for i = 1 to 9 by 3 do for j = 1 to 9 do for k = i to i+2 do printf(1, "%dx%d=%2d\t", {k,j,k*j}) end for puts(1, "\n") end for puts(1, "\n") end for Euphoria Umka
  32. Code to Code Code to Code // haxe --main Mt9x9

    --interp class Mt9x9 { static function main() { for (i in [1, 4, 7]) { for (j in 1...10) { for (k in [i, i+1, i+2]) { Sys.print(k+'x'+j+'='+(k*j<10?' ':'')+k*j+'\t'); } Sys.print('\n'); } Sys.println(''); } } } // haxe --main Mt9x9 --interp class Mt9x9 { static function main() { for (i in [1, 4, 7]) { for (j in 1...10) { for (k in [i, i+1, i+2]) { Sys.print(k+'x'+j+'='+(k*j<10?' ':'')+k*j+'\t'); } Sys.print('\n'); } Sys.println(''); } } } // nekoc mt9x9.neko && neko mt9x9.n var sprintf = $loader.loadprim("std@sprintf", 2); var i = 1; while i <= 9 { var j = 1; while j <= 9 { var k = i; while k <= i+2 { $print(k, "x", j, "=", sprintf("%2d", k*j), "\t"); k += 1; } $print("\n"); j += 1; } $print("\n"); i += 3; } // nekoc mt9x9.neko && neko mt9x9.n var sprintf = $loader.loadprim("std@sprintf", 2); var i = 1; while i <= 9 { var j = 1; while j <= 9 { var k = i; while k <= i+2 { $print(k, "x", j, "=", sprintf("%2d", k*j), "\t"); k += 1; } $print("\n"); j += 1; } $print("\n"); i += 3; } Neko Haxe
  33. Code to Code Code to Code // ponyc -b mt9x9

    && ./mt9x9 use "collections" use "format" actor Main new create(env: Env) => for i in Range[U8](1, 10, 3) do for j in Range[U8](1, 10) do for k in [i; i+1; i+2].values() do env.out.write(k.string() + "x" + j.string() + "=" + Format.int[U8](k*j where width=2) + "\t") end env.out.write("\n") end env.out.print("") end // ponyc -b mt9x9 && ./mt9x9 use "collections" use "format" actor Main new create(env: Env) => for i in Range[U8](1, 10, 3) do for j in Range[U8](1, 10) do for k in [i; i+1; i+2].values() do env.out.write(k.string() + "x" + j.string() + "=" + Format.int[U8](k*j where width=2) + "\t") end env.out.write("\n") end env.out.print("") end # objeckc -src mt9x9.obs -dest mt9x9.obe && objeckr mt9x9.obe class mt9x9 { function : Main(args : String[]) ~ Nil { for(i := 1; i <= 9; i += 3;) { for(j := 1; j <= 9; j += 1;) { for(k := i; k <= i+2; k++;) { IO.Console->Print(k)->Print('x')->Print(j)->Print('='); if(k*j<10) {IO.Console->Print(' ');}; IO.Console->Print(k*j)->Print('\t'); }; '\n'->Print(); }; ""->PrintLine(); }; } } # objeckc -src mt9x9.obs -dest mt9x9.obe && objeckr mt9x9.obe class mt9x9 { function : Main(args : String[]) ~ Nil { for(i := 1; i <= 9; i += 3;) { for(j := 1; j <= 9; j += 1;) { for(k := i; k <= i+2; k++;) { IO.Console->Print(k)->Print('x')->Print(j)->Print('='); if(k*j<10) {IO.Console->Print(' ');}; IO.Console->Print(k*j)->Print('\t'); }; '\n'->Print(); }; ""->PrintLine(); }; } } Objeck Pony
  34. Code to Code Code to Code #!/usr/bin/nit # nitc mt9x9.nit

    && ./mt9x9 || ./mt9x9.nit || nit mt9x9.nit for i in [1..10[.step(3) do for j in [1..9] do for k in [i, i+1, i+2] do printn "{k}x{j}=" if k*j < 10 then printn " " end printn "{k*j}\t" end printn "\n" end print "" end #!/usr/bin/nit # nitc mt9x9.nit && ./mt9x9 || ./mt9x9.nit || nit mt9x9.nit for i in [1..10[.step(3) do for j in [1..9] do for k in [i, i+1, i+2] do printn "{k}x{j}=" if k*j < 10 then printn " " end printn "{k*j}\t" end printn "\n" end print "" end # nim compile mt9x9.nim && ./mt9x9 import strformat for i in countup(1, 9, 3): for j in 1..9: for k in [i, i+1, i+2]: write(stdout, k, 'x', j, '=', &"{k*j:2d}", '\t') writeLine(stdout, "") echo() # nim compile mt9x9.nim && ./mt9x9 import strformat for i in countup(1, 9, 3): for j in 1..9: for k in [i, i+1, i+2]: write(stdout, k, 'x', j, '=', &"{k*j:2d}", '\t') writeLine(stdout, "") echo() Nim Nit
  35. Code to Code Code to Code #!/usr/bin/ruby # ./mt9x9.rb ||

    ruby mt9x9.rb for i in (1..9).step(3) for j in (1..9) [i, i+1, i+2].each{|k| print "%dx%d=%2d\t" % [k, j, k*j] } print "\n" end puts end #!/usr/bin/ruby # ./mt9x9.rb || ruby mt9x9.rb for i in (1..9).step(3) for j in (1..9) [i, i+1, i+2].each{|k| print "%dx%d=%2d\t" % [k, j, k*j] } print "\n" end puts end // rustc mt9x9.rs && ./mt9x9 fn main() { for i in (1..10).step_by(3) { for j in 1..10 { for k in &[i, i+1, i+2] { print!("{}x{}={:2}\t", k, j, k*j); } print!("\n"); } println!(); } } // rustc mt9x9.rs && ./mt9x9 fn main() { for i in (1..10).step_by(3) { for j in 1..10 { for k in &[i, i+1, i+2] { print!("{}x{}={:2}\t", k, j, k*j); } print!("\n"); } println!(); } } Rust Ruby
  36. Code to Code Code to Code #!/usr/bin/scsh -s !# ;

    ./mt9x9.scsh || scsh -s mt9x9.scsh (for-each (lambda (i) (for-each (lambda (j) (for-each (lambda (k) (format #t "~Dx~D=" k j) (if (< (* k j) 10) (format #t " ")) (format #t "~D~A" (* k j) #\tab)) (list i (+ i 1) (+ i 2))) (display #\newline)) (map (lambda (x) (+ 1 x)) (iota 9))) (newline)) '(1 4 7)) #!/usr/bin/scsh -s !# ; ./mt9x9.scsh || scsh -s mt9x9.scsh (for-each (lambda (i) (for-each (lambda (j) (for-each (lambda (k) (format #t "~Dx~D=" k j) (if (< (* k j) 10) (format #t " ")) (format #t "~D~A" (* k j) #\tab)) (list i (+ i 1) (+ i 2))) (display #\newline)) (map (lambda (x) (+ 1 x)) (iota 9))) (newline)) '(1 4 7)) #!/usr/bin/txr -f ;; ./mt9x9.tl || ./txr -f mt9x9.txr (each ((i (range 1 9 3))) (each ((j (range 1 9))) (each ((k (list i (+ i 1) (+ i 2)))) (format t "~ax~a=~2a\t" k j (* k j)) ) (put-string "\n") ) (put-line) ) #!/usr/bin/txr -f ;; ./mt9x9.tl || ./txr -f mt9x9.txr (each ((i (range 1 9 3))) (each ((j (range 1 9))) (each ((k (list i (+ i 1) (+ i 2)))) (format t "~ax~a=~2a\t" k j (* k j)) ) (put-string "\n") ) (put-line) ) TXR Lisp SCSH
  37. Code to Code Code to Code #!/usr/bin/guile -s !# ;

    ./mt9x9.scm || guile mt9x9.scm (use-modules (ice-9 format)) (for-each (lambda (i) (for-each (lambda (j) (for-each (lambda (k) (format #t "~dx~d=~2d~c" k j (* k j) #\tab)) (list i (+ i 1) (+ i 2))) (display #\newline)) (map 1+ (iota 9))) (newline)) '(1 4 7)) #!/usr/bin/guile -s !# ; ./mt9x9.scm || guile mt9x9.scm (use-modules (ice-9 format)) (for-each (lambda (i) (for-each (lambda (j) (for-each (lambda (k) (format #t "~dx~d=~2d~c" k j (* k j) #\tab)) (list i (+ i 1) (+ i 2))) (display #\newline)) (map 1+ (iota 9))) (newline)) '(1 4 7)) #!/usr/bin/gcl -f ; ./mt9x9.lisp || gcl -f mt9x9.lisp (dolist (i '(1 4 7)) (dolist (j '(1 2 3 4 5 6 7 8 9)) (dolist (k (list i (+ i 1) (+ i 2))) (format t "~Dx~D=~2D ~@T" k j (* k j)) ) (format t "~%") ) (terpri) ) #!/usr/bin/gcl -f ; ./mt9x9.lisp || gcl -f mt9x9.lisp (dolist (i '(1 4 7)) (dolist (j '(1 2 3 4 5 6 7 8 9)) (dolist (k (list i (+ i 1) (+ i 2))) (format t "~Dx~D=~2D ~@T" k j (* k j)) ) (format t "~%") ) (terpri) ) CommonLisp Scheme
  38. Code to Code Code to Code #!/usr/bin/janet # ./mt9x9.janet ||

    janet mt9x9.janet (loop [i :range [1 9] :when (zero? (% (- i 1) 3))] (for j 1 10 (each k [i (+ i 1) (+ i 2)] (prin k "x" j "=" (string/format "%2d" (* k j)) "\t") ) (print) ) (print) ) #!/usr/bin/janet # ./mt9x9.janet || janet mt9x9.janet (loop [i :range [1 9] :when (zero? (% (- i 1) 3))] (for j 1 10 (each k [i (+ i 1) (+ i 2)] (prin k "x" j "=" (string/format "%2d" (* k j)) "\t") ) (print) ) (print) ) #!/usr/bin/clojure ;; ./mt9x9.clj || clojure mt9x9.clj (doseq [i (range 1 10 3) j (range 1 10) k [i (+ i 1) (+ i 2)]] (printf "%dx%d=%2d" k j (* k j)) (print (if (not= k (+ i 2)) "\t" (if (= j 9) "\n\n" "\n"))) ) #!/usr/bin/clojure ;; ./mt9x9.clj || clojure mt9x9.clj (doseq [i (range 1 10 3) j (range 1 10) k [i (+ i 1) (+ i 2)]] (printf "%dx%d=%2d" k j (* k j)) (print (if (not= k (+ i 2)) "\t" (if (= j 9) "\n\n" "\n"))) ) Clojure Janet
  39. Code to Code Code to Code #!/usr/bin/racket ; ./mt9x9.rkt ||

    racket mt9x9.rkt #lang racket (for ([i (in-range 1 10 3)]) (for ([j (in-range 1 10)]) (for ([k (list i (+ i 1) (+ i 2))]) (printf "~ax~a=" k j) (display (~a (* k j) #:width 2 #:align 'right)) (printf "\t") ) (displayln "") ) (newline) ) #!/usr/bin/racket ; ./mt9x9.rkt || racket mt9x9.rkt #lang racket (for ([i (in-range 1 10 3)]) (for ([j (in-range 1 10)]) (for ([k (list i (+ i 1) (+ i 2))]) (printf "~ax~a=" k j) (display (~a (* k j) #:width 2 #:align 'right)) (printf "\t") ) (displayln "") ) (newline) ) #!/usr/bin/es ;; ./mt9x9.esl || es mt9x9.esl (for i in (1 10 3) (for j in (1 10) (for k in (@ i (i + 1) (+ i 2)) (printf '$(k)x$(j)=') (if ((k * j) < 10) (printf " ")) (printf '$(k * j)\t') ) (printf "\n") ) (print) ) #!/usr/bin/es ;; ./mt9x9.esl || es mt9x9.esl (for i in (1 10 3) (for j in (1 10) (for k in (@ i (i + 1) (+ i 2)) (printf '$(k)x$(j)=') (if ((k * j) < 10) (printf " ")) (printf '$(k * j)\t') ) (printf "\n") ) (print) ) ESlang Racket
  40. Code to Code Code to Code #! /usr/bin/gforth \ ./mt9x9.fth

    || gforth mt9x9.fth : mt9x9 10 1 do 10 1 do 3 0 do i k + 1 u.r 120 emit j 1 u.r 61 emit i k + j * 2 u.r 9 emit loop 10 emit loop cr 3 +loop ; mt9x9 bye #! /usr/bin/gforth \ ./mt9x9.fth || gforth mt9x9.fth : mt9x9 10 1 do 10 1 do 3 0 do i k + 1 u.r 120 emit j 1 u.r 61 emit i k + j * 2 u.r 9 emit loop 10 emit loop cr 3 +loop ; mt9x9 bye % gs -q -dNODISPLAY -dBATCH mt9x9.ps 1 3 9 { /i exch def 1 1 9 { /j exch def i 1 i 2 add { /k exch def k 1 string cvs print (x) print j 1 string cvs print (=) print k j mul dup 10 lt { ( ) print } if 2 string cvs print (\t) print } for (\n) print } for () = } for % gs -q -dNODISPLAY -dBATCH mt9x9.ps 1 3 9 { /i exch def 1 1 9 { /j exch def i 1 i 2 add { /k exch def k 1 string cvs print (x) print j 1 string cvs print (=) print k j mul dup 10 lt { ( ) print } if 2 string cvs print (\t) print } for (\n) print } for () = } for PostScript Forth
  41. Code to Code Code to Code #!/usr/bin/thune ; ./mt9x9.t ||

    thune mt9x9.t 1 :i [ 1 :j [ i :k [ k prin 'x' prin j prin '=' prin 10 k j mul gt? ift (' ' prin) k j mul prin '^-' prin k inc :k ] 3 loop '^/' prin j inc :j ] 9 loop '^/' prin 3 i add :i ] 3 loop #!/usr/bin/thune ; ./mt9x9.t || thune mt9x9.t 1 :i [ 1 :j [ i :k [ k prin 'x' prin j prin '=' prin 10 k j mul gt? ift (' ' prin) k j mul prin '^-' prin k inc :k ] 3 loop '^/' prin j inc :j ] 9 loop '^/' prin 3 i add :i ] 3 loop #!/usr/bin/gst " ./mt9x9.st || gst mt9x9.st " 1 to: 9 by: 3 do: [ :i | 1 to: 9 do: [ :j | i to: i+2 do: [ :k | Transcript show: k printString, 'x', j printString, '='. k*j < 10 ifTrue: [Transcript show: ' ']. Transcript show: (k*j) printString. Character tab display ]. Character nl display ]. Transcript cr ]. #!/usr/bin/gst " ./mt9x9.st || gst mt9x9.st " 1 to: 9 by: 3 do: [ :i | 1 to: 9 do: [ :j | i to: i+2 do: [ :k | Transcript show: k printString, 'x', j printString, '='. k*j < 10 ifTrue: [Transcript show: ' ']. Transcript show: (k*j) printString. Character tab display ]. Character nl display ]. Transcript cr ]. Smalltalk Thune
  42. Code to Code Code to Code -- ghc mt9x9.hs &&

    ./mt9x9 || runghc mt9x9.hs import Control.Monad main = do forM_ [1,4..9] $ \i -> do forM_ [1..9] $ \j -> do forM_ [i, i+1, i+2] $ \k -> do putStr (show k ++ "x" ++ show j ++ "=" ++ (if (k*j) < 10 then " " else "") ++ show (k*j) ++ "\t") putStrLn "" putChar '\n' -- ghc mt9x9.hs && ./mt9x9 || runghc mt9x9.hs import Control.Monad main = do forM_ [1,4..9] $ \i -> do forM_ [1..9] $ \j -> do forM_ [i, i+1, i+2] $ \k -> do putStr (show k ++ "x" ++ show j ++ "=" ++ (if (k*j) < 10 then " " else "") ++ show (k*j) ++ "\t") putStrLn "" putChar '\n' #!/usr/bin/elixir # ./mt9x9.exs || elixir mt9x9.exs Enum.each(Stream.take_every(1..9, 3), fn i -> Enum.each(Enum.sort(1..9), fn j -> Enum.each([i, i+1, i+2], fn k -> IO.write "#{k}x#{j}=” IO.write ‘#{String.pad_leading(to_string(k*j),2)}\t" end) IO.write "\n" end) IO.puts "" end) #!/usr/bin/elixir # ./mt9x9.exs || elixir mt9x9.exs Enum.each(Stream.take_every(1..9, 3), fn i -> Enum.each(Enum.sort(1..9), fn j -> Enum.each([i, i+1, i+2], fn k -> IO.write "#{k}x#{j}=” IO.write ‘#{String.pad_leading(to_string(k*j),2)}\t" end) IO.write "\n" end) IO.puts "" end) Elixir Haskell
  43. Code to Code Code to Code % erlc mt9x9.erl &&

    erl -noshell -s mt9x9 start -s init stop -module(mt9x9). -export([start/0]). start() -> [block(I) || I <- lists:seq(1, 9, 3)]. block(I) -> [line(I, J) || J <- lists:seq(1, 9)], io:fwrite("~n"). line(I, J) -> [io:format("~Bx~B=~2B\t", [K, J, K*J]) || K <- lists:seq(I, I+2)], io:nl(). % erlc mt9x9.erl && erl -noshell -s mt9x9 start -s init stop -module(mt9x9). -export([start/0]). start() -> [block(I) || I <- lists:seq(1, 9, 3)]. block(I) -> [line(I, J) || J <- lists:seq(1, 9)], io:fwrite("~n"). line(I, J) -> [io:format("~Bx~B=~2B\t", [K, J, K*J]) || K <- lists:seq(I, I+2)], io:nl(). #!/usr/bin/escript % ./mt9x9.es || escript mt9x9.es main(_) -> [block(I) || I <- lists:seq(1, 9, 3)]. block(I) -> [line(I, J) || J <- lists:seq(1, 9)], io:fwrite("~n"). line(I, J) -> [io:format("~Bx~B=~2B\t", [K, J, K*J]) || K <- lists:seq(I, I+2)], io:nl(). #!/usr/bin/escript % ./mt9x9.es || escript mt9x9.es main(_) -> [block(I) || I <- lists:seq(1, 9, 3)]. block(I) -> [line(I, J) || J <- lists:seq(1, 9)], io:fwrite("~n"). line(I, J) -> [io:format("~Bx~B=~2B\t", [K, J, K*J]) || K <- lists:seq(I, I+2)], io:nl(). EScript Erlang
  44. Code to Code Code to Code // patscc mt9x9.dats -o

    mt9x9 && ./mt9x9 #include "share/atspre_staload.hats" implement main0() = block(1) where { fun item(i: int, j: int, k: int): void = if k <= i+2 then ( print!(k, "x", j, "=", (if k*j < 10 then " " else ""): string, k*j, "\t"); item(i, j, k+1) ) fun line(i: int, j: int): void = if j <= 9 then ( item(i, j, i); print("\n"); line(i, j+1) ) fun block(i: int): void = if i <= 9 then ( line(i, 1); print_newline(); block(i+3) ) } // patscc mt9x9.dats -o mt9x9 && ./mt9x9 #include "share/atspre_staload.hats" implement main0() = block(1) where { fun item(i: int, j: int, k: int): void = if k <= i+2 then ( print!(k, "x", j, "=", (if k*j < 10 then " " else ""): string, k*j, "\t"); item(i, j, k+1) ) fun line(i: int, j: int): void = if j <= 9 then ( item(i, j, i); print("\n"); line(i, j+1) ) fun block(i: int): void = if i <= 9 then ( line(i, 1); print_newline(); block(i+3) ) } #!/usr/bin/miranda -exec || ./mt9x9.mira || miranda -exec mt9x9.mira main = concat (map block [1, 4, 7]) where block i = concat (map line [1..9]) ++ "\n" where line j = concat (map item [i..i+2]) ++ "\n" where item k = shownum k ++ "x" ++ shownum j ++ "=" ++ rjustify 2 (shownum (k*j)) ++ "\t" #!/usr/bin/miranda -exec || ./mt9x9.mira || miranda -exec mt9x9.mira main = concat (map block [1, 4, 7]) where block i = concat (map line [1..9]) ++ "\n" where line j = concat (map item [i..i+2]) ++ "\n" where item k = shownum k ++ "x" ++ shownum j ++ "=" ++ rjustify 2 (shownum (k*j)) ++ "\t" Miranda ATS
  45. Code to Code Code to Code #!/usr/bin/io // ./mt9x9.io ||

    io mt9x9.io for(i, 1, 9, 3, for(j, 1, 9, list(i, i+1, i+2) foreach(k, write(k, "x", j, "=", if(k*j<10," ",""), k*j, "\t") ) "" println ) writeln ) #!/usr/bin/io // ./mt9x9.io || io mt9x9.io for(i, 1, 9, 3, for(j, 1, 9, list(i, i+1, i+2) foreach(k, write(k, "x", j, "=", if(k*j<10," ",""), k*j, "\t") ) "" println ) writeln ) #!/usr/bin/icon # ./mt9x9.icn || icon mt9x9.icn # || iconc mt9x9.icn && ./mt9x9 procedure main() local i, j, k every i := 1 to 9 by 3 do { every j := 1 to 9 do { every k := ![i, i+1, i+2] do writes(k, "x", j, "=", right(k*j,2), "\t") writes("\n") } write() } end #!/usr/bin/icon # ./mt9x9.icn || icon mt9x9.icn # || iconc mt9x9.icn && ./mt9x9 procedure main() local i, j, k every i := 1 to 9 by 3 do { every j := 1 to 9 do { every k := ![i, i+1, i+2] do writes(k, "x", j, "=", right(k*j,2), "\t") writes("\n") } write() } end Icon Io
  46. Code to Code Code to Code // gravity mt9x9.gravity func

    main() { for (var i in [1, 4, 7]) { for (var j in 1...9) { for (var k in i...i+2) { System.put(k, "x", j, "=") if (k*j < 10) System.put(" ") System.put(k*j, "\t") } System.put("\n") } System.print() } System.exit(0) } // gravity mt9x9.gravity func main() { for (var i in [1, 4, 7]) { for (var j in 1...9) { for (var k in i...i+2) { System.put(k, "x", j, "=") if (k*j < 10) System.put(" ") System.put(k*j, "\t") } System.put("\n") } System.print() } System.exit(0) } #!/usr/bin/wren // ./mt9x9.wren || wren mt9x9.wren for (i in (1...10).where {|n| n % 3 == 1 }) { for (j in 1..9) { [i, i+1, i+2].each {|k| System.write("%(k)x%(j)=%(k*j<10?" ":"")%(k*j)\t") } System.write("\n") } System.print() } #!/usr/bin/wren // ./mt9x9.wren || wren mt9x9.wren for (i in (1...10).where {|n| n % 3 == 1 }) { for (j in 1..9) { [i, i+1, i+2].each {|k| System.write("%(k)x%(j)=%(k*j<10?" ":"")%(k*j)\t") } System.write("\n") } System.print() } Wren Gravity
  47. Code to Code Code to Code #!/usr/bin/falcon -M // ./mt9x9.fal

    || falcon mt9x9.fal for i in [1:9:3] for j = 1 to 9 for k in [i, i+1, i+2] s = k*j >> @"$(k)x$(j)=$(s:2r)\t" end printl() end > end #!/usr/bin/falcon -M // ./mt9x9.fal || falcon mt9x9.fal for i in [1:9:3] for j = 1 to 9 for k in [i, i+1, i+2] s = k*j >> @"$(k)x$(j)=$(s:2r)\t" end printl() end > end // flaxc mt9x9.flx && ./mt9x9 || flaxc -run mt9x9.flx import libc as _ import std::io as _ @entry fn main() { for i in [1, 4, 7] { for j in 1...9 { for k in i...i+2 step 1 => printf("%dx%d=%2d\t", k, j, k*j) printf("\n") } println() } } // flaxc mt9x9.flx && ./mt9x9 || flaxc -run mt9x9.flx import libc as _ import std::io as _ @entry fn main() { for i in [1, 4, 7] { for j in 1...9 { for k in i...i+2 step 1 => printf("%dx%d=%2d\t", k, j, k*j) printf("\n") } println() } } Flax Falcon
  48. Code to Code Code to Code -- sqlite3 < mt9x9.sql

    .mode tabs CREATE TABLE t(j INT, i INT); WITH RECURSIVE for(j) AS (VALUES(1) UNION ALL SELECT j+1 FROM for WHERE j < 9) INSERT INTO t SELECT j, 1 FROM for; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; UPDATE t SET i = i + 3; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; UPDATE t SET i = i + 3; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; -- sqlite3 < mt9x9.sql .mode tabs CREATE TABLE t(j INT, i INT); WITH RECURSIVE for(j) AS (VALUES(1) UNION ALL SELECT j+1 FROM for WHERE j < 9) INSERT INTO t SELECT j, 1 FROM for; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; UPDATE t SET i = i + 3; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; UPDATE t SET i = i + 3; SELECT i||'x'||j||'='||SUBSTR(' '||(i*j),-2,2), (i+1)||'x'||j||'='||SUBSTR(' '||((i+1)*j),-2,2), (i+2)||'x'||j||'='||SUBSTR(' '||((i+2)*j),-2,2) FROM t; SELECT ''; #!/usr/bin/hbrun * ./mt9x9.prg || hbrun mt9x9.prg local i, j, k for i := 1 to 9 step 3 for j := 1 to 9 for each k in {i, i+1, i+2} ?? str(k, 1) + "x" + str(j, 1) + "=" + str(k*j, 2) + chr(9) next ?? chr(10) next ? next #!/usr/bin/hbrun * ./mt9x9.prg || hbrun mt9x9.prg local i, j, k for i := 1 to 9 step 3 for j := 1 to 9 for each k in {i, i+1, i+2} ?? str(k, 1) + "x" + str(j, 1) + "=" + str(k*j, 2) + chr(9) next ?? chr(10) next ? next xBASE SQL
  49. Code to Code Code to Code #!/usr/bin/ijconsole NB. ./mt9x9.ijs ||

    ijconsole mt9x9.ijs 3 : 0 '' for_i. 1 + 3 * i. 3 do. for_j. 1 + i. 9 do. s =: '' for_k. i + i. 3 do. s =: s, (":k), 'x', (":j), '=', (>'2.0' 8!:0 k*j), TAB end. smoutput s end. smoutput '' end. ) exit 0 #!/usr/bin/ijconsole NB. ./mt9x9.ijs || ijconsole mt9x9.ijs 3 : 0 '' for_i. 1 + 3 * i. 3 do. for_j. 1 + i. 9 do. s =: '' for_k. i + i. 3 do. s =: s, (":k), 'x', (":j), '=', (>'2.0' 8!:0 k*j), TAB end. smoutput s end. smoutput '' end. ) exit 0 #!/usr/bin/dc [ ./mt9x9.dc || dc mt9x9.dc ]sz [32 P]sS [ lk n [x] P lj n [=] P lk lj * d 9 !<S n 9 P lk 1 + d sk li 2 + !<K ]sK [ li d sk lK x 10 P lj 1 + d sj 9 !<J ]sJ [ 1 d sj lJ x 10 P li 3 + d si 9 !<I ]sI 1 d si lI x #!/usr/bin/dc [ ./mt9x9.dc || dc mt9x9.dc ]sz [32 P]sS [ lk n [x] P lj n [=] P lk lj * d 9 !<S n 9 P lk 1 + d sk li 2 + !<K ]sK [ li d sk lK x 10 P lj 1 + d sj 9 !<J ]sJ [ 1 d sj lJ x 10 P li 3 + d si 9 !<I ]sI 1 d si lI x DC J
  50. Code to Code Code to Code #!/usr/bin/Rscript # ./mt9x9.R ||

    Rscript mt9x9.R for(i in seq(1, 9, 3)) { for(j in 1:9) { for(k in list(i, i+1, i+2)) { cat(sprintf("%dx%d=%2d\t", k, j, k*j)) } cat("\n") } cat("\n") } #!/usr/bin/Rscript # ./mt9x9.R || Rscript mt9x9.R for(i in seq(1, 9, 3)) { for(j in 1:9) { for(k in list(i, i+1, i+2)) { cat(sprintf("%dx%d=%2d\t", k, j, k*j)) } cat("\n") } cat("\n") } % octave mt9x9.m for i = (1:3:9) for j = (1:9) for k = [i, i+1, i+2] fprintf('%dx%d=%2d\t', k, j, k*j); end fprintf('\n'); end disp(''); end % octave mt9x9.m for i = (1:3:9) for j = (1:9) for k = [i, i+1, i+2] fprintf('%dx%d=%2d\t', k, j, k*j); end fprintf('\n'); end disp(''); end MATLAB R
  51. Code to Code Code to Code #!/usr/bin/gnuplot # ./mt9x9.plt ||

    gnuplot mt9x9.plt s = "" do for [i = 1:9:3] for [j = 1:9] for [k = i:i+2] { s = s.sprintf('%dx%d=%2d', k, j, k*j) if (k != i+2) {s = s."\t"} else { if (j == 9) {print s."\n"} else {print s} s = "" } } #!/usr/bin/gnuplot # ./mt9x9.plt || gnuplot mt9x9.plt s = "" do for [i = 1:9:3] for [j = 1:9] for [k = i:i+2] { s = s.sprintf('%dx%d=%2d', k, j, k*j) if (k != i+2) {s = s."\t"} else { if (j == 9) {print s."\n"} else {print s} s = "" } } /* maxima --very-quiet < mt9x9.mac */ ttyoff: true; for i: 1 step 3 thru 9 do ( for j: 1 thru 9 do ( for k in [i, i+1, i+2] do ( printf(true, "~dx~d=~2d~a", k, j, k*j, tab) ), printf(true, "~%") ), newline() ); /* maxima --very-quiet < mt9x9.mac */ ttyoff: true; for i: 1 step 3 thru 9 do ( for j: 1 thru 9 do ( for k in [i, i+1, i+2] do ( printf(true, "~dx~d=~2d~a", k, j, k*j, tab) ), printf(true, "~%") ), newline() ); Maxima Gnuplot
  52. Code to Code Code to Code ; gdl -q -e

    mt9x9 pro mt9x9 for i = 1, 9, 3 do begin for j = 1, 9 do begin for k = i, i+2 do begin print, k,"x",j,"=",k*j,string(9b), $ format='($,I1,A,I1,A,I2,A)' endfor print, string(10b), format='($,A)' endfor print endfor end ; gdl -q -e mt9x9 pro mt9x9 for i = 1, 9, 3 do begin for j = 1, 9 do begin for k = i, i+2 do begin print, k,"x",j,"=",k*j,string(9b), $ format='($,I1,A,I1,A,I2,A)' endfor print, string(10b), format='($,A)' endfor print endfor end #!/usr/bin/julia # ./mt9x9.jl || julia mt9x9.jl using Printf for i in 1:3:9, j = 1:9, k = [i, i+1, i+2] @printf("%dx%d=%2d", k, j, k*j) print(k!=i+2 ? "\t" : j==9 ? "\n\n" : "\n") end #!/usr/bin/julia # ./mt9x9.jl || julia mt9x9.jl using Printf for i in 1:3:9, j = 1:9, k = [i, i+1, i+2] @printf("%dx%d=%2d", k, j, k*j) print(k!=i+2 ? "\t" : j==9 ? "\n\n" : "\n") end Julia IDL
  53. Code to Code Code to Code // iverilog mt9x9.v -o

    mt9x9 && ./mt9x9 module mt9x9; integer i, j, k; initial begin for(i = 1; i <= 9; i += 3) begin for(j = 1; j <= 9; j++) begin for(k = i; k <= i+2; k++) begin $write("%0dx%0d=%2d\t", k, j, k*j); end $write("\n"); end $display(); end end endmodule // iverilog mt9x9.v -o mt9x9 && ./mt9x9 module mt9x9; integer i, j, k; initial begin for(i = 1; i <= 9; i += 3) begin for(j = 1; j <= 9; j++) begin for(k = i; k <= i+2; k++) begin $write("%0dx%0d=%2d\t", k, j, k*j); end $write("\n"); end $display(); end end endmodule -- ghdl -c mt9x9.vhd -e mt9x9 && ./mt9x9 LIBRARY std; USE std.TEXTIO.all; entity mt9x9 is end mt9x9; architecture mt9x9 of mt9x9 is begin process variable i, j, k: integer; variable s: line; begin for i in 1 to 9 loop next when i mod 3 /= 1; for j in 1 to 9 loop for k in i to i+2 loop write(s, k); write(s, 'x'); write(s, j); write(s, '='); write(s, k*j, right, 2); write(s, character'val(9)); end loop; writeline(OUTPUT, s); end loop; write(s, character'val(0)); writeline(OUTPUT, s); end loop; wait; end process; end mt9x9; -- ghdl -c mt9x9.vhd -e mt9x9 && ./mt9x9 LIBRARY std; USE std.TEXTIO.all; entity mt9x9 is end mt9x9; architecture mt9x9 of mt9x9 is begin process variable i, j, k: integer; variable s: line; begin for i in 1 to 9 loop next when i mod 3 /= 1; for j in 1 to 9 loop for k in i to i+2 loop write(s, k); write(s, 'x'); write(s, j); write(s, '='); write(s, k*j, right, 2); write(s, character'val(9)); end loop; writeline(OUTPUT, s); end loop; write(s, character'val(0)); writeline(OUTPUT, s); end loop; wait; end process; end mt9x9; VHDL Verilog
  54. Code to Code Code to Code #!/usr/bin/s7 # s7c mt9x9.sd7

    && ./mt9x9 || s7 mt9x9.sd7 || ./mt9x9.sd7 $ include "seed7_05.s7i"; const proc: main is func local var integer: i is 1; var integer: j is 1; var integer: k is 1; begin for i range 1 to 9 step 3 do for j range 1 to 9 do for k range [](i, i+1, i+2) do write(k <& "x" <& j <& "=" <& k*j lpad 2 <& "\t"); end for; write("\n"); end for; writeln; end for; end func; #!/usr/bin/s7 # s7c mt9x9.sd7 && ./mt9x9 || s7 mt9x9.sd7 || ./mt9x9.sd7 $ include "seed7_05.s7i"; const proc: main is func local var integer: i is 1; var integer: j is 1; var integer: k is 1; begin for i range 1 to 9 step 3 do for j range 1 to 9 do for k range [](i, i+1, i+2) do write(k <& "x" <& j <& "=" <& k*j lpad 2 <& "\t"); end for; write("\n"); end for; writeln; end for; end func; 批曰。『 wenyan mt9x9.wy 』。 有數一名之曰「甲」。 恆為是。若「甲」不小於十者乃止也。 有數一名之曰「乙」。 恆為是。若「乙」不小於十者乃止也。 有數「甲」名之曰「丙」。 吾有一言。名之曰「列」。 恆為是。若「丙」不小於「甲」加三者乃止也。 乘「丙」以「乙」名之曰「果」。 加「列」以「丙」。昔之「列」者今其是矣。 加「列」以『 x 』。昔之「列」者今其是矣。 加「列」以「乙」。昔之「列」者今其是矣。 加「列」以『 = 』。昔之「列」者今其是矣。 若「果」小於十者 加「列」以『 』。昔之「列」者今其是矣也。 加「列」以「果」。昔之「列」者今其是矣。 加「列」以『 \t 』。昔之「列」者今其是矣。 加「丙」以一。昔之「丙」者今其是矣。 云云。 吾有一言。曰「列」。書之。 加「乙」以一。昔之「乙」者今其是矣。 云云。 書之。 加「甲」以三。昔之「甲」者今其是矣。 云云。 批曰。『 wenyan mt9x9.wy 』。 有數一名之曰「甲」。 恆為是。若「甲」不小於十者乃止也。 有數一名之曰「乙」。 恆為是。若「乙」不小於十者乃止也。 有數「甲」名之曰「丙」。 吾有一言。名之曰「列」。 恆為是。若「丙」不小於「甲」加三者乃止也。 乘「丙」以「乙」名之曰「果」。 加「列」以「丙」。昔之「列」者今其是矣。 加「列」以『 x 』。昔之「列」者今其是矣。 加「列」以「乙」。昔之「列」者今其是矣。 加「列」以『 = 』。昔之「列」者今其是矣。 若「果」小於十者 加「列」以『 』。昔之「列」者今其是矣也。 加「列」以「果」。昔之「列」者今其是矣。 加「列」以『 \t 』。昔之「列」者今其是矣。 加「丙」以一。昔之「丙」者今其是矣。 云云。 吾有一言。曰「列」。書之。 加「乙」以一。昔之「乙」者今其是矣。 云云。 書之。 加「甲」以三。昔之「甲」者今其是矣。 云云。 文言 Seed7
  55. Code to Code Code to Code \ abclang < mt9x9.abc

    FOR i IN {1; 4; 7}: FOR j IN {1..9}: FOR k IN {i..i+2}: WRITE "`k`x`j`=`k*j>>2``"">>2`" WRITE / WRITE / \ abclang < mt9x9.abc FOR i IN {1; 4; 7}: FOR j IN {1..9}: FOR k IN {i..i+2}: WRITE "`k`x`j`=`k*j>>2``"">>2`" WRITE / WRITE / // fsharpc mt9x9.fs && mono mt9x9.exe // || fsharpi --quiet --exec mt9x9.fs module mt9x9 for i in 1..3..9 do for j in 1..9 do List.iter (fun k -> printf "%dx%d=%2d\t" k j (k*j)) [i; i+1; i+2] printf "\n" printfn "" // fsharpc mt9x9.fs && mono mt9x9.exe // || fsharpi --quiet --exec mt9x9.fs module mt9x9 for i in 1..3..9 do for j in 1..9 do List.iter (fun k -> printf "%dx%d=%2d\t" k j (k*j)) [i; i+1; i+2] printf "\n" printfn "" F# ABC
  56. Code to Code Code to Code #!/usr/bin/python3 # ./mt9x9.py ||

    python3 mt9x9.py for i in range(1, 10, 3): for j in range(1, 10): for k in [i, i+1, i+2]: print(f"{k}x{j}={k*j:2}", end='\t') print(end='\n') print() #!/usr/bin/python3 # ./mt9x9.py || python3 mt9x9.py for i in range(1, 10, 3): for j in range(1, 10): for k in [i, i+1, i+2]: print(f"{k}x{j}={k*j:2}", end='\t') print(end='\n') print() #!/usr/bin/booi // booc mt9x9.boo && mono mt9x9.exe || ./mt9x9.boo // || booi mt9x9.boo for i in range(1, 10, 3): for j in range(1, 10): for k as int in [i, i+1, i+2]: System.Console.Write("${k}x${j}=") if k*j < 10: System.Console.Write(" ") System.Console.Write("${k*j}\t") print("") print #!/usr/bin/booi // booc mt9x9.boo && mono mt9x9.exe || ./mt9x9.boo // || booi mt9x9.boo for i in range(1, 10, 3): for j in range(1, 10): for k as int in [i, i+1, i+2]: System.Console.Write("${k}x${j}=") if k*j < 10: System.Console.Write(" ") System.Console.Write("${k*j}\t") print("") print Boo Python
  57. Reference Reference Rosetta Code <https://www.rosettacode.org/wiki/Multiplication_tables> Learn X in Y minutes

    <https://learnxinyminutes.com/> Fibonacci Benchmark <https://github.com/drujensen/fib> Excluded target languages A+, Agda, APL, Assembly, Brainfuck, Chapel, Clean, Crack, Idris, K, Kite, Pike, Pure, Q, Red, Sawzall, Sidef, Voodoo, Zig
  58. Thank you! Slides Template :資訊未來大自由 by Eric Sun