Skip to content

Instantly share code, notes, and snippets.

@AyaMorisawa
Last active November 4, 2015 15:31
Show Gist options
  • Save AyaMorisawa/2f25766995b1ebdd7e0e to your computer and use it in GitHub Desktop.
Save AyaMorisawa/2f25766995b1ebdd7e0e to your computer and use it in GitHub Desktop.
var p = console.log.bind(console);
var q = require('readline-sync').question;
var gcd = (a, b) => !b ? a : gcd(b, a % b);
var r = () => Math.floor(Math.random()*9)+1
var i = 1;
for(;;) {
var x = r();
var y = r();
var df = x % y === 0;
if(df) continue;
var g = gcd(x, y);
if(g === 1) continue;
var sn = x/g;
var sd = y/g;
p(`(${i}) ${x}/${y}`);
var a = q('Input the answer: ');
var as = a.split('/');
var an = parseInt(as[0]);
var ad = parseInt(as[1]);
var c = an === sn && ad === sd;
p(c ? 'Good!' : `Bad: The correct answer is ${sn}/${sd}`);
i++;
}
var p = console.log.bind(console);
var q = require('readline-sync').question;
var gcd = (a, b) => !b ? a : gcd(b, a % b);
var r = () => Math.floor(Math.random()*9)+1
var i = 1;
for(;;) {
var x = r();
var y = r();
var z = r();
var xz = x * z;
var yz = y * z;
var df = x % y === 0;
if(df) continue;
var g = gcd(x, y);
if(g === 1) continue;
var sn = x/g;
var sd = y/g;
p(`(${i}) ${xz}/${yz}`);
var a = q('Input the answer: ');
var as = a.split('/');
var an = parseInt(as[0]);
var ad = parseInt(as[1]);
var c = an === sn && ad === sd;
p(c ? 'Good!' : `Bad: The correct answer is ${sn}/${sd}`);
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment