学習環境
- 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.2(組合せ)、同じものがあるときの順列、問19、20、21、22、23.を取り組んでみる。
コード(Emacs)
HTML5
<button id="run0">run</button> <button id="clear0">clear</button> <pre id="output0"></pre> <script src="sample19.js"></script>
JavaScript
let btn0 = document.querySelector('#run0'),
btn1 = document.querySelector('#clear0'),
pre0 = document.querySelector('#output0');
let permutation = (n, r) => {
let iter = (i, result) => {
if (i > n) {
return result;
}
return iter(i + 1, i * result);
};
return iter(n - (r - 1) , 1);
};
let factorial = (n) => {
return n <= 1 ? 1 : n * factorial(n - 1);
};
let combination = (n, r) => {
return factorial(n) / (factorial(r) * factorial(n - r));
};
let output = () => {
pre0.textContent =
'19.\n' +
`${factorial(8) / (factorial(3) * factorial(2))}\n` +
'20.\n' +
`${combination(8, 4)}\n` +
'21.\n' +
`${permutation(5, 3) + 3 * permutation(5, 2) + 3 * 5 + 1}\n` +
'22-1.\n' +
`${combination(10, 4)}\n` +
'22-2.\n' +
`${1/2 * (210 - combination(5, 2)) + combination(5, 2)}\n` +
'23-1.\n' +
`${combination(11, 5)}\n` +
'23-2.\n' +
`${combination(7, 3) * combination(4, 2)}\n` +
'23-3.\n' +
`${462 - 210}\n` +
'23-4.\n' +
`${210 - combination(4, 2) * combination(3, 2) * combination(4, 2)}\n`;
};
btn0.onclick = output;
btn1.onclick = () => {
pre0.textContent = '';
};
output();
0 コメント:
コメントを投稿