## 2017年4月25日火曜日

### 数学 - JavaScript - 確からしさをみる - 確率 – 確率とその基本性質 - 確率の計算(一般の加法定理)

1. $\frac{\left(\begin{array}{c}13\\ 1\end{array}\right)+\left(\begin{array}{c}1\\ 1\end{array}\right)}{\left(\begin{array}{c}52\\ 1\end{array}\right)}=\frac{14}{52}=\frac{7}{26}$

2. $\frac{\left(\begin{array}{c}13\\ 1\end{array}\right)}{\left(\begin{array}{c}52\\ 1\end{array}\right)}+\frac{\left(\begin{array}{c}4\\ 1\end{array}\right)}{\left(\begin{array}{c}52\\ 1\end{array}\right)}-\frac{\left(\begin{array}{c}1\\ 1\end{array}\right)}{\left(\begin{array}{c}52\\ 1\end{array}\right)}=\frac{16}{52}=\frac{4}{13}$

1. $\frac{25}{100}+\frac{16}{100}-\frac{8}{100}=\frac{33}{100}$

2. $1-\frac{33}{100}=\frac{67}{100}$

3. $\frac{25}{100}-\frac{8}{100}=\frac{17}{100}$

1. $\frac{3!}{{3}^{3}}=\frac{2}{9}$

2. $1-\frac{{2}^{3}}{{3}^{3}}=1-\frac{8}{27}=\frac{19}{27}$

1. $\begin{array}{l}\frac{\left(\begin{array}{c}17\\ 4\end{array}\right)}{\left(\begin{array}{c}20\\ 4\end{array}\right)}=\frac{17·16·15·14}{20·19·18·17}=\frac{2·14}{19·3}=\frac{28}{57}\\ 1-\frac{28}{57}=\frac{29}{57}\\ aの主張。\end{array}$

コード(Emacs)

HTML5

<pre id="output0"></pre>
<button id="run0">run0</button>
<button id="clear0">clear</button>

<script src="sample12.js"></script>


JavaScript

let pre0 = document.querySelector('#output0'),
btn0 = document.querySelector('#run0'),
btn1 = document.querySelector('#clear0'),
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 output = () => {
p('13.');
[[range(1, 101).filter((n) => n % 4 === 0 || n % 6 === 0).length / 100, 33 / 100],
[range(1, 101).filter((n) => n % 4 !== 0 && n % 6 !== 0).length / 100, 67 / 100],
[range(1, 101).filter((n) => n % 4 === 0 && n % 6 !== 0).length / 100, 17 / 100]]
.forEach((x) => p(${x[0]},${x[1]}, \${x[0] === x[1]}));
};

btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';

output();