# Python 3 Eurasian Plan Problem 84 Millionaire EulerProject.png

For more questions, see: https://www.jianshu.com/p/8c3ec805433d

#### 84. Monopoly

The standard chessboard of the moneybags is roughly as follows: Monopoly.png

_Starting from the square marked with GO, throw two six-sided dice, and take the sum of the points as the number of steps forward in this round. If no other rules are added, after many rounds of play, the probability of falling on each grid should be close to 2.5%. However, due to the existence of G2J (imprisonment), CC (treasure box card) and CH (opportunity card), this probability distribution will change.
In addition to falling on G2J or possibly drawing jail cards on CC or CH, if players throw two identical points three times in a row, such as (3,3), (1,1), (5,5), they will not advance 5+5=10 steps on the third time, but go straight to jail.
At the beginning of the game, the cards in CC and CH will be randomly disrupted. When a player falls on CC or CH, they take a card from the top of CC and CH cards and move forward according to the meaning of the card, and put the card back to the bottom of the stack. The treasure box card and the opportunity card each have 16 cards, because we only care about the cards that will affect the movement, the other cards are invalid. The cards of treasure box card and opportunity card are as follows:

• Treasure Box Card (2 cards, 14 other cards are invalid):
Back to the starting point GO
_Entering Jail JAIL
• Opportunity cards (10 cards, the other 6 are invalid):
Back to the starting point GO
_Entering Jail JAIL
Move to C1
Move to E3
Moving to H2
Move to R1
Move to the next R (Railway Company)
Move to the next R
Move to the next U (Public Service Company)
_three steps backward

_This question mainly examines the probability of stopping on a particular grid. Obviously, besides the possibility of stopping on G2J is 0, the possibility of stopping on CH is the smallest, because there is a 5/8 probability that the player will move to another grid. There is no distinction between being sent to prison or being left in prison, and regardless of the need to throw two identical points in order to get out of prison, it is assumed that the second round of entry into prison will be automatically released.
_Starting from the starting point GO, we can connect these two digits to represent the sequence of squares by marking the squares from 00 to 39 in turn.
Statistically speaking, the three largest stopping probability squares are:
__JAIL(6.24%): grid 10
__E3(3.18%): square 24
_GO(3.09%): square 00.
The three squares can be represented by a six-digit string: 102400
The above possibilities are obtained by using two six-sided dices. Now we use two four-sided dices to find a six-digit string consisting of three squares with the greatest stopping probability.

``````import numpy as np
import random
#Computation of random numbers
def Comnum(num, count):#Calculating the Random Numbers of Several Colors
numlist = []
st = 0
while st < count:
numlist.append(random.randint(1, num))
st += 1
return numlist

#CH card
chlist = list(np.array([0, 10, 11, 24, 39, 5, 99, 99, 999, 9999] + * 6)[random.sample(range(16), 16)])#99999 represents invalid cards and shuffles immediately
chdict ={7: [15, 12], 22: [25, 28], 36: [5, 12]}
#CC card
bxlist = list(np.array([0, 10] + * 14)[random.sample(range(16), 16)])#99999 represents invalid cards and shuffles immediately
bxdict = [2, 17, 33]

#Define the function after taking card and playback card
def Card(exlist):
return exlist[1:] + [exlist]#Place the cards at the bottom after you have taken them.

#Counting dictionary
countdict = {kk : 0 for kk in range(40)}#Each number represents a square.
#Start simulation
start = 0
jailsign = 0
monitimes = 10000#Number of simulations
for moni in range(monitimes):
#Beginning Random Number
randomlist = Comnum(4, 2)#Calculating the Random Numbers of Two Four-Faced Chromosomes
sezi = sum(randomlist)#Calculate the number of steps forward
if randomlist == randomlist:
jailsign += 1
else:
jailsign = 0
if jailsign >= 3:#Throw the same number of points three times in a row
countdict += 1#JAIL
start = 10
else:
busu = (sezi + start) % 40
if busu == 30:#G2J
countdict += 1#JAIL
start = 10
else:
if busu in bxdict:#CC card
if bxlist == 99999:#Stop Moving
countdict[busu] += 1
start = busu
else:
countdict[bxlist] += 1
start = bxlist
bxlist = Card(bxlist).copy()
elif busu in chdict:#CH card
if chlist == 99:#next R
nnum = chdict[busu]
elif chlist == 999:#next U
nnum = chdict[busu]
elif chlist == 99999:#Stop Moving
nnum = busu
elif chlist == 9999:#Backward 3
nnum = busu - 3
if nnum == 33:#CC card
if bxlist != 99999:  # Stop Moving
nnum = bxlist
bxlist = Card(bxlist).copy()
else:
nnum = chlist
countdict[nnum] += 1
start = nnum
chlist = Card(chlist).copy()
else:
countdict[busu] += 1
start = busu

#Select the first n maximum values and output the string
def Str(exdict, N, M):
sdict = sorted(exdict.items(), key = lambda x: x, reverse = True)
ncount = 0
strkey = ''
while ncount < N:
item = sdict[ncount]

if len(str(item)) < 2:
strkey += '0%s'%item
print('0%s : %.4f%%\n'%(item, exdict[item] / M * 100))
else:
strkey += '%s' % item
print('%s : %.4f%%' % (item, exdict[item] / M * 100))
ncount += 1
return strkey

print('After the simulation, the number of stops per square:%s'%countdict)
print(Str(countdict, 3, monitimes))