学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro + Apple Pencil
- MyScript Nebo(iPad アプリ)
- 参考書籍
数学読本〈6〉線形写像・1次変換/数論へのプレリュード/集合論へのプレリュード/εとδ/落ち穂拾い など(松坂 和夫(著)、岩波書店)の第24章(無限をかぞえる - 集合論へのプレリュード)、24.2(可算集合)、可算集合の性質(2)、問1.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3 from sympy import pprint, Rational def g(m, n): return Rational((m + n - 1) * (m + n - 2), 2) + n d = {} for m in range(1, 10): for n in range(1, m + 1): d[g(m, n)] = f'g({m}, {n})' m -= 1 for n in sorted(d): print(f'{d[n]} = {n}')
入出力結果(Terminal, Jupyter(IPython))
$ ./sample1.py g(1, 1) = 1 g(2, 1) = 2 g(1, 2) = 3 g(3, 1) = 4 g(2, 2) = 5 g(1, 3) = 6 g(4, 1) = 7 g(3, 2) = 8 g(2, 3) = 9 g(1, 4) = 10 g(5, 1) = 11 g(4, 2) = 12 g(3, 3) = 13 g(2, 4) = 14 g(1, 5) = 15 g(6, 1) = 16 g(5, 2) = 17 g(4, 3) = 18 g(3, 4) = 19 g(2, 5) = 20 g(1, 6) = 21 g(7, 1) = 22 g(6, 2) = 23 g(5, 3) = 24 g(4, 4) = 25 g(3, 5) = 26 g(2, 6) = 27 g(1, 7) = 28 g(8, 1) = 29 g(7, 2) = 30 g(6, 3) = 31 g(5, 4) = 32 g(4, 5) = 33 g(3, 6) = 34 g(2, 7) = 35 g(1, 8) = 36 g(9, 1) = 37 g(8, 2) = 38 g(7, 3) = 39 g(6, 4) = 40 g(5, 5) = 41 g(4, 6) = 42 g(3, 7) = 43 g(2, 8) = 44 g(1, 9) = 45 $
HTML5
<pre id="output0"></pre> <label for="m0">m = </label> <input id="m0" type="number" min="1" step="1" value="1"> <label for="n0">n = </label> <input id="n0" type="number" min="1" step="1" value="1"> <button id="run0">run</button> <button id="clear0">clear</button> <script src="sample1.js"></script>
JavaScript
let pre0 = document.querySelector('#output0'), btn0 = document.querySelector('#run0'), btn1 = document.querySelector('#clear0'), input_m = document.querySelector('#m0'), input_n = document.querySelector('#n0'), inputs = [input_m, input_n], p = (x) => pre0.textContent += x + '\n', range = (start, end, step=1) => { let res = []; for (let i = start; i < end; i += step) { res.push(i); } return res; }; let g = (m, n) => (m + n - 1) * (m + n - 2) / 2 + n; let output = () => { let m = parseInt(input_m.value, 10), n = parseInt(input_n.value, 10); p(`g(${m}, ${n}) = ${g(m, n)}`); }; inputs.forEach((input) => input.onchange = output); btn0.onclick = output; btn1.onclick = () => pre0.textContent = ''; output();
0 コメント:
コメントを投稿