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

Multiplication Table in Various Programming Languages

趙惟倫
September 18, 2018

Multiplication Table in Various Programming Languages

趙惟倫

September 18, 2018
Tweet

More Decks by 趙惟倫

Other Decks in Programming

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/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 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 #!/usr/bin/bs # ./mt9x9.bs ||

    bs mt9x9.bs for i = 1, i <= 9, i = i+3 for j = 1, j <= 9, ++j s = "" for k = i, k <= i+2, ++k s = s_k_"x"_j_"="_("", " ")[k*j < 10]_k*j_"\t" next put = s next put = "" next run exit #!/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 BS
  6. Code to Code Code to Code #!/usr/bin/ring // ./mt9x9.ring ||

    ring mt9x9.ring for i = 1 to 9 step 3 for j = 1 to 9 for k in [i, i+1, i+2] see "" + k + "x" + j + "=" if k*j<10 see " " ok see "" + k*j + tab next put nl 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 Ring
  7. 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 module: mt9x9 // make-dylan-app mt9x9; mv mt9x9.dylan mt9x9; cd mt9x9; // dylan-compiler -build mt9x9.lid && _build/bin/mt9x9 for (i from 1 below 10 by 3) for (j from 1 to 9) for (k from i to i + 2) format-out("%dx%d=%2d\t", k, j, k * j); end; format-out("\n"); end; format-out("\n"); end; Dylan Sather
  8. Code to Code Code to Code #!/usr/bin/agena # ./mt9x9.agn ||

    agena mt9x9.agn for i from 1 to 9 by 3 do for j from 1 to 9 do for k in [i, i+1, i+2] do printf('%dx%d=%2d\t', k, j, k*j) od; print() od; writeline() od; #!/usr/bin/kite # ./mt9x9.kite || kite mt9x9.kite i = 1; while(i <= 9) [ j = 1; while(j <= 9) [ k = i; s = ""; until(k > 2+i) [ s = s + ("%dx%d=%2d\t" | format([k, j, k*j])); k = k + 1; ]; s | print; j = j + 1; ]; "" | print; i = i + 3; ]; Kite Agena
  9. 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. % 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
  10. 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. (* 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
  11. 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; #!/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
  12. Code to Code Code to Code { 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 /* plic -C -dELF -lsiaxgo -ew mt9x9.pli -o mt9x9.o ld -z muldefs -Bstatic --oformat=elf32-i386 \ -melf_i386 -e main mt9x9.o libprf.a -o mt9x9 */ mt9x9: proc options(main); dcl(i, j, k) fixed dec(1); do i = 1 to 9 by 3; do j = 1 to 9; do k = i to i+2; put edit (k, 'x', j, '=', k*j) (P'9', A, P'9', A, P'Z9'); put edit ('09'X) (A); end; put skip edit ('') (A); end; put skip edit ('') (A); end; end mt9x9; PL/I
  13. 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; (* 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
  14. 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/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
  15. 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/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
  16. 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"); } } // g++ mt9x9.cpp -o mt9x9 && ./mt9x9 #include <iostream> using namespace std; int main() { for(int i = 1; i <= 9; i += 3) { for(int j = 1; j <= 9; j++) { for(int k: {i, i+1, i+2}) printf("%dx%d=%2d\t", k, j, k*j); printf("\n"); } cout << endl; } } C++ C
  17. 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(); } } } // 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#
  18. Code to Code Code to Code #!/usr/bin/pike // ./mt9x9.pike ||

    pike mt9x9.pike int main() { for(int i = 1; i <= 9; i += 3) { for(int j = 1; j <= 9; j++) { foreach(({i, i+1, i+2}), int k) { write(k+"x"+j+"="+sprintf("%2d\t", k*j)); } write("\n"); } write("\n"); } } // vlang mt9x9.v && ./mt9x9 || vlang run mt9x9.v fn main() { for i := 1; i <= 9; i += 3 { for j in 1..10 { for k in [i, i+1, i+2] { print('${k}x${j}=${k*j:2}\t') } print('\n') } println('') } } V Pike
  19. Code to Code Code to Code // 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!(); } } // zig build-exe mt9x9.zig && ./mt9x9 || zig run mt9x9.zig const std = @import("std"); pub fn main() !void { var i: u8 = 1; while (i < 10) : (i += 3) { var j: u8 = 1; while (j < 10) : (j += 1) { for ([_]u8{i, i+1, i+2}) |k| { std.debug.print("{d}x{d}={d: >2}\t", .{k, j, k*j}); } std.debug.print("\n", .{}); } std.debug.print("\n", .{}); } } Zig Rust
  20. Code to Code Code to Code // 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() } } // odin-lang build mt9x9.odin -file && ./mt9x9.bin package mt9x9 import "core:fmt" main :: proc() { for i := 1; i <= 9; i += 3 { for j in 1..=9 { for k in ([]int{i, i+1, i+2}) { fmt.printf("%dx%d=", k, j); if k*j<10 do fmt.print(" "); fmt.printf("%d\t", k*j); } fmt.print("\n"); } fmt.println(); } } Odin Go
  21. 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; // valac mt9x9.vala && ./mt9x9 void main() { for(int i = 1; i <= 9; i += 3) { for(int j = 1; j <= 9; j++) { int[] K = {i, i+1, i+2}; foreach(int k in K) stdout.printf("%dx%d=%2d\t", k, j, k*j); print("\n"); } stdout.putc('\n'); } } Vala Seed7
  22. 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") } } #!/usr/bin/never -f # ./mt9x9.nev || never -f mt9x9.nev func main() -> int { var i = 0; for (i = 1; i <= 9; i = i+3) { var j = 0; for (j = 1; j <= 9; j = j+1) { var k = 0; for (k = i; k <= i+2; k = k+1) { prints(k + "x" + j + "="); if (k*j < 10) {prints(" ")} else {prints("")}; prints(k*j + "\t") }; prints("\n") }; prints("\n") } } Never Umka
  23. Code to Code Code to Code #!/usr/bin/monkeylang // ./mt9x9.mon ||

    monkeylang mt9x9.mon i = 1 for (i <= 9) { foreach j in 1..9 { foreach k in [i, i+1, i+2] { printf("%dx%d=%2d\t", k, j, k*j) } puts("\n") } puts("\n") i += 3 } Monkey #!/usr/bin/lily # ./mt9x9.lily || lily mt9x9.lily for i in 1...9 by 3: { for j in 1...9: { foreach k in [i, i+1, i+2]: { stdout.write("{}x{}=".format(k, j)) if k*j < 10: { stdout.write(" ") } stdout.write("{}\t".format(k*j)) } stdout.write("\n") } print("") } Lily
  24. Code to Code Code to Code // as3shebang mt9x9.as3 for(var

    i:uint = 1; i <= 9; i += 3) { for(var j:uint = 1; j <= 9; j++) { var s:String = ""; for(var k:uint = i; k <= i+2; k++) s += k+"x"+j+"="+(" "+k*j).slice(-2)+"\t"; trace(s); } trace(); } #!/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 ActionScript
  25. Code to Code Code to Code #!/usr/bin/deno run // deno

    compile mt9x9.ts && ./mt9x9 || // ./mt9x9.ts || deno run mt9x9.ts for(let i:number = 1; i <= 9; i += 3) { for(let j:number = 1; j <= 9; j++) console.log( [i, i+1, i+2].map( k => k+'x'+j+'='+(' '+k*j).slice(-2) ).join('\t') ) console.log() } #!/usr/bin/bsh // ./mt9x9.bsh || bsh mt9x9.bsh for(i = 1; i <= 9; i += 3) { for(j = 1; j <= 9; j++) { for(k: new int[]{i, i+1, i+2}) System.out.printf("%dx%d=%2d\t", k, j, k*j); System.out.printf("\n"); } System.out.println(); } BeanShell TypeScript
  26. Code to Code Code to Code // javac mt9x9.java &&

    java mt9x9 public class mt9x9 { public static void main(String args[]) { for(int i = 1; i <= 9; i += 3) { for(int j = 1; j <= 9; j++) { for(int k: new int[]{i, i+1, i+2}) 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() } } } Fantom Java
  27. 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() } } } // kotlinc-native -o mt9x9 mt9x9.kt && ./mt9x9.kexe fun main() { for (i in 1..9 step 3) { for (j in 1..9) { (i..i+2).forEach { print("${it}x${j}=") print((it*j).toString().padStart(2) + "\t") } print("\n") } println() } } Kotlin Scala
  28. 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 "" } // 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
  29. Code to Code Code to Code ## aviator mt9x9.av for

    i in range(1, 9, 3) { for j in range(1, 10) { for k in tuple(i, i+1, i+2) { print(k+"x"+j+"="+(k*j<10?" ":"")+k*j+"\t"); } println(); } if i < 7 {p();} } return ""; AviatorScript #!/usr/bin/covs # ./mt9x9.csc || covs mt9x9.csc foreach i in {1, 4, 7} foreach j in range(1, 10) for k = i, k <= i+2, k++ system.out.print(to_string(k)+"x"+to_string(j)+"=") system.out.print(k*j < 10 ? " " : "") system.out.print(to_string(k*j)+"\t") end system.out.print("\n") end system.out.println("") end Covariant Script
  30. 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/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
  31. 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/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
  32. 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/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
  33. 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/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 TCL
  34. Code to Code Code to Code #!/usr/bin/hhvm // ./mt9x9.hack ||

    hhvm mt9x9.hack <<__EntryPoint>> function main(): void { for ($i = 1; $i <= 9; $i += 3) { for ($j = 1; $j <= 9; $j++) { foreach (vec[$i, $i+1, $i+2] as $k) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } print("\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++) { foreach (array($i, $i+1, $i+2) as $k) { printf("%dx%d=%2d\t", $k, $j, $k*$j); } print("\n"); } echo "\n"; } ?> PHP Hack
  35. Code to Code Code to Code #!/usr/bin/bash # ./mt9x9.sh ||

    bash mt9x9.sh for i in {1..9..3}; do for (( j = 1; j <= 9; j++ )); 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 Fish BASH
  36. Code to Code Code to Code #!/usr/bin/elvish # ./mt9x9.elv ||

    elvish mt9x9.elv for i [(range 1 10 &step=3)] { for j [(range 1 10)] { for k [$i (+ $i 1) (+ $i 2)] { printf '%dx%d=%2d\t' $k $j (* $k $j) } print "\n" } echo } #!/usr/bin/ngs # ./mt9x9.ngs || ngs mt9x9.ngs for(i; 3) { for(j = 1; j <= 9; j += 1) { [i*3+1, i*3+2, i*3+3].each(F(k) { write("${k}x${j}=${if k*j<10 ' ' ''}${k*j}\t") }) write('\n') } echo('') } NGS Elvish
  37. Code to Code Code to Code #!/usr/bin/abs // ./mt9x9.abs ||

    abs mt9x9.abs for i in [1, 4, 7] { for j in 1..9 { s = "" for k in [i, i+1, i+2] { s = s + fmt("%sx%s=%2s\t", k, j, k*j) } echo(s) } echo() } #!/usr/bin/tcsh -f # ./mt9x9.csh || tcsh -f mt9x9.csh foreach i (1 4 7) set j = 1 while ($j <= 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" @ j++ end echo end CSH ABS
  38. Code to Code Code to Code #!/usr/bin/oh # ./mt9x9.oh ||

    oh mt9x9.oh for (seq 3) (method (I) { define i (math "$I * 3 + 1") for (seq 9) (method (J) { define j (math "$J + 1") for (seq 3) (method (K) { define k (math "$K + $i") printf %dx%d=%2d\t $k $j (math "$k * $j") }) printf \n }) echo }) #!/usr/bin/murex # ./mt9x9.mx || murex mt9x9.mx for: (i = 1; i <= 9; i = i + 3) { a: [1..9] -> foreach: j { a: [$i, ${= i+1}, ${= i+2}] -> foreach: k { (${= k}x${= j}=) if: {= $k*$j < 10} {( )} (${= $k*$j})\t } ()\n } out: } Murex Oh
  39. 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 } "" } @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
  40. 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 } } AWK # mlr -n put -f mt9x9.mlr begin { for (int i = 1; i <= 9; i += 3) { for (int j = 1; j <= 9; j += 1) { for (int k = i; k <= i+2; k += 1) { printn fmtnum(k, "%dx").fmtnum(j, "%d=") printn fmtnum(j*k, "%2d\t"); } printn "\n"; } print; } } Miller
  41. Code to Code Code to Code #!/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 #!/usr/bin/stap // ./mt9x9.stp || stap mt9x9.stp probe oneshot { 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) print("\n") } println() } } SystemTap
  42. 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() } // chuck mt9x9.ck for (1 => int i; i < 10; 3 +=> i) { for (1 => int j; j < 10; j++) { for (i => int k; k <= i+2; k++) { chout <= k <= "x" <= j <= "="; if (k*j < 10) chout <= " "; chout <= k*j <= "\t"; } chout <= "\n"; } chout <= IO.nl(); } Chuck Swift
  43. 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. // ./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
  44. 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(''); } } } // 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
  45. 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 # 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
  46. 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 % 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 Nit
  47. 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/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
  48. 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/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
  49. 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/txr -f ;; ./mt9x9.tl || ./txr -f mt9x9.tl (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
  50. Code to Code Code to Code #!/usr/bin/dern !# ; ./mt9x9.dern

    || dern mt9x9.dern (print-readably false) (for i from {D+1} to {D+9} step {D+3} (for j from {D+1} to {D+9} (for k from i to (+ i {D+2}) (print k) (print [x]) (print j) (print [=]) (if (< (* k j) {D+10}) (print [ ])) (print (* k j)) (print [|tab|]) ) (print [|newline|]) ) (print [|0A|]) ) #!/usr/bin/newlisp ; ./mt9x9.lsp || newlispmt9x9.lsp (for (i 1 9 3) (for (j 1 9) (for (k i (+ i 2)) (print (format "%dx%d=%2d\t" k j (* k j))) ) (print "\n") ) (println) ) (exit) newLISP Dern
  51. 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/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
  52. 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/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 Crystal Ruby
  53. Code to Code Code to Code # ./mt9x9.joy || joy

    mt9x9.joy 1 [9 <=] [ 1 [9 <=] [ 0 [2 <=] [ dup rotated dupd + dup 48 + putch 'x putch rolldown dup 48 + putch '= putch dup rollup * 'i 2 1 format putchars rolldown '\t putch succ ] while pop '\n putch succ ] while pop '\n putch 3 + ] while pop. #!/usr/bin/retro ( retro mt9x9.retro ) ~~~ { #1 #4 #7 } [ { #1 #2 #3 #4 #5 #6 #7 #8 #9 } [ dup-pair swap { #0 #1 #2 } [ + dup-pair n:put 'x s:put n:put '= s:put * dup #10 lt? [ '_ s:put ] if '%n\t s:format s:put dup-pair swap ] a:for-each nl drop-pair drop ] a:for-each nl drop ] a:for-each ~~~ Retro Joy
  54. Code to Code Code to Code ! Factor mt9x9.factor USING:

    byte-arrays io io.encodings.ascii io.encodings.string kernel math prettyprint ranges sequences ; 1 9 3 <range> [ 9 [1..b] [ over dup 2 + 1 <range> [ 2dup pprint "x" write pprint "=" write over * dup 10 < [ bl pprint ] [ pprint ] if 9 1byte-array ascii decode write ] each drop "\n" write ] each drop nl ] each % 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 Factor
  55. 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/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
  56. 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' #!/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
  57. Code to Code Code to Code -- idris mt9x9.idr -o

    mt9x9 && ./mt9x9 item : Nat -> Nat -> String item j k = (show k)++"x"++(show j)++"="++ (if k*j < 10 then " " else "")++(show (k*j))++" " line : Nat -> Nat -> String line i j = unwords $ map (item j) [(i)..(i+2)] block : Nat -> String block i = unlines $ map (line i) [1..9] main : IO () main = putStr $ unlines $ map block [1, 4, 7] // pure -c mt9x9.pure -o mt9x9 && ./mt9x9 || pure mt9x9.pure using system; map block [1, 4, 7] with block i = map (line i) (1..9); line i j = map (item j) (i..i+2); item j k = printf ("%dx%d=%2d%s") (k, j, k*j, (if k mod 3~=0 then "\t" else if j==9 then "\n\n" else "\n")); end; Pure Idris
  58. 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 % 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 Eiffel
  59. 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(). #!/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
  60. 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) ) } #!/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
  61. Code to Code Code to Code // grain mt9x9.gr ||

    grain run mt9x9.gr.wasm import File from "sys/file" import Range from "range" let item = (j, k) => { File.fdWrite(File.stdout, toString(k) ++ "x") File.fdWrite(File.stdout, toString(j) ++ "=") if (k*j < 10) { File.fdWrite(File.stdout, " " ++ toString(k*j) ++ "\t") } else { File.fdWrite(File.stdout, toString(k*j) ++ "\t") } void } let line = (i, j) => { Range.forEach(k => item(j, k), Range.Inclusive(i, i+2)) print("") } let block = (i) => { Range.forEach(j => line(i*3+1, j), Range.Inclusive(1, 9)) print("") } Range.forEach(i => block(i), Range.Inclusive(0, 2)) #!/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 Grain
  62. Code to Code Code to Code * snobol4 -b mt9x9.sno

    i = 1 block j = 1 line k = i s = "" item s = s k "x" j "=" LPAD(k * j, 2) CHAR(9) k = ?LT(k, i + 2) k + 1 :S(item) OUTPUT = s j = ?LT(j, 9) j + 1 :S(line) OUTPUT = "" i = ?LT(i, 7) i + 3 :S(block) END SNOBOL #!/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
  63. 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) } #!/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
  64. 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 // 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
  65. 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 % sisalc -fileio mt9x9.sis -o mt9x9 && ./mt9x9 define main type string = array[character]; function main(returns string) for i in array[1: 1, 4, 7] cross j in 1, 9 cross k in i, i+2 s := array[1: character(48+k),'x',character(48+j),'='] || if k*j < 10 then array[1: ' ',character(48+k*j)] else array[1: character(48+k*j/10),character(48+mod(k*j,10))] end if || if k ~= i+2 then array[1: '\t'] elseif j = 9 then array[1: '\n','\n'] else array[1: '\n'] end if returns value of catenate s end for end function SISAL Forth
  66. 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/nial -defs # ./mt9x9.ndf || nial -defs mt9x9.ndf for i with 1 + (3 * tell 3) do for j with count 9 do for k with i + tell 3 do writechars link (string k) `x (string j) `=; if (k*j) < 10 then writechars ' ' endif; writechars link (string (k*j)) (char 9) endfor; writechars char 10 endfor; write '' endfor; bye Nial J
  67. 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/genius # ./mt9x9.gel || genius mt9x9.gel for i = 1 to 9 by 3 do ( for j = 1 to 9 do ( for k in [i, i+1, i+2] do ( printn(k+"x"+j+"="); if k*j < 10 then printn(" "); printn(k*j+"\t") ); printn("\n") ); print("") ) GEL BC
  68. Code to Code Code to Code // chpl mt9x9.chpl &&

    ./mt9x9 for i in 1..9 by 3 { for j in 1..9 { for k in [i, i+1, i+2] { writef("%{#}x%{#}=%{##}\t", k, j, k*j); } write('\n'); } writeln(); } % nelson-cli -q -f mt9x9.nlf for i = 1:3:9 for j = 1:9 s = ""; for k = [i, i+1, i+2] s = s + sprintf("%dx%d=%2d\t", k, j, k*j); end disp(s); end disp(""); end exit() Nelson Chapel
  69. 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/octave-cli % ./mt9x9.m || octave-cli mt9x9.m for i = (1:3:9) for j = (1:9) for k = [i, i+1, i+2] printf('%dx%d=%2d\t', k, j, k*j); endfor puts("\n"); endfor disp(''); endfor MATLAB R
  70. Code to Code Code to Code #!/usr/bin/gnuplot # ./mt9x9.plt ||

    gnuplot mt9x9.plt do for [i = 1:9:3] for [j = 1:9] { s = "" do for [k = i:i+2] { s = s.sprintf("%dx%d=%2d\t", k, j, k*j) } if (j == 9) {print s."\n"} else {print 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 Gnuplot
  71. Code to Code Code to Code * pspp mt9x9.sps NEW

    FILE. INPUT PROGRAM. STRING #s #s0 TO #s2 (A6). LOOP #i = 1 TO 9 BY 3. LOOP #j = 1 TO 9. LOOP #k = #i TO #i+2. COMPUTE #s = CONCAT(STRING(#k,F1),"x",STRING(#j,F1),"=",STRING(#k*#j,F2)). IF(#k = #i) #s0 = #s. IF(#k = #i+1) #s1 = #s. IF(#k = #i+2) #s2 = #s. END LOOP. PRINT / #s0(A6) " " #s1(A6) " " #s2(A6). END LOOP. PRINT. END LOOP. WRITE. END FILE. END INPUT PROGRAM. EXECUTE. #!/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 SPSS
  72. 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 #!/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 ) Io IDL
  73. Code to Code Code to Code // iverilog mt9x9.vlg -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; VHDL Verilog
  74. Code to Code Code to Code #!/usr/bin/ampl # ./mt9x9.run ||

    ampl mt9x9.run for {i in 1 .. 9 by 3} { for {j in 1 .. 9} { for {k in {i, i+1, i+2}} { printf "%dx%d=%2d\t", k, j, k*j; } printf "\n"; } printf "\n"; } ! 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 AMPL
  75. 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 ! // daScript mt9x9.das require strings [export] def main for i in [[int[3] 1; 4; 7]] for j in range(1, 10) for k in range(i, i+3) print("{k}x{j}={format("%2d", k*j)}\t") print("\n") print("\n") daScript MUMPS
  76. 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 / // 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
  77. 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/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
  78. Code to Code Code to Code // lobster mt9x9.lobster for([1,

    4, 7]) i: for(9) J: let j = J + 1 var s = "" for([i, i+1, i+2]) k: s += "{k}x{j}={if k*j<10: " " else: ""}{k*j}\t" print s print "" # 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 Lobster
  79. Code to Code Code to Code \: zoem -i mt9x9

    \set{i}{1} \while{\let{\i <= 9}}{ \set{j}{1} \while{\let{\j <= 9}}{ \set{k}{\i} \set{K}{0} \while{\let{\K <= 2}}{ \setx{k}{\let{\i + \K}} \write{-}{txt}{\k\,x\j\,=} \set{s}{\let{\k * \j}} \if{\let{\s < 10}}{\write{-}{txt}{ }}{} \write{-}{txt}{\s } \setx{K}{\let{\K + 1}} } \write{-}{txt}{\|} \setx{j}{\let{\j + 1}} } \write{-}{txt}{\|} \setx{i}{\let{\i + 3}} } Zoem -- 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 ''; SQL
  80. 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. COBOL 批曰。『 wenyan mt9x9.wy 』。 有數一名之曰「甲」。 恆為是。若「甲」不小於十者乃止也。 有數一名之曰「乙」。 恆為是。若「乙」不小於十者乃止也。 有數「甲」名之曰「丙」。 吾有一言。名之曰「列」。 恆為是。若「丙」不小於「甲」加三者乃止也。 乘「丙」以「乙」名之曰「果」。 加「列」以「丙」。昔之「列」者今其是矣。 加「列」以『 x 』。昔之「列」者今其是矣。 加「列」以「乙」。昔之「列」者今其是矣。 加「列」以『 = 』。昔之「列」者今其是矣。 若「果」小於十者 加「列」以『 』。昔之「列」者今其是矣也。 加「列」以「果」。昔之「列」者今其是矣。 加「列」以『 \t 』。昔之「列」者今其是矣。 加「丙」以一。昔之「丙」者今其是矣。 云云。 吾有一言。曰「列」。書之。 加「乙」以一。昔之「乙」者今其是矣。 云云。 書之。 加「甲」以三。昔之「甲」者今其是矣。 云云。 文言
  81. 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> 99 Bottles of Beer <https://www.99-bottles-of-beer.net/> Excluded target languages 11l, A+, Agda, APL, Assembly, Brainfuck, Clean, Crack, Elena, Eliza, K, Objective-C, Q, Red, Sawzall, Self, Sidef, Voodoo
  82. Thank you! Slides Template :資訊未來大自由 by Eric Sun