Skip to content

Commit fa599e9

Browse files
committed
add script for gcd game, add draft of the gcd game, add constant for gcd game
1 parent 31e5c45 commit fa599e9

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

brain_games/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
CALC_GAME_INTRODUCTION = [
1010
'What is the result of the expression?'
1111
]
12+
GCD_GAME_INTRODUCTION = [
13+
'Find the greatest common divisor of given numbers.'
14+
]
1215

1316

1417
GAMES_TO_WIN = 3

brain_games/game_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import brain_games.constants as const
33

44

5-
def game_engine(get_question_and_answer: callable, introduction):
5+
def game_engine(get_question_and_answer, introduction):
66
username = prompt.string(''.join(const.GREETING))
77

88
print(f'Hello, {username}!')

brain_games/games/gcd.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
from brain_games.game_engine import game_engine
4+
from brain_games.constants import GCD_GAME_INTRODUCTION
5+
6+
7+
def get_greatest_common_divisor(num1, num2):
8+
while num2:
9+
num1, num2 = num2, num1 % num2
10+
return num1
11+
12+
13+
def get_random_numbers_and_answer():
14+
num1, num2 = random.randint(1, 101), random.randint(1, 101)
15+
question = f' {num1} {num2}'
16+
answer = str(get_greatest_common_divisor(num1, num2))
17+
return question, answer
18+
19+
20+
def gcd_game():
21+
game_engine(get_random_numbers_and_answer, GCD_GAME_INTRODUCTION)

brain_games/scripts/brain_gcd.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python3
2+
3+
from brain_games.games.gcd import gcd_game
4+
5+
6+
def main():
7+
gcd_game()
8+
9+
10+
if __name__ == '__main__':
11+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ prompt = "^0.4.1"
1616
brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
1818
brain-calc = "brain_games.scripts.brain_calc:main"
19+
brain-gcd = "brain_games.scripts.brain_gcd:main"
1920

2021
[tool.poetry.group.dev.dependencies]
2122
flake8 = "^7.1.1"

0 commit comments

Comments
 (0)