Enjoy.
( Forth program for making HTML multiplication tables )
( Joel Matthew Rees, October 2018, Amagasaki, Japan )
( Copyright 2018 Joel Matthew Rees )
( Permission granted for private, non-profit use. )
( Runs in gforth. Should run in almost any Forth. )
: decout ( n --- )
base @ swap
10 base ! 1 .R
base ! ;
: colheadout ( percentwidth n --- )
over ." <th align='center' width='" decout ." %'>"
1 .R ." </th>" ;
: hrow ( percentwidth limit --- )
0 do i colheadout loop drop ;
: headrow ( percentwidth limit --- )
." <tr>" CR ." <th>×</th>" hrow CR ." </tr>" CR ;
: thout ( n --- )
." <th align='center'>" 1 .R ." </th>" ;
: tdout ( n --- )
." <td align='center'>" 1 .R ." </td>" ;
: row ( limit current --- limit )
over 0 do dup i * tdout loop drop ;
: fullrow ( limit current --- limit )
." <tr>" CR dup thout row CR ." </tr>" CR ;
: htmltable ( base --- )
CR ." <table border='1'>" CR
base @ >R
dup base !
3 + ( limit )
100 over 1 + / ( width in percent )
over headrow
dup 0 do
i fullrow
loop
drop
R> base !
." </table>" CR
;
: maketables
1+ 2 do
." <br />" CR
i 1 .R ." s table:<br />" CR
i htmltable
loop ;
The results of running "10 maketables" (copied from terminal window and pasted as-is into Blogger's HTML edit mode):
2s table:
× | 0 | 1 | 10 | 11 | 100 |
---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 10 | 11 | 100 |
10 | 0 | 10 | 100 | 110 | 1000 |
11 | 0 | 11 | 110 | 1001 | 1100 |
100 | 0 | 100 | 1000 | 1100 | 10000 |
3s table:
× | 0 | 1 | 2 | 10 | 11 | 12 |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 10 | 11 | 12 |
2 | 0 | 2 | 11 | 20 | 22 | 101 |
10 | 0 | 10 | 20 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 110 | 121 | 202 |
12 | 0 | 12 | 101 | 120 | 202 | 221 |
4s table:
× | 0 | 1 | 2 | 3 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 10 | 11 | 12 |
2 | 0 | 2 | 10 | 12 | 20 | 22 | 30 |
3 | 0 | 3 | 12 | 21 | 30 | 33 | 102 |
10 | 0 | 10 | 20 | 30 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 110 | 121 | 132 |
12 | 0 | 12 | 30 | 102 | 120 | 132 | 210 |
5s table:
× | 0 | 1 | 2 | 3 | 4 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 11 | 13 | 20 | 22 | 24 |
3 | 0 | 3 | 11 | 14 | 22 | 30 | 33 | 41 |
4 | 0 | 4 | 13 | 22 | 31 | 40 | 44 | 103 |
10 | 0 | 10 | 20 | 30 | 40 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 41 | 103 | 120 | 132 | 144 |
6s table:
× | 0 | 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 10 | 12 | 14 | 20 | 22 | 24 |
3 | 0 | 3 | 10 | 13 | 20 | 23 | 30 | 33 | 40 |
4 | 0 | 4 | 12 | 20 | 24 | 32 | 40 | 44 | 52 |
5 | 0 | 5 | 14 | 23 | 32 | 41 | 50 | 55 | 104 |
10 | 0 | 10 | 20 | 30 | 40 | 50 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 55 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 40 | 52 | 104 | 120 | 132 | 144 |
7s table:
× | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 6 | 11 | 13 | 15 | 20 | 22 | 24 |
3 | 0 | 3 | 6 | 12 | 15 | 21 | 24 | 30 | 33 | 36 |
4 | 0 | 4 | 11 | 15 | 22 | 26 | 33 | 40 | 44 | 51 |
5 | 0 | 5 | 13 | 21 | 26 | 34 | 42 | 50 | 55 | 63 |
6 | 0 | 6 | 15 | 24 | 33 | 42 | 51 | 60 | 66 | 105 |
10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 55 | 66 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 36 | 51 | 63 | 105 | 120 | 132 | 144 |
8s table:
× | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 6 | 10 | 12 | 14 | 16 | 20 | 22 | 24 |
3 | 0 | 3 | 6 | 11 | 14 | 17 | 22 | 25 | 30 | 33 | 36 |
4 | 0 | 4 | 10 | 14 | 20 | 24 | 30 | 34 | 40 | 44 | 50 |
5 | 0 | 5 | 12 | 17 | 24 | 31 | 36 | 43 | 50 | 55 | 62 |
6 | 0 | 6 | 14 | 22 | 30 | 36 | 44 | 52 | 60 | 66 | 74 |
7 | 0 | 7 | 16 | 25 | 34 | 43 | 52 | 61 | 70 | 77 | 106 |
10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 36 | 50 | 62 | 74 | 106 | 120 | 132 | 144 |
9s table:
× | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 6 | 8 | 11 | 13 | 15 | 17 | 20 | 22 | 24 |
3 | 0 | 3 | 6 | 10 | 13 | 16 | 20 | 23 | 26 | 30 | 33 | 36 |
4 | 0 | 4 | 8 | 13 | 17 | 22 | 26 | 31 | 35 | 40 | 44 | 48 |
5 | 0 | 5 | 11 | 16 | 22 | 27 | 33 | 38 | 44 | 50 | 55 | 61 |
6 | 0 | 6 | 13 | 20 | 26 | 33 | 40 | 46 | 53 | 60 | 66 | 73 |
7 | 0 | 7 | 15 | 23 | 31 | 38 | 46 | 54 | 62 | 70 | 77 | 85 |
8 | 0 | 8 | 17 | 26 | 35 | 44 | 53 | 62 | 71 | 80 | 88 | 107 |
10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 36 | 48 | 61 | 73 | 85 | 107 | 120 | 132 | 144 |
10s table:
× | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 |
3 | 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 |
4 | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 |
5 | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 |
6 | 0 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 66 | 72 |
7 | 0 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 | 77 | 84 |
8 | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 |
9 | 0 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 | 99 | 108 |
10 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 | 110 | 120 |
11 | 0 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 | 99 | 110 | 121 | 132 |
12 | 0 | 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 | 108 | 120 | 132 | 144 |
No comments:
Post a Comment