2017年4月15日土曜日

開発環境

The Art of Computer Programming Volume 1 Fundamental Algorithms Third Edition 日本語版(Donald E. Knuth (著)、青木 孝 (著)、筧 一彦 (著)、鈴木 健一 (著)、長尾 高弘 (著)、有澤 誠 (その他)、和田 英一 (その他)、ドワンゴ)の第1章(基礎概念)、1.2(数学的な基礎)、演習問題6を取り組んでみる。


  1. a'm+b'n=cam+bn=d c=qd+r am+bn=d ( a'qa )m+( b'qb )n =a'm+b'nq( am+bn ) =cqd =r

コード(Emacs)

HTML5

m = <input id="m0" type="number" min="1" step="1" value="10">
n = <input id="n0" type="number" min="1" step="1" value="15">
a = <input id="a0" type="number" min="1" step="1" value="0">
b = <input id="b0" type="number" min="1" step="1" value="1">
a1 = <input id="a1" type="number" min="" step="1" value="1">
b1 = <input id="b1" type="number" min="1" step="1" value="0">
c = <input id="c0" type="number" min="1" step="1" value="10">
d = <input id="d0" type="number" min="1" step="1" value="15">
<br>
<button id="run0">run</button>
<button id="clear0">clear</button>
<pre id="output0"></pre>

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

JavaScript

let input0 = document.querySelector('#m0'),
    input1 = document.querySelector('#n0'),
    input2 = document.querySelector('#a0'),
    input3 = document.querySelector('#b0'),
    input4 = document.querySelector('#a1'),
    input5 = document.querySelector('#b1'),
    input6 = document.querySelector('#c0'),
    input7 = document.querySelector('#d0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    pre0 = document.querySelector('#output0'),
    p = (x) => pre0.textContent += x + '\n';

let f = (m, n, a, b, a1, b1, c, d) => {
    return (a1 * m + b1 * n) === c &&
        (a * m + b * n === d);
};

let output = () => {
    let m = parseInt(input0.value, 10),
        n = parseInt(input1.value, 10),
        a = parseInt(input2.value, 10),
        b = parseInt(input3.value, 10),
        a1 = parseInt(input4.value, 10),
        b1 = parseInt(input5.value, 10),
        c = parseInt(input6.value, 10),
        d = parseInt(input7.value, 10);

    p(f(m, n, a, b, a1, b1, c, d));

    let q = Math.floor(c / d),
        r = c % d;

    c = d;
    d = r;
    let t = a1;
    a1 = a;
    a = t - q * a;
    t = b1;
    b1 = b;
    b = t - q * b;
    p(f(m, n, a, b, a1, b1, c, d));
};

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

output();
m = n = a = b = a1 = b1 = c = d =










 
						

0 コメント:

コメントを投稿

Comments on Google+: