Skip to content

Commit

Permalink
prime game
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagidza committed Sep 5, 2023
1 parent f83d1d2 commit ace172d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 0x0A-primegame/0-prime_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3
""" Prime Game """


def isWinner(x, nums):
""" Prime Game """
if not nums or x < 1:
return None
n = max(nums)
nums.sort()
m = [False for i in range(n + 1)]
for i in range(2, int(n ** 0.5) + 1):
if not m[i]:
for j in range(i*i, n + 1, i):
m[j] = True
m[0] = m[1] = True
c = 0
for i in range(len(m)):
if not m[i]:
c += 1
m[i] = c
p1 = 0
for n in nums:
p1 += m[n] % 2 == 1
if p1 * 2 == len(nums):
return None
if p1 * 2 > len(nums):
return "Maria"
return "Ben"

0 comments on commit ace172d

Please sign in to comment.