File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
brain_games/scripts/games Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ brain-even:
1010brain-calc :
1111 uv run brain-calc
1212
13+ brain-gcd :
14+ uv run brain-gcd
15+
1316build :
1417 uv build
1518
Original file line number Diff line number Diff line change 1+ from random import randint
2+
3+ from brain_games .engine import engine
4+
5+ GAME_TASK = 'Find the greatest common divisor of given numbers.'
6+ MIN_NUMBER = 2
7+ MAX_NUMBER = 10
8+
9+
10+ def get_gcd (num_1 , num_2 ):
11+ min_num = num_1 if num_1 < num_2 else num_2
12+ gcd = 1
13+ counter = 2
14+ while counter < min_num / 2 :
15+ if num_1 % counter == 0 and num_2 % counter == 0 :
16+ gcd = counter
17+ counter += 1
18+ return gcd
19+
20+
21+ def get_game_data ():
22+ random_member = randint (MIN_NUMBER , MAX_NUMBER )
23+ first_number = randint (MIN_NUMBER , MAX_NUMBER ) * random_member
24+ second_number = randint (MIN_NUMBER , MAX_NUMBER ) * random_member
25+ gcd = get_gcd (first_number , second_number )
26+ game_question = f'{ first_number } { second_number } '
27+ game_answer = str (gcd )
28+ return [game_question , game_answer ]
29+
30+
31+ def main ():
32+ engine (GAME_TASK , get_game_data )
33+
34+
35+ if __name__ == "__main__" :
36+ main ()
Original file line number Diff line number Diff line change @@ -24,3 +24,4 @@ dev = [
2424brain-games = " brain_games.scripts.games.brain_games:main"
2525brain-even = " brain_games.scripts.games.brain_even:main"
2626brain-calc = " brain_games.scripts.games.brain_calc:main"
27+ brain-gcd = " brain_games.scripts.games.brain_gcd:main"
You can’t perform that action at this time.
0 commit comments