-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpiles.py
37 lines (31 loc) · 831 Bytes
/
piles.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
import numpy as np
import math
import random
import matplotlib.pyplot as plt
maxPerPile = 10
numberOfPiles = 10
maxIter = 100
x = 0
piles_left = []
piles = np.empty(numberOfPiles)
piles.fill(10)
#print(piles)
totPiles = np.sum(piles)
#print(totPiles)
numPiles = np.array([piles.size])
while(True):
if (piles.size > 1 and totPiles == np.sum(piles)):
piles = piles[np.nonzero(piles)]
if(piles.size == 1):
break
#piles_left.append(piles.size)
for i in np.arange(piles.size):
piles[i] -= 1
num = np.random.randint(piles.size)
piles[num] += 1
numPiles = np.append(numPiles,piles.size)
x += 1
print(x)
#plt.plot(range(maxIter),piles_left)
#plt.title('Piles left vs No. of Iterations')
#plt.show()