UserScriptで毎回値の変わる100マス計算表を作りたい
100マス計算表って何に使うんですか?


あー、私が暗算できないので脳トレとして使うんです

いくつになっても7+5と8+5がわからなくて.....10の位と1の位を忘れてしまうんですよね

ほい

script.jsconst range = n => [...Array(n).keys()]
function getUniqueNum(max, len) {
const nums = new Set();
while(nums.size < len) {
nums.add(Math.floor(Math.random() * max) + 1);
}
return [...nums]
}
const row = getUniqueNum(10,10)
const col = getUniqueNum(10,10)
const cells = range(10).map( (i) => range(10).map( j => row[j] * col[i]))
function addHeader(row, col, cells) {
return [
["", ...row],
...cells.map( (_row,i) => [col[i], ..._row] ),
]
}
const tableToCsv = table => table.map( row => row.join("\t") ).join(`\n`)
text = tableToCsv(addHeader(row, col, cells))
console.log(text)
navigator.clipboard.writeText(text)
a | 10 | 8 | 6 | 7 | 5 | 3 | 1 | 4 | 2 | 9 |
1 | 10 | 8 | 6 | 7 | 5 | 3 | 1 | 4 | 2 | 9 |
6 | 60 | 48 | 36 | 42 | 30 | 18 | 6 | 24 | 12 | 54 |
7 | 70 | 56 | 42 | 49 | 35 | 21 | 7 | 28 | 14 | 63 |
2 | 20 | 16 | 12 | 14 | 10 | 6 | 2 | 8 | 4 | 18 |
3 | 30 | 24 | 18 | 21 | 15 | 9 | 3 | 12 | 6 | 27 |
10 | 100 | 80 | 60 | 70 | 50 | 30 | 10 | 40 | 20 | 90 |
5 | 50 | 40 | 30 | 35 | 25 | 15 | 5 | 20 | 10 | 45 |
9 | 90 | 72 | 54 | 63 | 45 | 27 | 9 | 36 | 18 | 81 |
4 | 40 | 32 | 24 | 28 | 20 | 12 | 4 | 16 | 8 | 36 |
8 | 80 | 64 | 48 | 56 | 40 | 24 | 8 | 32 | 16 | 72 |