学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
数学読本〈4〉数列の極限,順列/順列・組合せ/確率/関数の極限と微分法(松坂 和夫(著)、岩波書店)の第15章(「場合の数」 を数える - 順列・組合せ)、15.3(二項定理)、二項定理の応用、二項係数の性質、問40、41、42.を取り組んでみる。
コード(Emacs)
HTML5
<button id="run0">run</button> <button id="clear0">clear</button> <pre id="output0"></pre> <script src="sample40.js"></script>
JavaScript
let btn0 = document.querySelector('#run0'),
btn1 = document.querySelector('#clear0'),
pre0 = document.querySelector('#output0'),
p = (x) => pre0.textContent += x + '\n';
let range = (start, end, step=1) => {
let iter = (i, result) => {
return i >= end ? result : iter(i + step, result.concat([i]));
}
return iter(start, []);
};
let factorial = (n) => {
return n <= 1 ? 1 : n * factorial(n - 1);
};
let combination = (n, r) => {
return factorial(n) / (factorial(r) * factorial(n - r));
};
let term = (n, i) => i * combination(n, i),
f = (n) => range(1, n + 1).map((i) => term(n, i)).reduce((x, y) => x + y);
let output = () => {
p('40-1.');
let r = Math.floor(Math.random() * 100) + 1,
n = r + Math.floor(Math.random()) + 1;
p(`${r * combination(n, r)} === ${n * combination(n - 1, r - 1)}: ` +
`${r * combination(n, r) === n * combination(n - 1, r - 1)}`);
p('40-2.');
n = Math.floor(Math.random() * 100);
p(`${n * Math.pow(2, n - 1)} === ${f(n)}: ` +
`${n * Math.pow(2, n - 1) === f(n)}`);
p('42.');
n = Math.floor(Math.random() * 100) + 2;
p(range(0, n + 1).map((i) => Math.floor(combination(n, i))));
};
btn0.onclick = output;
btn1.onclick = () => {
pre0.textContent = '';
};
output();
0 コメント:
コメントを投稿