Last active
November 4, 2015 15:31
-
-
Save AyaMorisawa/2f25766995b1ebdd7e0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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