-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchutes.py
58 lines (44 loc) · 954 Bytes
/
chutes.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
48
49
50
51
52
53
54
55
56
57
58
import random
N = 10
def roll():
return random.randint(1, 6)
ladders = {1: 38,
4: 14,
9: 31,
21: 42,
28: 84,
36: 44,
51: 67,
71: 91,
80: 100}
chutes = {16: 6,
47: 26,
49: 11,
56: 53,
62: 19,
64: 60,
87: 24,
93: 73,
95: 75,
98: 78}
ladders.update(chutes)
routes = ladders
def land_on(sq):
print sq,
hits[sq] += 1
for i in xrange(N):
square = 0
hits = [0] * 101
while True:
this_roll = roll()
if this_roll + square > 100:
# does staying on the same space count twice?
continue
square += this_roll
land_on(square)
if square in routes:
square = routes[square]
land_on(square)
if square == 100:
print
break # won the game