Project Euler 84 - Monopoly Odds

Official link: https://projecteuler.net/problem=84

Thought Process

I programmed the monopoly game. GO is assigned value 0 and H2 is 39. I then keep track of a few variables

number_of_rolls, squares_landed_on , current_square, community_chest_count, chance_count

I have 4 functions in my code:

  1. compute(rolls, x): This makes a player roll, rolls number of times, and selects the x-sided die

  2. dice_roll(x): It will roll 2 x-sided die randomly using the python Random Module

  3. chance(count): This will return a card based on chance_count (mod 16)

  4. community_chest(count): This will return a card based on community_chest_count (mod 16)

Then I add all the squares I land on to squares_landed_on and output the 3 most landed squares in order

To increase the accuracy increase number_of_rolls I get the correct answer consistently with 50,000 rolls

Interactive Code

Enter how many rolls you would like (rolls) and what sided die you want (x)

Code will output the top 3 squares for an x-sided die given the number of rolls

It takes about 5 seconds for 50,000 rolls