Skip to content

Commit be292b1

Browse files
committed
done step 7 of the project
1 parent cff8bc0 commit be292b1

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
## Brain Calc
1010
[![asciicast](https://asciinema.org/a/0Qp0SBrF6oVx5djcfAp1UXj8W.svg)](https://asciinema.org/a/0Qp0SBrF6oVx5djcfAp1UXj8W)
11+
12+
## Brain GCD
13+
[![asciicast](https://asciinema.org/a/nP0uI7dz54y5BVvA2rY9Fk58g.svg)](https://asciinema.org/a/nP0uI7dz54y5BVvA2rY9Fk58g)

bin/brain-gcd.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import playGcd from '../src/games/gcd.js';
4+
5+
playGcd();

demo.cast4

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{"version": 2, "width": 80, "height": 24, "timestamp": 1758182190, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.316922, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
3+
[2.56228, "o", "b"]
4+
[3.037123, "o", "r"]
5+
[3.193882, "o", "a"]
6+
[3.73763, "o", "i"]
7+
[4.001552, "o", "n"]
8+
[4.815088, "o", "-"]
9+
[5.837692, "o", "g \r"]
10+
[6.067107, "o", "c"]
11+
[6.176749, "o", "d"]
12+
[6.592189, "o", "\r\n\u001b[?2004l\r"]
13+
[6.642685, "o", "Welcome to the Brain Games!\r\n"]
14+
[6.642754, "o", "Find the greatest common divisor of given numbers.\r\n"]
15+
[6.644632, "o", "May I have your name? "]
16+
[8.69769, "o", "M"]
17+
[9.451599, "o", "i"]
18+
[9.723412, "o", "c"]
19+
[10.018442, "o", "h"]
20+
[10.152143, "o", "a"]
21+
[10.393142, "o", "e"]
22+
[10.655704, "o", "l"]
23+
[11.04693, "o", "\r\n"]
24+
[11.048234, "o", "Hello, Michael!\r\n"]
25+
[11.048291, "o", "Question: 71, 81\r\n"]
26+
[11.048377, "o", "Your answer: "]
27+
[15.67017, "o", "1"]
28+
[16.594359, "o", "\r\n"]
29+
[16.595367, "o", "Correct!\r\nQuestion: 34, 49\r\nYour answer: "]
30+
[21.217996, "o", "1"]
31+
[22.482206, "o", "\r\n"]
32+
[22.482717, "o", "Correct!\r\n"]
33+
[22.483049, "o", "Question: 10, 76\r\nYour answer: "]
34+
[27.986481, "o", "2"]
35+
[28.828391, "o", "\r\n"]
36+
[28.829101, "o", "Correct!\r\n"]
37+
[28.829225, "o", "Congratulations, Michael!\r\n"]
38+
[28.840136, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
39+
[32.556712, "o", "b"]
40+
[32.90468, "o", "r"]
41+
[33.082949, "o", "a"]
42+
[33.456277, "o", "i"]
43+
[33.78053, "o", "n"]
44+
[34.838543, "o", "-"]
45+
[35.939623, "o", "g \r"]
46+
[36.247152, "o", "c"]
47+
[36.384529, "o", "d"]
48+
[36.66893, "o", "\r\n\u001b[?2004l\r"]
49+
[36.721417, "o", "Welcome to the Brain Games!\r\n"]
50+
[36.721797, "o", "Find the greatest common divisor of given numbers.\r\n"]
51+
[36.723306, "o", "May I have your name? "]
52+
[38.853015, "o", "N"]
53+
[39.260558, "o", "i"]
54+
[40.336296, "o", "c"]
55+
[40.506102, "o", "k"]
56+
[41.227548, "o", "\r\n"]
57+
[41.228778, "o", "Hello, Nick!\r\n"]
58+
[41.229, "o", "Question: 100, 85\r\n"]
59+
[41.229089, "o", "Your answer: "]
60+
[47.296547, "o", "5"]
61+
[48.066237, "o", "\r\n"]
62+
[48.066954, "o", "Correct!\r\nQuestion: 32, 85\r\n"]
63+
[48.067483, "o", "Your answer: "]
64+
[53.336879, "o", "4"]
65+
[54.823006, "o", "\r\n"]
66+
[54.823602, "o", "'4' is wrong answer ;(. Correct answer was '1'.\r\nLet's try again, Nick!\r\n"]
67+
[54.832061, "o", "\u001b[?2004h\u001b]0;michael@michael-Nitro-ANV15-51: ~/qa-auto-engineer-javascript-project-44\u0007\u001b[01;32mmichael@michael-Nitro-ANV15-51\u001b[00m:\u001b[01;34m~/qa-auto-engineer-javascript-project-44\u001b[00m$ "]
68+
[62.336022, "o", "\u001b[?2004l\r\r\nexit\r\n"]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"bin": {
2121
"brain-games": "bin/brain-games.js",
2222
"brain-even": "bin/brain-even.js",
23-
"brain-calc": "bin/brain-calc.js"
23+
"brain-calc": "bin/brain-calc.js",
24+
"brain-gcd": "bin/brain-gcd.js"
2425
},
2526
"dependencies": {
2627
"readline-sync": "^1.4.10"

src/games/gcd.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import runEngine from '../index.js'
2+
import getRandomNumber from '../utils.js'
3+
4+
const rule = 'Find the greatest common divisor of given numbers.'
5+
6+
const getGcd = (x, y) => {
7+
let a = x
8+
let b = y
9+
10+
if (b === 0) return a
11+
12+
while (b !== 0) {
13+
const temp = b
14+
b = a % b
15+
a = temp
16+
}
17+
return a
18+
}
19+
20+
const makeRound = () => {
21+
const x = getRandomNumber(1, 100)
22+
const y = getRandomNumber(1, 100)
23+
24+
const question = `${x}, ${y}`
25+
const answer = String(getGcd(x, y))
26+
return [question, answer]
27+
}
28+
29+
export default function playGcd() {
30+
runEngine(rule, makeRound);
31+
}

0 commit comments

Comments
 (0)