-
Notifications
You must be signed in to change notification settings - Fork 0
/
LittleLeague.py
executable file
·47 lines (44 loc) · 1.2 KB
/
LittleLeague.py
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
44
45
46
47
game = []
strikes = 0
hits = 0
hits_in_a_row = 0
runs = 0
outs = 0
f = open('S.txt', 'r')
input = f.read()
for i in range(1, len(input)):
if input[i] == '(':
if input[i + 6] == ')':
play = {"pitch": input[i+1:i+3], "swing": input[i+5]}
elif input[i + 5] == ')':
play = {"pitch": input[i+1:i+2], "swing": input[i+4]}
else:
print("Should never reach here")
game.append(play)
for i in range(0, len(game)):
play = game[i]
if play["pitch"] == "FB" and play["swing"] == "F":
runs += (hits + 1)
hits = 0
elif play["pitch"] == "C" and play["swing"] == "S":
strikes = 0
hits+=1
hits_in_a_row+=1
if hits_in_a_row == 4:
hits -= 1
runs += 1
elif play["pitch"] == "FB" and play["swing"] == "S":
strikes+=1
if strikes == 3:
outs += 1
if outs == 3:
break
elif play["pitch"] == "C" and play["swing"] == "F":
strikes+=1
if strikes == 3:
outs += 1
if outs == 3:
break
else:
print("Something's wrong")
print(runs)