VOVELS set AEIOU def count_ov sub inp offset res while True res_idx in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
VOVELS = set('AEIOU')
def count_ov(sub, inp, offset):
res = 0
while True:
res_idx = inp.find(sub, offset)
if res_idx > -1:
res += 1
offset = res_idx + 1
else:
break
return res
def minion_game(inp):
kev = 0
history = set()
len_inp = len(inp)
for idx, char in enumerate(inp):
if char in VOVELS:
for slen in range(1, len_inp - idx + 1):
sub = inp[idx:idx + slen]
if sub not in history:
kev += count_ov(sub, inp, idx)
history.add(sub)
#print('Kevin', kev)
st = 0
history = set()
for idx, char in enumerate(inp):
if char not in VOVELS:
for slen in range(1, len_inp - idx + 1):
sub = inp[idx:idx + slen]
if sub not in history:
st += count_ov(sub, inp, idx)
history.add(sub)
if st > kev:
print('Stuart', st)
elif st < kev:
print('Kevin', kev)
else:
print('Draw')
if __name__ == '__main__':