June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,17 @@
|
|||
10 ' Multiplication Tables
|
||||
20 LET N% = 12
|
||||
30 FOR J% = 1 TO N% - 1
|
||||
40 PRINT USING "###"; J%;
|
||||
50 PRINT " ";
|
||||
60 NEXT J%
|
||||
70 PRINT USING "###"; N%
|
||||
80 FOR J% = 0 TO N% - 1
|
||||
90 PRINT "----";
|
||||
100 NEXT J%
|
||||
110 PRINT "+"
|
||||
120 FOR I% = 1 TO N%
|
||||
130 FOR J% = 1 TO N%
|
||||
140 IF J% < I% THEN PRINT " "; ELSE PRINT USING "###"; I% * J%;: PRINT " ";
|
||||
150 NEXT J%
|
||||
160 PRINT "| "; USING "##"; I%
|
||||
170 NEXT I%
|
||||
21
Task/Multiplication-tables/HolyC/multiplication-tables.holyc
Normal file
21
Task/Multiplication-tables/HolyC/multiplication-tables.holyc
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
U8 i, j, n = 12;
|
||||
for (j = 1; j <= n; j++)
|
||||
if (j != n)
|
||||
Print("%3d%c", j, ' ');
|
||||
else
|
||||
Print("%3d%c", j, '\n');
|
||||
|
||||
for (j = 0; j <= n; j++)
|
||||
if (j != n)
|
||||
Print("----");
|
||||
else
|
||||
Print("+\n");
|
||||
|
||||
for (i = 1; i <= n; i++) {
|
||||
for (j = 1; j <= n; j++)
|
||||
if (j < i)
|
||||
Print(" ");
|
||||
else
|
||||
Print("%3d ", i * j);
|
||||
Print("| %d\n", i);
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
(() => {
|
||||
|
||||
// multTable :: Int -> Int -> [[String]]
|
||||
const multTable = (m, n) => {
|
||||
const xs = enumFromToInt(m, n);
|
||||
return [
|
||||
['x', ...xs],
|
||||
...concatMap(
|
||||
x => [
|
||||
[x, ...concatMap(
|
||||
y => y < x ? [''] : [x * y],
|
||||
xs
|
||||
)]
|
||||
],
|
||||
xs
|
||||
)
|
||||
];
|
||||
};
|
||||
|
||||
// main :: () -> IO String
|
||||
const main = () => {
|
||||
return wikiTable(
|
||||
multTable(1, 12), true,
|
||||
'text-align:center;width:33em;height:33em;table-layout:fixed;'
|
||||
);
|
||||
};
|
||||
|
||||
// GENERIC FUNCTIONS -----------------------------------------------------
|
||||
|
||||
// Tuple (,) :: a -> b -> (a, b)
|
||||
const Tuple = (a, b) => ({
|
||||
type: 'Tuple',
|
||||
'0': a,
|
||||
'1': b
|
||||
});
|
||||
|
||||
// Size of space -> filler Char -> String -> Centered String
|
||||
// center :: Int -> Char -> String -> String
|
||||
const center = (n, c, s) => {
|
||||
const
|
||||
qr = quotRem(n - s.length, 2),
|
||||
q = qr[0];
|
||||
return concat(concat([replicate(q, c), s, replicate(q + qr[1], c)]));
|
||||
};
|
||||
|
||||
// concat :: [[a]] -> [a]
|
||||
// concat :: [String] -> String
|
||||
const concat = xs =>
|
||||
xs.length > 0 ? (() => {
|
||||
const unit = typeof xs[0] === 'string' ? '' : [];
|
||||
return unit.concat.apply(unit, xs);
|
||||
})() : [];
|
||||
|
||||
// concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
const concatMap = (f, xs) => [].concat.apply([], xs.map(f));
|
||||
|
||||
// enumFromToInt :: Int -> Int -> [Int]
|
||||
const enumFromToInt = (m, n) =>
|
||||
n >= m ? Array.from({
|
||||
length: Math.floor(n - m) + 1
|
||||
}, (_, i) => m + i) : [];
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = (f, xs) => xs.map(f);
|
||||
|
||||
// quotRem :: Int -> Int -> (Int, Int)
|
||||
const quotRem = (m, n) => Tuple(Math.floor(m / n), m % n);
|
||||
|
||||
// replicate :: Int -> a -> [a]
|
||||
const replicate = (n, x) =>
|
||||
Array.from({
|
||||
length: n
|
||||
}, () => x);
|
||||
|
||||
// FORMATTING -------------------------------------------------------------
|
||||
|
||||
// wikiTable :: [[a]] -> Bool -> String -> String
|
||||
const wikiTable = (rows, blnHeader, style) =>
|
||||
'{| class="wikitable" ' + (
|
||||
style ? 'style="' + style + '"' : ''
|
||||
) + rows.map((row, i) => {
|
||||
const dlm = ((blnHeader && !i) ? '!' : '|');
|
||||
return '\n|-\n' + dlm + ' ' + row.map(v =>
|
||||
typeof v !== 'undefined' ? v : ' '
|
||||
)
|
||||
.join(' ' + dlm + dlm + ' ');
|
||||
})
|
||||
.join('') + '\n|}';
|
||||
|
||||
// MAIN ------------------------------------------------------------------
|
||||
return main();
|
||||
})();
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
MODULE MultiplicationTables;
|
||||
|
||||
FROM SWholeIO IMPORT
|
||||
WriteInt;
|
||||
FROM STextIO IMPORT
|
||||
WriteString, WriteLn;
|
||||
|
||||
CONST
|
||||
N = 12;
|
||||
|
||||
VAR
|
||||
I, J: INTEGER;
|
||||
|
||||
BEGIN
|
||||
FOR J := 1 TO N - 1 DO
|
||||
WriteInt(J, 3);
|
||||
WriteString(" ");
|
||||
END;
|
||||
WriteInt(N, 3);
|
||||
WriteLn;
|
||||
FOR J := 0 TO N - 1 DO
|
||||
WriteString("----");
|
||||
END;
|
||||
WriteString("+");
|
||||
WriteLn;
|
||||
FOR I := 1 TO N DO
|
||||
FOR J := 1 TO N DO
|
||||
IF J < I THEN
|
||||
WriteString(" ");
|
||||
ELSE
|
||||
WriteInt(I * J, 3);
|
||||
WriteString(" ");
|
||||
END;
|
||||
END;
|
||||
WriteString("| ");
|
||||
WriteInt(I, 2);
|
||||
WriteLn;
|
||||
END;
|
||||
END MultiplicationTables.
|
||||
29
Task/Multiplication-tables/VBA/multiplication-tables.vba
Normal file
29
Task/Multiplication-tables/VBA/multiplication-tables.vba
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Multiplication_Tables()
|
||||
Dim strTemp As String, strBuff As String
|
||||
Dim i&, j&, NbDigits As Byte
|
||||
|
||||
'You can adapt the following const :
|
||||
Const NB_END As Byte = 12
|
||||
|
||||
Select Case NB_END
|
||||
Case Is < 10: NbDigits = 3
|
||||
Case 10 To 31: NbDigits = 4
|
||||
Case 31 To 100: NbDigits = 5
|
||||
Case Else: MsgBox "Number too large": Exit Sub
|
||||
End Select
|
||||
strBuff = String(NbDigits, " ")
|
||||
|
||||
For i = 1 To NB_END
|
||||
strTemp = Right(strBuff & i, NbDigits)
|
||||
For j = 2 To NB_END
|
||||
If j < i Then
|
||||
strTemp = strTemp & strBuff
|
||||
Else
|
||||
strTemp = strTemp & Right(strBuff & j * i, NbDigits)
|
||||
End If
|
||||
Next j
|
||||
Debug.Print strTemp
|
||||
Next i
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue