Project Euler:problem Monopoly Odds

Source: Internet
Author: User

In the game, Monopoly, the standard board are set up in the following-to-do:

GO A1 CC1 A2 T1 R1 B1 CH1 B2 B3 JAIL
H2 C1
T2 U1
H1 C2
CH3 C3
R4 R2
G3 D1
CC3 CC2
G2 D2
G1 D3
g2j F3 u2 F2 f1 R3 e3 E2 ch2 E1 FP

A player starts on the GO square and adds the scores on both 6-sided dice to determine the number of squares they advance I n a clockwise direction. Without any further rules we would expect to visit each square with equal probability:2.5%. However, landing on g2j (Go to Jail), CC (Community Chest), and CH (chance) changes this distribution.

In addition to G2J, and one card from all CC and CH, that orders the player to go directly to jail, if a player rolls Three consecutive doubles, they don't advance the result of their 3rd roll. Instead they proceed directly to jail.

at the beginning of the game, the CC and CH cards are shuffled. When a-player lands on CC or CH they take a-card from the top of the respective pile and, after following the instructions , it's returned to the bottom of the pile. There is sixteen cards in all pile, but for the purpose of this problem we is only concerned with cards that order a mo Vement; Any instruction isn't concerned with movement would be ignored and the player would remain on the Cc/ch square.

    • Community Chest (2/16 cards):
      1. Advance to go
      2. GO to JAIL
    • Chance (10/16 cards):
      1. Advance to GO
      2. go to JAIL
      3. go to C1
      4. go to e3
      5. go to H2
      6. go to R1
      7. go to next R (railway Company)
      8. go to next R
      9. go To next U (utility company)
      10. Go back 3 squares.

the heart of this problem concerns The likelihood of visiting a particular square. That's, the probability of finishing at the-square after-a roll. For this reason it should was clear that, with the exception of g2j for which the probability of finishing on it is zero, t He CH squares'll has the lowest probabilities, as 5/8 request a movement to another square, and it's the final square That's the player finishes at the all roll this we are interested in. We shall make no distinction between "Just visiting" and being sent to JAIL, and we shall also ignore the rule about Requi Ring a double to ' get out of jail ', assuming that they pay-to-get out on their next turn.

By starting on GO and numbering the squares sequentially from XX to We can concatenate these two-digit numbers to Produ Ce strings that correspond with sets of squares.

Statistically it can be shown so the three most popular squares, in order, is JAIL (6.24%) = Square, E3 (3.18%) = Sq Uare, and GO (3.09%) = Square 00. So these three most popular squares can is listed with the Six-digit modal string:102400.

If, instead of using 6-sided dice, and the 4-sided dice is used, find the Six-digit modal string.



English is too slag or look Chinese translation is not easy to understand wrong test instructions

Players from go, each time the score of two six-sided dice to determine his next move to the grid (clockwise direction). If there are no other rules, we can expect that each lattice will be accessed in equal probability: 2.5%. However, if the lattice g2j (go to prison jail), Lattice cc (Community chest), Lattice ch (opportunity), the distribution will be changed.

in addition to G2J and a card in CC and CH that allow the player to go directly to prison (JAIL), the third player will go straight to prison if the player has two identical numbers for three consecutive dice.

at the beginning of the game, the cards in CC and CH are emitted in a disorderly sequence. When the player falls to CC or CH, hetake a card on top of the pile, and after executing the following instructions,put the cards back on the bottom of the pile. There are 16 cards in each heap, but for simplicity we only consider moving cards in this topic, and any cards that do not involve moving will be ignored and the player will still be on the cc/ch grid.
  • CC (2/16 cards):
    1. Go to the Go
    2. Go to JAIL.
  • CH (10/16 cards):
    1. Go to the Go
    2. Go to JAIL.
    3. Go to C1.
    4. Go to E3.
    5. Go to H2.
    6. Go to R1.
    7. Go to the next R (railroad Company)
    8. Go to the next R
    9. Go to the next U (tool Company)
    10. 3-Grid fallback

The core issue of this topic is the possibility of each lattice being accessed. That is, the chance of falling to a grid after each roll of the dice. Therefore, in addition to the probability of falling to the g2j is zero, the probability of falling to CH is the least because 5/8 of the chance of falling to CH will move to the other lattice again. And what we're interested in is the lattice that we end up with each time we roll the dice . We don't make a distinction between "just visiting" and being sent to jail, and we also ignore the need to throw a double (two identical numbers) to get out of the jail rule, just assume the player next round automatically goes out of jail.

Starting with go to the lattice number (00 to 39), we connect these two-digit numbers to get the string corresponding to the set of the lattice.

statistically, three of the most popular grids are available in order, JAIL (6.24%) = 10th, E3 (3.18%) = 24th, GO (3.09%) = No. 00. So the three most popular squares can be represented by a six-bit string: 102400.

If we replace the two 6-sided dice with two 4-sided dice, find the three-bit string representing the six most popular squares.

Import Randomdef Shuffle_16card (): #随机洗牌 deck=[i for I in Range (1,17)] Random.shuffle (deck) return de Ckdef Next_rail (POS): If POS in range (0,5): return 5 if POS in range (35,40): return 5 if POS in ran GE (5,15): return if POS in range (15,25): return if POS in range (25,35): Return 35def Next _utility (POS): If POS in range (0,12): return if POS in range (28,40): return if POS in range (1        2,28): Return 28def cc (CARD,POS): if Card==1:return 0 elif Card==2:return Else: Return posdef Chance (Card,pos): if Card==1:return 0 elif card==2:return elif card==3:r  Eturn elif Card==4:return elif card==5:return 5 elif Card==6:return Card = = 7 or Card==8:return next_rail (POS) elif Card==9:return next_utility (POS) elif card==10:p Os=pos-3 If POS &Lt    0:pos=40+pos return POS Else:return pos def dice_num (): A=random.randrange (1,5)    B=random.randrange (1,5) if a== b:doubles=true else:doubles=false return (a+b,doubles) def main (): Chancedeck=shuffle_16card () Ccdeck=shuffle_16card () pos=0 doublecount=0 count=0 result=[0 for I in range (+)] while Count <1000000000:count=count+1 dice=dice_num () if dice[1] = = True:dou Blecount=doublecount+1 else:doublecount=0 if doublecount==3:pos=10 double  Count=0 else:pos=pos+dice[0] If POS >= 40:pos=pos-40 if pos = = 2 or pos = =-or pos = = 33:t1=ccdeck.pop () ccdeck.insert (0,T1) pos=cc (t1,p OS) if pos==7 or pos = =-or pos = = 36:t2=chancedeck.pop () chancedeck.insert (T2               , POS) Pos=chance (t2,pos) If pos = = 30:pos=10 result[pos]=result[pos]+1 Print (Result) an  S=[[i,result[i]] for I in range (+)] Ans.sort (Key=lambda x:x[1]) print (ans) if __name__ = = ' __main__ ': Main ()



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Project Euler:problem Monopoly Odds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.