File tree Expand file tree Collapse file tree 4 files changed +54
-2
lines changed
brain_games/scripts/games Expand file tree Collapse file tree 4 files changed +54
-2
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 1010[ ![ Maintainability Rating] ( https://sonarcloud.io/api/project_badges/measure?project=pwr44_devops-engineer-from-scratch-project-49&metric=sqale_rating )] ( https://sonarcloud.io/summary/new_code?id=pwr44_devops-engineer-from-scratch-project-49 )
1111[ ![ Vulnerabilities] ( https://sonarcloud.io/api/project_badges/measure?project=pwr44_devops-engineer-from-scratch-project-49&metric=vulnerabilities )] ( https://sonarcloud.io/summary/new_code?id=pwr44_devops-engineer-from-scratch-project-49 )
1212
13- ### Asciinema: step 5
13+ ### Asciinema: step 5: btain-even
1414
1515[ ![ asciicast] ( https://asciinema.org/a/746759.svg )] ( https://asciinema.org/a/746759 )
1616
17- ### Asciinema: step 6
17+ ### Asciinema: step 6: brain-calc
1818
1919[ ![ asciicast] ( https://asciinema.org/a/xBVfA6WioDJ7SYInLt7sZVp6X.svg )] ( https://asciinema.org/a/xBVfA6WioDJ7SYInLt7sZVp6X )
20+
21+ ### Asciinema: step 7: brain-gcd
22+
23+ [ ![ asciicast] ( https://asciinema.org/a/LKymopkNQHeyv55y6M94obHR3.svg )] ( https://asciinema.org/a/LKymopkNQHeyv55y6M94obHR3 )
24+
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_second_number (first_number , random_member ):
11+ second_number = randint (MIN_NUMBER , MAX_NUMBER ) * random_member
12+ while second_number == first_number :
13+ second_number = randint (MIN_NUMBER , MAX_NUMBER ) * random_member
14+ return second_number
15+
16+
17+ def get_gcd (num_1 , num_2 ):
18+ max_num = num_1 if num_1 > num_2 else num_2
19+ gcd = 1
20+ counter = 2
21+ while counter <= max_num / 2 :
22+ if num_1 % counter == 0 and num_2 % counter == 0 :
23+ gcd = counter
24+ counter += 1
25+ return gcd
26+
27+
28+ def get_game_data ():
29+ random_member = randint (MIN_NUMBER , MAX_NUMBER )
30+ first_number = randint (MIN_NUMBER , MAX_NUMBER ) * random_member
31+ second_number = get_second_number (first_number , random_member )
32+ gcd = get_gcd (first_number , second_number )
33+ game_question = f'{ first_number } { second_number } '
34+ game_answer = str (gcd )
35+ return [game_question , game_answer ]
36+
37+
38+ def main ():
39+ engine (GAME_TASK , get_game_data )
40+
41+
42+ if __name__ == "__main__" :
43+ 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