Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,20 @@
function timesTable(){
let output = "";
const size = 12;
for(let i = 1; i <= size; i++){
output += i.toString().padStart(3);
output += i !== size ? " " : "\n";
}
for(let i = 0; i <= size; i++)
output += i !== size ? "════" : "╕\n";
for(let i = 1; i <= size; i++){
for(let j = 1; j <= size; j++){
output += j < i
? " "
: (i * j).toString().padStart(3) + " ";
}
output += `${i}\n`;
}
return output;
}

View file

@ -0,0 +1,50 @@
<!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>

View file

@ -0,0 +1,45 @@
(function (m, n) {
// [m..n]
function range(m, n) {
return Array.apply(null, Array(n - m + 1)).map(function (x, i) {
return m + i;
});
}
// Monadic bind (chain) for lists
function mb(xs, f) {
return [].concat.apply([], xs.map(f));
}
var rng = range(m, n),
lstTable = [['x'].concat( rng )]
.concat(mb(rng, function (x) {
return [[x].concat(mb(rng, function (y) {
return y < x ? [''] : [x * y]; // triangle only
}))]}));
/* FORMATTING OUTPUT */
// [[a]] -> bool -> s -> s
function wikiTable(lstRows, blnHeaderRow, strStyle) {
return '{| class="wikitable" ' + (
strStyle ? 'style="' + strStyle + '"' : ''
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
}).join(' ' + strDelim + strDelim + ' ');
}).join('') + '\n|}';
}
// Formatted as WikiTable
return wikiTable(
lstTable, true,
'text-align:center;width:33em;height:33em;table-layout:fixed;'
) + '\n\n' +
// or simply stringified as JSON
JSON.stringify(lstTable);
})(1, 12);

View file

@ -0,0 +1,13 @@
[["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]]

View file

@ -0,0 +1,74 @@
(() => {
"use strict";
// -------------- MULTIPLICATION TABLE ---------------
// multTable :: Int -> Int -> [[String]]
const multTable = m => n => {
const xs = enumFromTo(m)(n);
return [
["x", ...xs],
...xs.flatMap(
x => [
[x, ...xs.flatMap(
y => y < x ? (
[""]
) : [`${x * y}`]
)]
]
)
];
};
// ---------------------- TEST -----------------------
// main :: () -> IO String
const main = () =>
wikiTable({
class: "wikitable",
style: [
"text-align:center",
"width:33em",
"height:33em",
"table-layout:fixed"
].join(";")
})(
multTable(1)(12)
);
// ---------------- GENERIC FUNCTIONS ----------------
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = m => n =>
n >= m ? Array.from({
length: Math.floor(n - m) + 1
}, (_, i) => m + i) : [];
// ------------------- FORMATTING --------------------
// wikiTable :: Dict -> [[a]] -> String
const wikiTable = opts =>
rows => {
const
style = ["class", "style"].reduce(
(a, k) => k in opts ? (
`${a}${k}="${opts[k]}" `
) : a, ""
),
body = rows.map((row, i) => {
const
cells = row.map(
x => `${x}` || " "
).join(" || ");
return `${i ? "|" : "!"} ${cells}`;
}).join("\n|-\n");
return `{| ${style}\n${body}\n|}`;
};
// MAIN ---
return main();
})();