File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import run from '../src/games/gcd.js' ;
4+
5+ run ( ) ;
Original file line number Diff line number Diff line change 1+ import playGame from '../index.js' ;
2+
3+ const rules = 'Find the greatest common divisor of given numbers.' ;
4+
5+ const findGcd = ( ) => {
6+ const firstNum = Math . floor ( Math . random ( ) * 150 ) + 1 ;
7+ const secondNum = Math . floor ( Math . random ( ) * 50 ) + 1 ;
8+ const minNum = Math . min ( firstNum , secondNum ) ;
9+ const question = `${ firstNum } ${ secondNum } ` ;
10+ let correctAnswer = 1 ;
11+
12+ for ( let i = 2 ; i <= minNum ; i += 1 ) {
13+ if ( firstNum % i === 0 && secondNum % i === 0 ) {
14+ correctAnswer = i ;
15+ }
16+ }
17+
18+ return [ question , String ( correctAnswer ) ] ;
19+ } ;
20+
21+ export default ( ) => playGame ( rules , findGcd ) ;
You can’t perform that action at this time.
0 commit comments