A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
3
Task/Multiplication-tables/0DESCRIPTION
Normal file
3
Task/Multiplication-tables/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Produce a formatted 12×12 multiplication table of the kind memorised by rote when in primary school.
|
||||
|
||||
Only print the top half triangle of products.
|
||||
2
Task/Multiplication-tables/1META.yaml
Normal file
2
Task/Multiplication-tables/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Arithmetic operations
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
main:(
|
||||
INT max = 12;
|
||||
INT width = ENTIER(log(max)*2)+1;
|
||||
STRING empty = " "*width, sep="|", hr = "+" + (max+1)*(width*"-"+"+");
|
||||
FORMAT ifmt = $g(-width)"|"$; # remove leading zeros #
|
||||
|
||||
printf(($gl$, hr));
|
||||
print(sep + IF width<2 THEN "x" ELSE " "*(width-2)+"x " FI + sep);
|
||||
FOR col TO max DO printf((ifmt, col)) OD;
|
||||
printf(($lgl$, hr));
|
||||
|
||||
FOR row TO max DO
|
||||
[row:max]INT product;
|
||||
FOR col FROM row TO max DO product[col]:=row*col OD;
|
||||
STRING prefix=(empty+sep)*(row-1);
|
||||
printf(($g$, sep, ifmt, row, $g$, prefix, ifmt, product, $l$))
|
||||
OD;
|
||||
printf(($gl$, hr))
|
||||
)
|
||||
22
Task/Multiplication-tables/AWK/multiplication-tables.awk
Normal file
22
Task/Multiplication-tables/AWK/multiplication-tables.awk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
BEGIN{
|
||||
for(i=1;i<13;i++){
|
||||
for(j=1;j<13;j++){
|
||||
if(j>=i||j==1){printf("%4d",i*j);}
|
||||
else {printf(" ");}
|
||||
}
|
||||
print;
|
||||
}
|
||||
}
|
||||
|
||||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
2 4 6 8 10 12 14 16 18 20 22 24
|
||||
3 9 12 15 18 21 24 27 30 33 36
|
||||
4 16 20 24 28 32 36 40 44 48
|
||||
5 25 30 35 40 45 50 55 60
|
||||
6 36 42 48 54 60 66 72
|
||||
7 49 56 63 70 77 84
|
||||
8 64 72 80 88 96
|
||||
9 81 90 99 108
|
||||
10 100 110 120
|
||||
11 121 132
|
||||
12 144
|
||||
25
Task/Multiplication-tables/Ada/multiplication-tables.ada
Normal file
25
Task/Multiplication-tables/Ada/multiplication-tables.ada
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
|
||||
procedure Multiplication_Table is
|
||||
package IO is new Integer_IO (Integer);
|
||||
use IO;
|
||||
begin
|
||||
Put (" | ");
|
||||
for Row in 1..12 loop
|
||||
Put (Row, Width => 4);
|
||||
end loop;
|
||||
New_Line;
|
||||
Put_Line ("--+-" & 12 * 4 * '-');
|
||||
for Row in 1..12 loop
|
||||
Put (Row, Width => 2);
|
||||
Put ("| ");
|
||||
for Column in 1..12 loop
|
||||
if Column < Row then
|
||||
Put (" ");
|
||||
else
|
||||
Put (Row * Column, Width => 4);
|
||||
end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Multiplication_Table;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
set n to 12 -- Size of table.
|
||||
repeat with x from 0 to n
|
||||
if x = 0 then set {table, x} to {{return}, -1}
|
||||
repeat with y from 0 to n
|
||||
if y's contents = 0 then
|
||||
if x > 0 then set row to {f(x)}
|
||||
if x = -1 then set {row, x} to {{f("x")}, 1}
|
||||
else
|
||||
if y ≥ x then set end of row to f(x * y)
|
||||
if y < x then set end of row to f("")
|
||||
end if
|
||||
end repeat
|
||||
set end of table to row & return
|
||||
end repeat
|
||||
return table as string
|
||||
|
||||
-- Handler/Function for formatting fixed width integer string.
|
||||
on f(x)
|
||||
set text item delimiters to ""
|
||||
return (characters -4 thru -1 of (" " & x)) as string
|
||||
end f
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
Gui, -MinimizeBox
|
||||
Gui, Margin, 0, 0
|
||||
Gui, Font, s9, Fixedsys
|
||||
Gui, Add, Edit, h0 w0
|
||||
Gui, Add, Edit, w432 r14 -VScroll
|
||||
Gosub, Table
|
||||
Gui, Show,, Multiplication Table
|
||||
Return
|
||||
|
||||
GuiClose:
|
||||
GuiEscape:
|
||||
ExitApp
|
||||
Return
|
||||
|
||||
Table:
|
||||
; top row
|
||||
Table := " x |"
|
||||
Loop, 12
|
||||
Table .= SubStr(" " A_Index, -3)
|
||||
Table .= "`n"
|
||||
|
||||
; underlines
|
||||
Table .= "----+"
|
||||
Loop, 48
|
||||
Table .= "-"
|
||||
Table .= "`n"
|
||||
|
||||
; table
|
||||
Loop, 12 { ; rows
|
||||
Table .= SubStr(" " Row := A_Index, -2) " |"
|
||||
Loop, 12 ; columns
|
||||
Table .= SubStr(" " (A_Index >= Row ? A_Index * Row : ""), -3)
|
||||
Table .= "`n"
|
||||
}
|
||||
GuiControl,, Edit2, %Table%
|
||||
Return
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#AutoIt Version: 3.2.10.0
|
||||
$tableupto=12
|
||||
$table=""
|
||||
for $i = 1 To $tableupto
|
||||
for $j = $i to $tableupto
|
||||
$prod=string($i*$j)
|
||||
if StringLen($prod) == 1 then
|
||||
$prod = " "& $prod
|
||||
EndIf
|
||||
if StringLen($prod) == 2 then
|
||||
$prod = " "& $prod
|
||||
EndIf
|
||||
$table = $table&" "&$prod
|
||||
Next
|
||||
$table = $table&" - "&$i&@CRLF
|
||||
for $k = 1 to $i
|
||||
$table = $table&" "
|
||||
Next
|
||||
Next
|
||||
msgbox(0,"Multiplication Tables",$table)
|
||||
26
Task/Multiplication-tables/BASIC/multiplication-tables.bas
Normal file
26
Task/Multiplication-tables/BASIC/multiplication-tables.bas
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
CLS
|
||||
|
||||
'header row
|
||||
PRINT " ";
|
||||
FOR n = 1 TO 12
|
||||
'do it this way for alignment purposes
|
||||
o$ = " "
|
||||
MID$(o$, LEN(o$) - LEN(STR$(n)) + 1) = STR$(n)
|
||||
PRINT o$;
|
||||
NEXT
|
||||
PRINT : PRINT " "; STRING$(49, "-");
|
||||
|
||||
FOR n = 1 TO 12
|
||||
PRINT
|
||||
IF n < 10 THEN PRINT " ";
|
||||
PRINT n; "|"; 'row labels
|
||||
FOR m = 1 TO n - 1
|
||||
PRINT " ";
|
||||
NEXT
|
||||
FOR m = n TO 12
|
||||
'alignment again
|
||||
o$ = " "
|
||||
MID$(o$, LEN(o$) - LEN(STR$(m * n)) + 1) = STR$(m * n)
|
||||
PRINT o$;
|
||||
NEXT
|
||||
NEXT
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
@% = 5 : REM Set column width
|
||||
FOR row% = 1 TO 12
|
||||
PRINT row% TAB(row% * @%) ;
|
||||
FOR col% = row% TO 12
|
||||
PRINT row% * col% ;
|
||||
NEXT col%
|
||||
PRINT
|
||||
NEXT row%
|
||||
83
Task/Multiplication-tables/C++/multiplication-tables.cpp
Normal file
83
Task/Multiplication-tables/C++/multiplication-tables.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cmath> // for log10()
|
||||
#include <algorithm> // for max()
|
||||
|
||||
size_t get_table_column_width(const int min, const int max)
|
||||
{
|
||||
unsigned int abs_max = std::max(max*max, min*min);
|
||||
|
||||
// abs_max is the largest absolute value we might see.
|
||||
// If we take the log10 and add one, we get the string width
|
||||
// of the largest possible absolute value.
|
||||
// Add one for a little whitespace guarantee.
|
||||
size_t colwidth = 1 + std::log10(abs_max) + 1;
|
||||
|
||||
// If only one of them is less than 0, then some will
|
||||
// be negative.
|
||||
bool has_negative_result = (min < 0) && (max > 0);
|
||||
|
||||
// If some values may be negative, then we need to add some space
|
||||
// for a sign indicator (-)
|
||||
if(has_negative_result)
|
||||
colwidth++;
|
||||
|
||||
return colwidth;
|
||||
}
|
||||
|
||||
void print_table_header(const int min, const int max)
|
||||
{
|
||||
size_t colwidth = get_table_column_width(min, max);
|
||||
|
||||
// table corner
|
||||
std::cout << std::setw(colwidth) << " ";
|
||||
|
||||
for(int col = min; col <= max; ++col)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << col;
|
||||
}
|
||||
|
||||
// End header with a newline and blank line.
|
||||
std::cout << std::endl << std::endl;
|
||||
}
|
||||
|
||||
void print_table_row(const int num, const int min, const int max)
|
||||
{
|
||||
size_t colwidth = get_table_column_width(min, max);
|
||||
|
||||
// Header column
|
||||
std::cout << std::setw(colwidth) << num;
|
||||
|
||||
// Spacing to ensure only the top half is printed
|
||||
for(int multiplicand = min; multiplicand < num; ++multiplicand)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << " ";
|
||||
}
|
||||
|
||||
// Remaining multiplicands for the row.
|
||||
for(int multiplicand = num; multiplicand <= max; ++multiplicand)
|
||||
{
|
||||
std::cout << std::setw(colwidth) << num * multiplicand;
|
||||
}
|
||||
|
||||
// End row with a newline and blank line.
|
||||
std::cout << std::endl << std::endl;
|
||||
}
|
||||
|
||||
void print_table(const int min, const int max)
|
||||
{
|
||||
// Header row
|
||||
print_table_header(min, max);
|
||||
|
||||
// Table body
|
||||
for(int row = min; row <= max; ++row)
|
||||
{
|
||||
print_table_row(row, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
print_table(1, 12);
|
||||
return 0;
|
||||
}
|
||||
38
Task/Multiplication-tables/C-sharp/multiplication-tables.cs
Normal file
38
Task/Multiplication-tables/C-sharp/multiplication-tables.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
|
||||
namespace multtbl
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.Write(" X".PadRight(4));
|
||||
for (int i = 1; i <= 12; i++)
|
||||
Console.Write(i.ToString("####").PadLeft(4));
|
||||
|
||||
Console.WriteLine();
|
||||
Console.Write(" ___");
|
||||
|
||||
for (int i = 1; i <= 12; i++)
|
||||
Console.Write(" ___");
|
||||
|
||||
Console.WriteLine();
|
||||
for (int row = 1; row <= 12; row++)
|
||||
{
|
||||
Console.Write(row.ToString("###").PadLeft(3).PadRight(4));
|
||||
for (int col = 1; col <= 12; col++)
|
||||
{
|
||||
if (row <= col)
|
||||
Console.Write((row * col).ToString("###").PadLeft(4));
|
||||
else
|
||||
Console.Write("".PadLeft(4));
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Task/Multiplication-tables/C/multiplication-tables-1.c
Normal file
13
Task/Multiplication-tables/C/multiplication-tables-1.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
int main()
|
||||
{
|
||||
int i, j, n = 12;
|
||||
|
||||
for (j = 1; j <= n; j++) printf("%3d%c", j, j - n ? ' ':'\n');
|
||||
for (j = 0; j <= n; j++) printf(j - n ? "----" : "+\n");
|
||||
|
||||
for (i = 1; i <= n; printf("| %d\n", i++))
|
||||
for (j = 1; j <= n; j++)
|
||||
printf(j < i ? " " : "%3d ", i * j);
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
Task/Multiplication-tables/C/multiplication-tables-2.c
Normal file
14
Task/Multiplication-tables/C/multiplication-tables-2.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
------------------------------------------------
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 | 1
|
||||
4 6 8 10 12 14 16 18 20 22 24 | 2
|
||||
9 12 15 18 21 24 27 30 33 36 | 3
|
||||
16 20 24 28 32 36 40 44 48 | 4
|
||||
25 30 35 40 45 50 55 60 | 5
|
||||
36 42 48 54 60 66 72 | 6
|
||||
49 56 63 70 77 84 | 7
|
||||
64 72 80 88 96 | 8
|
||||
81 90 99 108 | 9
|
||||
100 110 120 | 10
|
||||
121 132 | 11
|
||||
144 | 12
|
||||
65
Task/Multiplication-tables/Chef/multiplication-tables.chef
Normal file
65
Task/Multiplication-tables/Chef/multiplication-tables.chef
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
Multigrain Bread.
|
||||
|
||||
Prints out a multiplication table.
|
||||
|
||||
Ingredients.
|
||||
12 cups flour
|
||||
12 cups grains
|
||||
12 cups seeds
|
||||
1 cup water
|
||||
9 dashes yeast
|
||||
1 cup nuts
|
||||
40 ml honey
|
||||
1 cup sugar
|
||||
|
||||
Method.
|
||||
Sift the flour.
|
||||
Put flour into the 1st mixing bowl.
|
||||
Put yeast into the 1st mixing bowl.
|
||||
Shake the flour until sifted.
|
||||
Put grains into the 2nd mixing bowl.
|
||||
Fold flour into the 2nd mixing bowl.
|
||||
Put water into the 2nd mixing bowl.
|
||||
Add yeast into the 2nd mixing bowl.
|
||||
Combine flour into the 2nd mixing bowl.
|
||||
Fold nuts into the 2nd mixing bowl.
|
||||
Liquify nuts.
|
||||
Put nuts into the 1st mixing bowl.
|
||||
Pour contents of the 1st mixing bowl into the baking dish.
|
||||
Sieve the flour.
|
||||
Put yeast into the 2nd mixing bowl.
|
||||
Add water into the 2nd mixing bowl.
|
||||
Sprinkle the seeds.
|
||||
Put flour into the 2nd mixing bowl.
|
||||
Combine seeds into the 2nd mixing bowl.
|
||||
Put yeast into the 2nd mixing bowl.
|
||||
Put seeds into the 2nd mixing bowl.
|
||||
Remove flour from the 2nd mixing bowl.
|
||||
Fold honey into the 2nd mixing bowl.
|
||||
Put water into the 2nd mixing bowl.
|
||||
Fold sugar into the 2nd mixing bowl.
|
||||
Squeeze the honey.
|
||||
Put water into the 2nd mixing bowl.
|
||||
Remove water from the 2nd mixing bowl.
|
||||
Fold sugar into the 2nd mixing bowl.
|
||||
Set aside.
|
||||
Drip until squeezed.
|
||||
Scoop the sugar.
|
||||
Crush the seeds.
|
||||
Put yeast into the 2nd mixing bowl.
|
||||
Grind the seeds until crushed.
|
||||
Put water into the 2nd mixing bowl.
|
||||
Fold seeds into the 2nd mixing bowl.
|
||||
Set aside.
|
||||
Drop until scooped.
|
||||
Randomize the seeds until sprinkled.
|
||||
Fold honey into the 2nd mixing bowl.
|
||||
Put flour into the 2nd mixing bowl.
|
||||
Put grains into the 2nd mixing bowl.
|
||||
Fold seeds into the 2nd mixing bowl.
|
||||
Shake the flour until sieved.
|
||||
Put yeast into the 2nd mixing bowl.
|
||||
Add water into the 2nd mixing bowl.
|
||||
Pour contents of the 2nd mixing bowl into the 2nd baking dish.
|
||||
|
||||
Serves 2.
|
||||
13
Task/Multiplication-tables/Clojure/multiplication-tables.clj
Normal file
13
Task/Multiplication-tables/Clojure/multiplication-tables.clj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(let [size 12
|
||||
trange (range 1 (inc size))
|
||||
fmt-width (+ (.length (str (* size size))) 1)
|
||||
fmt-str (partial format (str "%" fmt-width "s"))
|
||||
fmt-dec (partial format (str "% " fmt-width "d"))]
|
||||
|
||||
(doseq [s (cons
|
||||
(apply str (fmt-str " ") (map #(fmt-dec %) trange))
|
||||
(for [i trange]
|
||||
(apply str (fmt-dec i) (map #(fmt-str (str %))
|
||||
(map #(if (>= % i) (* i %) " ")
|
||||
(for [j trange] j))))))]
|
||||
(println s)))
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
print_multiplication_tables = (n) ->
|
||||
width = 4
|
||||
|
||||
pad = (s, n=width, c=' ') ->
|
||||
s = s.toString()
|
||||
result = ''
|
||||
padding = n - s.length
|
||||
while result.length < padding
|
||||
result += c
|
||||
result + s
|
||||
|
||||
s = pad('') + '|'
|
||||
for i in [1..n]
|
||||
s += pad i
|
||||
console.log s
|
||||
|
||||
s = pad('', width, '-') + '+'
|
||||
for i in [1..n]
|
||||
s += pad '', width, '-'
|
||||
console.log s
|
||||
|
||||
|
||||
for i in [1..n]
|
||||
s = pad i
|
||||
s += '|'
|
||||
s += pad '', width*(i - 1)
|
||||
for j in [i..n]
|
||||
s += pad i*j
|
||||
console.log s
|
||||
|
||||
print_multiplication_tables 12
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
> coffee multiply.coffee
|
||||
| 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
----+------------------------------------------------
|
||||
1| 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
2| 4 6 8 10 12 14 16 18 20 22 24
|
||||
3| 9 12 15 18 21 24 27 30 33 36
|
||||
4| 16 20 24 28 32 36 40 44 48
|
||||
5| 25 30 35 40 45 50 55 60
|
||||
6| 36 42 48 54 60 66 72
|
||||
7| 49 56 63 70 77 84
|
||||
8| 64 72 80 88 96
|
||||
9| 81 90 99 108
|
||||
10| 100 110 120
|
||||
11| 121 132
|
||||
12| 144
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(do ((m 0 (if (= 12 m) 0 (1+ m)))
|
||||
(n 0 (if (= 12 m) (1+ n) n)))
|
||||
((= n 13))
|
||||
(if (zerop n)
|
||||
(case m
|
||||
(0 (format t " *|"))
|
||||
(12 (format t " 12~&---+------------------------------------------------~&"))
|
||||
(otherwise
|
||||
(format t "~4,D" m)))
|
||||
(case m
|
||||
(0 (format t "~3,D|" n))
|
||||
(12 (format t "~4,D~&" (* n m)))
|
||||
(otherwise
|
||||
(if (>= m n)
|
||||
(format t "~4,D" (* m n))
|
||||
(format t " "))))))
|
||||
21
Task/Multiplication-tables/D/multiplication-tables.d
Normal file
21
Task/Multiplication-tables/D/multiplication-tables.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import std.stdio, std.array;
|
||||
|
||||
void main() {
|
||||
enum int max = 12;
|
||||
write(" | ");
|
||||
foreach (row; 1 .. max+1)
|
||||
writef("%4d", row);
|
||||
writeln();
|
||||
writeln("--+-", "-".replicate(max * 4));
|
||||
foreach (row; 1 .. max+1) {
|
||||
writef("%2d", row);
|
||||
write("| ");
|
||||
foreach (column; 1 .. max+1) {
|
||||
if (column < row)
|
||||
write(" ");
|
||||
else
|
||||
writef("%4d", row * column);
|
||||
}
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
const size = 12;
|
||||
var row, col : Integer;
|
||||
|
||||
Print(' | ');
|
||||
for row:=1 to size do
|
||||
Print(Format('%4d', [row]));
|
||||
PrintLn('');
|
||||
PrintLn('--+-'+StringOfChar('-', size*4));
|
||||
for row:=1 to size do begin
|
||||
Print(Format('%2d', [row]));
|
||||
Print('| ');
|
||||
for col:=1 to size do begin
|
||||
if col<row then
|
||||
Print(' ')
|
||||
else Print(Format('%4d', [row*col]));
|
||||
end;
|
||||
PrintLn('');
|
||||
end;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
program MultiplicationTables;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
const
|
||||
MAX_COUNT = 12;
|
||||
var
|
||||
lRow, lCol: Integer;
|
||||
begin
|
||||
Write(' | ');
|
||||
for lRow := 1 to MAX_COUNT do
|
||||
Write(Format('%4d', [lRow]));
|
||||
Writeln('');
|
||||
Writeln('--+-' + StringOfChar('-', MAX_COUNT * 4));
|
||||
for lRow := 1 to MAX_COUNT do
|
||||
begin
|
||||
Write(Format('%2d', [lRow]));
|
||||
Write('| ');
|
||||
for lCol := 1 to MAX_COUNT do
|
||||
begin
|
||||
if lCol < lRow then
|
||||
Write(' ')
|
||||
else
|
||||
Write(Format('%4d', [lRow * lCol]));
|
||||
end;
|
||||
Writeln;
|
||||
end;
|
||||
end.
|
||||
14
Task/Multiplication-tables/E/multiplication-tables.e
Normal file
14
Task/Multiplication-tables/E/multiplication-tables.e
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def size := 12
|
||||
println(`{|style="border-collapse: collapse; text-align: right;"`)
|
||||
println(`|`)
|
||||
for x in 1..size {
|
||||
println(`|style="border-bottom: 1px solid black; " | $x`)
|
||||
}
|
||||
for y in 1..size {
|
||||
println(`|-`)
|
||||
println(`|style="border-right: 1px solid black;" | $y`)
|
||||
for x in 1..size {
|
||||
println(`| ${if (x >= y) { x*y } else {""}}`)
|
||||
}
|
||||
}
|
||||
println("|}")
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
puts(1," x")
|
||||
for i = 1 to 12 do
|
||||
printf(1," %3d",i)
|
||||
end for
|
||||
|
||||
puts(1,'\n')
|
||||
|
||||
for i = 1 to 12 do
|
||||
printf(1,"%2d",i)
|
||||
for j = 1 to 12 do
|
||||
if j<i then
|
||||
puts(1," ")
|
||||
else
|
||||
printf(1," %3d",i*j)
|
||||
end if
|
||||
end for
|
||||
puts(1,'\n')
|
||||
end for
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
[$100\>[" "]?$10\>[" "]?." "]p:
|
||||
[$p;! m: 2[$m;\>][" "1+]# [$13\>][$m;*p;!1+]#%"
|
||||
"]l:
|
||||
1[$13\>][$l;!1+]#%
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
USING: io kernel math math.parser math.ranges sequences ;
|
||||
IN: multiplication-table
|
||||
|
||||
: print-row ( n -- )
|
||||
[ number>string 2 CHAR: space pad-head write " |" write ]
|
||||
[ 1 - [ " " write ] times ]
|
||||
[
|
||||
dup 12 [a,b]
|
||||
[ * number>string 4 CHAR: space pad-head write ] with each
|
||||
] tri nl ;
|
||||
|
||||
: print-table ( -- )
|
||||
" " write
|
||||
1 12 [a,b] [ number>string 4 CHAR: space pad-head write ] each nl
|
||||
" +" write
|
||||
12 [ "----" write ] times nl
|
||||
1 12 [a,b] [ print-row ] each ;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
class Main
|
||||
{
|
||||
static Void multiplicationTable (Int n)
|
||||
{
|
||||
// print column headings
|
||||
echo (" |" + (1..n).map |Int a -> Str| { a.toStr.padl(4)}.join("") )
|
||||
echo ("-----" + (1..n).map { "----" }.join("") )
|
||||
// work through each row
|
||||
(1..n).each |i|
|
||||
{
|
||||
echo ( i.toStr.padl(4) + "|" +
|
||||
Str.spaces(4*(i-1)) +
|
||||
(i..n).map |Int j -> Str| { (i*j).toStr.padl(4)}.join("") )
|
||||
}
|
||||
}
|
||||
|
||||
public static Void main ()
|
||||
{
|
||||
multiplicationTable (12)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
: multiplication-table
|
||||
cr 2 spaces 13 2 do i 4 u.r loop
|
||||
cr
|
||||
13 2 do
|
||||
cr i 2 u.r
|
||||
13 2 do
|
||||
i j < if 4 spaces else i j * 4 u.r then
|
||||
loop
|
||||
loop ;
|
||||
19
Task/Multiplication-tables/Fortran/multiplication-tables.f
Normal file
19
Task/Multiplication-tables/Fortran/multiplication-tables.f
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
program multtable
|
||||
implicit none
|
||||
|
||||
integer :: i, j, k
|
||||
|
||||
write(*, "(a)") " x| 1 2 3 4 5 6 7 8 9 10 11 12"
|
||||
write(*, "(a)") "--+------------------------------------------------"
|
||||
do i = 1, 12
|
||||
write(*, "(i2, a)", advance="no") i, "|"
|
||||
do k = 2, i
|
||||
write(*, "(a4)", advance="no") ""
|
||||
end do
|
||||
do j = i, 12
|
||||
write(*, "(i4)", advance="no") i*j
|
||||
end do
|
||||
write(*, *)
|
||||
end do
|
||||
|
||||
end program multtable
|
||||
27
Task/Multiplication-tables/Go/multiplication-tables.go
Normal file
27
Task/Multiplication-tables/Go/multiplication-tables.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Print(" x |")
|
||||
for i := 1; i <= 12; i++ {
|
||||
fmt.Printf("%4d", i)
|
||||
}
|
||||
fmt.Print("\n---+")
|
||||
for i := 1; i <= 12; i++ {
|
||||
fmt.Print("----")
|
||||
}
|
||||
for j := 1; j <= 12; j++ {
|
||||
fmt.Printf("\n%2d |", j)
|
||||
for i := 1; i <= 12; i++ {
|
||||
if i >= j {
|
||||
fmt.Printf("%4d", i*j)
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
def printMultTable = { size = 12 ->
|
||||
assert size > 1
|
||||
|
||||
// factor1 line
|
||||
print ' |'; (1..size).each { f1 -> printf('%4d', f1) }; println ''
|
||||
|
||||
// dividing line
|
||||
print '--+'; (1..size).each { printf('----', it) }; println ''
|
||||
|
||||
// factor2 result lines
|
||||
(1..size).each { f2 ->
|
||||
printf('%2d|', f2)
|
||||
(1..<f2).each{ print ' ' }
|
||||
(f2..size).each{ f1 -> printf('%4d', f1*f2) }
|
||||
println ''
|
||||
}
|
||||
}
|
||||
|
||||
printMultTable()
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import Control.Monad
|
||||
import Text.Printf
|
||||
|
||||
main = do
|
||||
putStrLn $ " x" ++ concatMap fmt [1..12]
|
||||
zipWithM_ f [1..12] $ iterate (" " ++) ""
|
||||
where f n s = putStrLn $ fmt n ++ s ++ concatMap (fmt . (*n)) [n..12]
|
||||
fmt n = printf "%4d" (n :: Int)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
WRITE(Row=1) " x 1 2 3 4 5 6 7 8 9 10 11 12"
|
||||
DO line = 1, 12
|
||||
WRITE(Row=line+2, Format='i2') line
|
||||
DO col = line, 12
|
||||
WRITE(Row=line+2, Column=4*col, Format='i3') line*col
|
||||
ENDDO
|
||||
ENDDO
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
procedure main()
|
||||
lim := 13
|
||||
wid := 5
|
||||
every writes(right("* |" | (1 to lim) | "\n",wid)|right("\n",wid*(lim+1),"_")) # header row and separator
|
||||
every (i := 1 to lim) &
|
||||
writes(right( i||" |" | (j := 1 to lim, if j < i then "" else i*j) | "\n",wid)) # table content and triangle
|
||||
end
|
||||
19
Task/Multiplication-tables/J/multiplication-tables.j
Normal file
19
Task/Multiplication-tables/J/multiplication-tables.j
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
multtable=: <:/~ * */~
|
||||
format=: 'b4.0' 8!:2 ]
|
||||
(('*' ; ,.) ,. ({. ; ])@format@multtable) >:i.12
|
||||
┌──┬────────────────────────────────────────────────┐
|
||||
│* │ 1 2 3 4 5 6 7 8 9 10 11 12│
|
||||
├──┼────────────────────────────────────────────────┤
|
||||
│ 1│ 1 2 3 4 5 6 7 8 9 10 11 12│
|
||||
│ 2│ 4 6 8 10 12 14 16 18 20 22 24│
|
||||
│ 3│ 9 12 15 18 21 24 27 30 33 36│
|
||||
│ 4│ 16 20 24 28 32 36 40 44 48│
|
||||
│ 5│ 25 30 35 40 45 50 55 60│
|
||||
│ 6│ 36 42 48 54 60 66 72│
|
||||
│ 7│ 49 56 63 70 77 84│
|
||||
│ 8│ 64 72 80 88 96│
|
||||
│ 9│ 81 90 99 108│
|
||||
│10│ 100 110 120│
|
||||
│11│ 121 132│
|
||||
│12│ 144│
|
||||
└──┴────────────────────────────────────────────────┘
|
||||
24
Task/Multiplication-tables/Java/multiplication-tables.java
Normal file
24
Task/Multiplication-tables/Java/multiplication-tables.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
public class MulTable{
|
||||
public static void main(String args[]){
|
||||
int i,j;
|
||||
for(i=1;i<=12;i++)
|
||||
{
|
||||
System.out.print("\t"+i);
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
for(i=0;i<100;i++)
|
||||
System.out.print("-");
|
||||
System.out.println("");
|
||||
for(i=1;i<=12;i++){
|
||||
System.out.print(""+i+"|");
|
||||
for(j=1;j<=12;j++){
|
||||
if(j<i)
|
||||
System.out.print("\t");
|
||||
else
|
||||
System.out.print("\t"+i*j);
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
|
||||
<title>12 times table</title>
|
||||
<script type='text/javascript'>
|
||||
|
||||
function multiplication_table(n, target) {
|
||||
var table = document.createElement('table');
|
||||
|
||||
var row = document.createElement('tr');
|
||||
var cell = document.createElement('th');
|
||||
cell.appendChild(document.createTextNode('x'));
|
||||
row.appendChild(cell);
|
||||
for (var x = 1; x <=n; x++) {
|
||||
cell = document.createElement('th');
|
||||
cell.appendChild(document.createTextNode(x));
|
||||
row.appendChild(cell);
|
||||
}
|
||||
table.appendChild(row);
|
||||
|
||||
for (var x = 1; x <=n; x++) {
|
||||
row = document.createElement('tr');
|
||||
cell = document.createElement('th');
|
||||
cell.appendChild(document.createTextNode(x));
|
||||
row.appendChild(cell);
|
||||
var y;
|
||||
for (y = 1; y < x; y++) {
|
||||
cell = document.createElement('td');
|
||||
cell.appendChild(document.createTextNode('\u00a0'));
|
||||
row.appendChild(cell);
|
||||
}
|
||||
for (; y <= n; y++) {
|
||||
cell = document.createElement('td');
|
||||
cell.appendChild(document.createTextNode(x*y));
|
||||
row.appendChild(cell);
|
||||
}
|
||||
table.appendChild(row);
|
||||
}
|
||||
target.appendChild(table);
|
||||
}
|
||||
|
||||
</script>
|
||||
<style type='text/css'>
|
||||
body {font-family: sans-serif;}
|
||||
table {border-collapse: collapse;}
|
||||
th, td {border: 1px solid black; text-align: right; width: 4ex;}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="multiplication_table(12, document.getElementById('target'));">
|
||||
<div id='target'></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Print " | 1 2 3 4 5 6 7 8 9 10 11 12"
|
||||
Print "--+------------------------------------------------------------"
|
||||
|
||||
For i = 1 To 12
|
||||
nums$ = Right$(" " + str$(i), 2) + "|"
|
||||
For ii = 1 To 12
|
||||
If i <= ii Then
|
||||
If ii >= 1 Then
|
||||
nums$ = nums$ + Left$(" ", (5 - Len(str$(i * ii))))
|
||||
End If
|
||||
nums$ = nums$ + str$(i * ii)
|
||||
Else
|
||||
nums$ = nums$ + " "
|
||||
End If
|
||||
Next ii
|
||||
Print nums$
|
||||
Next i
|
||||
13
Task/Multiplication-tables/Logo/multiplication-tables.logo
Normal file
13
Task/Multiplication-tables/Logo/multiplication-tables.logo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
to mult.table :n
|
||||
type "| | for [i 2 :n] [type form :i 4 0] (print)
|
||||
(print)
|
||||
for [i 2 :n] [
|
||||
type form :i 2 0
|
||||
for [j 2 :n] [
|
||||
type ifelse :i > :j ["| |] [form :i*:j 4 0]
|
||||
]
|
||||
(print)
|
||||
]
|
||||
end
|
||||
|
||||
mult.table 12
|
||||
18
Task/Multiplication-tables/Lua/multiplication-tables.lua
Normal file
18
Task/Multiplication-tables/Lua/multiplication-tables.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
io.write( " |" )
|
||||
for i = 1, 12 do
|
||||
io.write( string.format( "%#5d", i ) )
|
||||
end
|
||||
io.write( "\n", string.rep( "-", 12*5+4 ), "\n" )
|
||||
|
||||
for i = 1, 12 do
|
||||
io.write( string.format( "%#2d |", i ) )
|
||||
|
||||
for j = 1, 12 do
|
||||
if j < i then
|
||||
io.write( " " )
|
||||
else
|
||||
io.write( string.format( "%#5d", i*j ) )
|
||||
end
|
||||
end
|
||||
io.write( "\n" )
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function table = timesTable(N)
|
||||
table = [(0:N); (1:N)' triu( kron((1:N),(1:N)') )];
|
||||
end
|
||||
17
Task/Multiplication-tables/MATLAB/multiplication-tables-2.m
Normal file
17
Task/Multiplication-tables/MATLAB/multiplication-tables-2.m
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function table = timesTable(N)
|
||||
|
||||
%Generates a column vector with integers from 1 to N
|
||||
rowLabels = (1:N)';
|
||||
|
||||
%Generate a row vector with integers from 0 to N
|
||||
columnLabels = (0:N);
|
||||
|
||||
%Generate the multiplication table using the kronecker tensor product
|
||||
%of two vectors one a column vector and the other a row vector
|
||||
table = kron((1:N),(1:N)');
|
||||
|
||||
%Make it upper triangular and concatenate the rowLabels and
|
||||
%columnLabels to the table
|
||||
table = [columnLabels; rowLabels triu(table)];
|
||||
|
||||
end
|
||||
17
Task/Multiplication-tables/MATLAB/multiplication-tables-3.m
Normal file
17
Task/Multiplication-tables/MATLAB/multiplication-tables-3.m
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
timesTable(12)
|
||||
|
||||
ans =
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
1 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
2 0 4 6 8 10 12 14 16 18 20 22 24
|
||||
3 0 0 9 12 15 18 21 24 27 30 33 36
|
||||
4 0 0 0 16 20 24 28 32 36 40 44 48
|
||||
5 0 0 0 0 25 30 35 40 45 50 55 60
|
||||
6 0 0 0 0 0 36 42 48 54 60 66 72
|
||||
7 0 0 0 0 0 0 49 56 63 70 77 84
|
||||
8 0 0 0 0 0 0 0 64 72 80 88 96
|
||||
9 0 0 0 0 0 0 0 0 81 90 99 108
|
||||
10 0 0 0 0 0 0 0 0 0 100 110 120
|
||||
11 0 0 0 0 0 0 0 0 0 0 121 132
|
||||
12 0 0 0 0 0 0 0 0 0 0 0 144
|
||||
25
Task/Multiplication-tables/MOO/multiplication-tables-1.moo
Normal file
25
Task/Multiplication-tables/MOO/multiplication-tables-1.moo
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
@verb me:@tables none none none rxd
|
||||
@program me:@tables
|
||||
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
|
||||
player:tell("-------------------------------------------------------------------");
|
||||
for i in [1..12]
|
||||
line = ((i < 10) ? " " | " ") + tostr(i) + " | ";
|
||||
for j in [1..12]
|
||||
if (j >= i)
|
||||
product = i * j;
|
||||
"calculate spacing for right justification of values";
|
||||
if (product >= 100)
|
||||
spacer = "";
|
||||
elseif (product >= 10)
|
||||
spacer = " ";
|
||||
else
|
||||
spacer = " ";
|
||||
endif
|
||||
line = line + " " + spacer + tostr(product);
|
||||
else
|
||||
line = line + " ";
|
||||
endif
|
||||
endfor
|
||||
player:tell(line);
|
||||
endfor
|
||||
.
|
||||
11
Task/Multiplication-tables/MOO/multiplication-tables-2.moo
Normal file
11
Task/Multiplication-tables/MOO/multiplication-tables-2.moo
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@program me:@tables
|
||||
player:tell(" | 1 2 3 4 5 6 7 8 9 10 11 12");
|
||||
player:tell($string_utils:space(67, "-"));
|
||||
for i in [1..12]
|
||||
line = " " + $string_utils:right(i, 2) + " | ";
|
||||
for j in [1..12]
|
||||
line = line + " " + ((i > j) ? " " | $string_utils:right(j*i, 3));
|
||||
endfor
|
||||
player:tell(line);
|
||||
endfor
|
||||
.
|
||||
21
Task/Multiplication-tables/MUMPS/multiplication-tables.mumps
Normal file
21
Task/Multiplication-tables/MUMPS/multiplication-tables.mumps
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MULTTABLE(SIZE)
|
||||
;Print out a multiplication table
|
||||
;SIZE is the size of the multiplication table to make
|
||||
;MW is the maximum width of the numbers
|
||||
;D is the down axis
|
||||
;A is the across axis
|
||||
;BAR is the horizontal bar under the operands
|
||||
NEW MW,D,A,BAR
|
||||
IF $DATA(SIZE)<1 SET SIZE=12
|
||||
SET MW=$LENGTH(SIZE*SIZE)
|
||||
SET BAR="" FOR I=1:1:(MW+2) SET BAR=BAR_"-"
|
||||
FOR D=1:1:(SIZE+2) DO
|
||||
.FOR A=1:1:(SIZE+1) DO
|
||||
..WRITE:(D=1)&(A=1) !,$JUSTIFY("",MW-1)," X|"
|
||||
..WRITE:(D=1)&(A>1) ?((A-1)*5),$JUSTIFY((A-1),MW)
|
||||
..WRITE:(D=2)&(A=1) !,BAR
|
||||
..WRITE:(D=2)&(A'=1) BAR
|
||||
..WRITE:(D>2)&(A=1) !,$JUSTIFY((D-2),MW)," |"
|
||||
..WRITE:((A-1)>=(D-2))&((D-2)>=1) ?((A-1)*5),$JUSTIFY((D-2)*(A-1),MW)
|
||||
KILL MW,D,A,BAR
|
||||
QUIT
|
||||
|
|
@ -0,0 +1 @@
|
|||
Grid[{{Range[12]//Column,Grid[UpperTriangularize[KroneckerProduct[Range[12],Range[12]]]/.{0->""}]}}]
|
||||
10
Task/Multiplication-tables/Perl/multiplication-tables.pl
Normal file
10
Task/Multiplication-tables/Perl/multiplication-tables.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
our $max = 12;
|
||||
our $width = length($max**2) + 1;
|
||||
|
||||
printf "%*s", $width, $_ foreach 'x|', 1..$max;
|
||||
print "\n", '-' x ($width - 1), '+', '-' x ($max*$width), "\n";
|
||||
foreach my $i (1..$max) {
|
||||
printf "%*s", $width, $_
|
||||
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max;
|
||||
print "\n";
|
||||
}
|
||||
14
Task/Multiplication-tables/PicoLisp/multiplication-tables.l
Normal file
14
Task/Multiplication-tables/PicoLisp/multiplication-tables.l
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(de mulTable (N)
|
||||
(space 4)
|
||||
(for X N
|
||||
(prin (align 4 X)) )
|
||||
(prinl)
|
||||
(prinl)
|
||||
(for Y N
|
||||
(prin (align 4 Y))
|
||||
(space (* (dec Y) 4))
|
||||
(for (X Y (>= N X) (inc X))
|
||||
(prin (align 4 (* X Y))) )
|
||||
(prinl) ) )
|
||||
|
||||
(mulTable 12)
|
||||
29
Task/Multiplication-tables/Python/multiplication-tables.py
Normal file
29
Task/Multiplication-tables/Python/multiplication-tables.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
>>> size = 12
|
||||
>>> width = len(str(size**2))
|
||||
>>> for row in range(-1,size+1):
|
||||
if row==0:
|
||||
print("─"*width + "┼"+"─"*((width+1)*size-1))
|
||||
else:
|
||||
print("".join("%*s%1s" % ((width,) + (("x","│") if row==-1 and col==0
|
||||
else (row,"│") if row>0 and col==0
|
||||
else (col,"") if row==-1
|
||||
else ("","") if row>col
|
||||
else (row*col,"")))
|
||||
for col in range(size+1)))
|
||||
|
||||
|
||||
x│ 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
───┼───────────────────────────────────────────────
|
||||
1│ 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
2│ 4 6 8 10 12 14 16 18 20 22 24
|
||||
3│ 9 12 15 18 21 24 27 30 33 36
|
||||
4│ 16 20 24 28 32 36 40 44 48
|
||||
5│ 25 30 35 40 45 50 55 60
|
||||
6│ 36 42 48 54 60 66 72
|
||||
7│ 49 56 63 70 77 84
|
||||
8│ 64 72 80 88 96
|
||||
9│ 81 90 99 108
|
||||
10│ 100 110 120
|
||||
11│ 121 132
|
||||
12│ 144
|
||||
>>>
|
||||
1
Task/Multiplication-tables/R/multiplication-tables-1.r
Normal file
1
Task/Multiplication-tables/R/multiplication-tables-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
upper.tri(1:12 %o% 1:12, diag = TRUE) * 1:12 %o% 1:12
|
||||
10
Task/Multiplication-tables/R/multiplication-tables-2.r
Normal file
10
Task/Multiplication-tables/R/multiplication-tables-2.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
multiplication_table <- function(n=12)
|
||||
{
|
||||
one_to_n <- 1:n
|
||||
x <- matrix(one_to_n) %*% t(one_to_n)
|
||||
x[lower.tri(x)] <- 0
|
||||
rownames(x) <- colnames(x) <- one_to_n
|
||||
print(as.table(x), zero.print="")
|
||||
invisible(x)
|
||||
}
|
||||
multiplication_table()
|
||||
83
Task/Multiplication-tables/REXX/multiplication-tables.rexx
Normal file
83
Task/Multiplication-tables/REXX/multiplication-tables.rexx
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*REXX program displays a 12x12 multiplication boxed grid table, grid */
|
||||
/* will be displayed in "boxing" characters for ASCII or EBCDIC.*/
|
||||
parse arg high . /*get optional grid size. */
|
||||
if high=='' then high=12 /*not specified? Use default. */
|
||||
ebcdic='f0'==1 /*is this an EBCDIC machine? */
|
||||
|
||||
if ebcdic then do /*══════════EBCDIC═══════════════*/
|
||||
bar='fa'x /*vertical bar. */
|
||||
dash='bf'x /*horizontal dash. */
|
||||
bj ='cb'x /*bottom junction. */
|
||||
tj ='cc'x /* top junction. */
|
||||
cj ='8f'x /*center junction (cross). */
|
||||
lj ='eb'x /* left junction. */
|
||||
rj ='ec'x /* right junction. */
|
||||
tlc='ac'x /*top left corner. */
|
||||
trc='bc'x /*top right corner. */
|
||||
blc='ab'x /*bottom left corner. */
|
||||
brc='bb'x /*bottom right corner. */
|
||||
end
|
||||
else do /*══════════ASCII════════════════*/
|
||||
bar='b3'x /*vertical bar. */
|
||||
dash='c4'x /*horizontal dash. */
|
||||
bj ='c1'x /*bottom junction. */
|
||||
tj ='c2'x /* top junction. */
|
||||
cj ='c5'x /*center junction (cross). */
|
||||
lj ='c3'x /* left junction. */
|
||||
rj ='b4'x /* right junction. */
|
||||
tlc='da'x /*top left corner. */
|
||||
trc='bf'x /*top right corner. */
|
||||
blc='c0'x /*bottom left corner. */
|
||||
brc='d9'x /*bottom right corner. */
|
||||
end
|
||||
|
||||
cell=cj || copies(dash,5) /*define the top of the cell. */
|
||||
sep=copies(cell,high+1)rj /*build the table separator. */
|
||||
sepL=length(sep) /*length of separator line. */
|
||||
width=length(cell)-1 /*width of the table cells. */
|
||||
size=width-1 /*width for table numbers. */
|
||||
box.=left('',width) /*construct all the cells. */
|
||||
|
||||
do j=0 to high /*step through zero to H (12). */
|
||||
_=right(j,size-1)'x ' /*build "label"/border number. */
|
||||
box.0.j=_ /*build top label cell. */
|
||||
box.j.0=_ /*build left label cell. */
|
||||
end /*j*/
|
||||
|
||||
box.0.0=centre('times',width) /*redefine box.0.0 with 'X'. */
|
||||
|
||||
do row=1 for high /*step through 1 to H (12). */
|
||||
do col=row to high /*step through row to H (12). */
|
||||
box.row.col=right(row*col,size)' ' /*build a mult. cell. */
|
||||
end /*col*/
|
||||
end /*row*/
|
||||
|
||||
do row=0 to high /*step through all the lines. */
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
if row==0 then do
|
||||
asep=overlay(tlc,asep,1) /*make a better tlc. */
|
||||
asep=overlay(trc,asep,sepL) /*make a better trc. */
|
||||
asep=translate(asep,tj,cj) /*make a better tj. */
|
||||
end
|
||||
else asep=overlay(lj,asep,1) /*make a better lj. */
|
||||
|
||||
say asep /*display a table grid line. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
call buildLine row /*build one line of the grid. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
end /*row*/
|
||||
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
asep=overlay(blc,asep,1) /*make a better bot left corner.*/
|
||||
asep=overlay(brc,asep,sepL) /*make a better bot right corner.*/
|
||||
asep=translate(asep,bj,cj) /*make a better bot junction. */
|
||||
say asep /*display a table grid line. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────BUILDLINE subroutine────────────────*/
|
||||
buildLine: w=; parse arg arow /*start with a blank cell. */
|
||||
|
||||
do col=0 to high /*step through 0 to H (12). */
|
||||
w=w||bar||box.arow.col /*build one cell at a time. */
|
||||
end /*col*/
|
||||
say w || bar /*finish building the last cell. */
|
||||
return
|
||||
11
Task/Multiplication-tables/Ruby/multiplication-tables.rb
Normal file
11
Task/Multiplication-tables/Ruby/multiplication-tables.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def multiplication_table(n)
|
||||
puts " " + ((" %3d" * n) % (1..n).to_a)
|
||||
1.upto(n) do |x|
|
||||
print "%3d " % x
|
||||
1.upto(x-1) {|y| print " "}
|
||||
x.upto(n) {|y| print " %3d" % (x*y)}
|
||||
puts ""
|
||||
end
|
||||
end
|
||||
|
||||
multiplication_table 12
|
||||
26
Task/Multiplication-tables/Scheme/multiplication-tables.ss
Normal file
26
Task/Multiplication-tables/Scheme/multiplication-tables.ss
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(define iota
|
||||
(lambda (count start step)
|
||||
(let loop ((result (list (+ start (* (- count 1) step)))))
|
||||
(let ((acc (car result)))
|
||||
(if (= acc start)
|
||||
result
|
||||
(loop (cons (- acc step) result)))))))
|
||||
|
||||
|
||||
(define table
|
||||
(lambda (x)
|
||||
(let loop ((count 1)
|
||||
(numbers (iota x 1 1)))
|
||||
(if (not (null? numbers))
|
||||
(begin
|
||||
(display (make-string (* 6 (- count 1)) #\space))
|
||||
(for-each
|
||||
(lambda (n)
|
||||
(let ((number (number->string (* n count))))
|
||||
(display (string-append
|
||||
(make-string (- 6 (string-length number)) #\space)
|
||||
number))))
|
||||
numbers)
|
||||
(newline)
|
||||
(loop (+ count 1)
|
||||
(cdr numbers)))))))
|
||||
11
Task/Multiplication-tables/Tcl/multiplication-tables.tcl
Normal file
11
Task/Multiplication-tables/Tcl/multiplication-tables.tcl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
puts " x\u2502 1 2 3 4 5 6 7 8 9 10 11 12"
|
||||
puts \u0020\u2500\u2500\u253c[string repeat \u2500 48]
|
||||
for {set i 1} {$i <= 12} {incr i} {
|
||||
puts -nonewline [format "%3d" $i]\u2502[string repeat " " [expr {$i*4-4}]]
|
||||
for {set j 1} {$j <= 12} {incr j} {
|
||||
if {$j >= $i} {
|
||||
puts -nonewline [format "%4d" [expr {$i*$j}]]
|
||||
}
|
||||
}
|
||||
puts ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue