All Euler problems
Project Euler

Monopoly Odds

In a simplified Monopoly game with two 4-sided dice, find the three most visited squares. Express the answer as a six-digit string of their two-digit square numbers (in descending order of frequency).

Source sync Apr 19, 2026
Problem #0084
Level Level 04
Solved By 14,682
Languages C++, Python
Answer 101524
Length 850 words
probabilitymodular_arithmeticlinear_algebra

Problem Statement

This archive keeps the full statement, math, and original media on the page.

In the game, Monopoly, the standard board is set up in the following way:

Problem illustration

A player starts on the GO square and adds the scores on two 6-sided dice to determine the number of squares they advance in 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 each of CC and CH, that orders the player to go directly to jail, if a player rolls three consecutive doubles, they do not 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 is returned to the bottom of the pile. There are sixteen cards in each pile, but for the purpose of this problem we are only concerned with cards that order a movement; any instruction not concerned with movement will be ignored and the player will 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 is, the probability of finishing at that square after a roll. For this reason it should be clear that, with the exception of G2J for which the probability of finishing on it is zero, the CH squares will have the lowest probabilities, as 5/8 request a movement to another square, and it is the final square that the player finishes at on each roll that 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 requiring a double to "get out of jail", assuming that they pay to get out on their next turn.

By starting at GO and numbering the squares sequentially from 00 to 39 we can concatenate these two-digit numbers to produce strings that correspond with sets of squares.

Statistically it can be shown that the three most popular squares, in order, are JAIL (6.24%) = Square 10, E3 (3.18%) = Square 24, and GO (3.09%) = Square 00. So these three most popular squares can be listed with the six-digit modal string: 102400.

If, instead of using two 6-sided dice, two 4-sided dice are used, find the six-digit modal string.

Problem 84: Monopoly Odds

Mathematical Foundation

Definitions and Notation

Definition 1 (Board). The Monopoly board consists of 40 squares indexed 0,1,,390, 1, \ldots, 39. The distinguished squares are:

  • GO = 0, JAIL = 10, G2J (Go To Jail) = 30.
  • Community Chest (CC): {2,17,33}\{2, 17, 33\}.
  • Chance (CH): {7,22,36}\{7, 22, 36\}.
  • Railroads (R): {5,15,25,35}\{5, 15, 25, 35\}.
  • Utilities (U): {12,28}\{12, 28\}.

Definition 2 (Dice distribution). Two independent 4-sided dice yield a sum S{2,3,,8}S \in \{2, 3, \ldots, 8\} with probability mass function

P(S=k)=min(k1,9k)16,k=2,3,,8.P(S = k) = \frac{\min(k-1,\, 9-k)}{16}, \quad k = 2, 3, \ldots, 8.

The probability of doubles (both dice showing the same value) is P(doubles)=4/16=1/4P(\text{doubles}) = 4/16 = 1/4.

State Space Construction

Lemma 1 (Sufficiency of the doubles counter). The state space S={(s,d):0s39,  0d2}\mathcal{S} = \{(s, d) : 0 \le s \le 39,\; 0 \le d \le 2\}, where ss denotes the current square and dd the number of consecutive doubles already rolled, is a sufficient state representation for the Monopoly Markov chain. In particular, S=120|\mathcal{S}| = 120.

Proof. The transition distribution from a given position depends on two quantities: the current square ss (which determines whether special rules apply upon landing) and the consecutive doubles count dd (which determines whether the next double triggers a forced move to JAIL). The count dd takes values in {0,1,2}\{0, 1, 2\} because:

  • If d=2d = 2 and the next roll is a double, the player moves to JAIL and the count resets to 00.
  • If d<2d < 2 and the next roll is a double, the count increments to d+12d + 1 \le 2.
  • If the next roll is not a double, the count resets to 00.

Hence d=3d = 3 never persists as a state, and {0,1,2}\{0, 1, 2\} is exhaustive. The total state count is 40×3=12040 \times 3 = 120. \square

Existence and Uniqueness of the Stationary Distribution

Theorem 1 (Ergodicity). The Markov chain on S\mathcal{S} is irreducible and aperiodic. Consequently, by the Perron—Frobenius theorem, there exists a unique stationary distribution πRS\boldsymbol{\pi} \in \mathbb{R}^{|\mathcal{S}|} satisfying πTP=πT\boldsymbol{\pi}^T P = \boldsymbol{\pi}^T and π1=1\|\boldsymbol{\pi}\|_1 = 1.

Proof.

Irreducibility. It suffices to show that every state communicates with a fixed reference state, say (10,0)(10, 0) (JAIL with zero doubles). From any state (s,d)(s, d), three consecutive doubles lead to (10,0)(10, 0) regardless of ss and dd, and this event has positive probability (1/4)k>0(1/4)^k > 0 for the required number of doubles k3k \le 3. From (10,0)(10, 0), any target square ss' is reachable: the dice sums {2,3,,8}\{2, 3, \ldots, 8\} form a set of step sizes whose greatest common divisor is gcd(2,3,4,5,6,7,8)=1\gcd(2,3,4,5,6,7,8) = 1. By Bezout’s lemma, every residue modulo 40 is representable as a non-negative integer linear combination of these step sizes, so any square is reachable in a bounded number of non-double rolls (each setting d=0d = 0).

Aperiodicity. From state (s,0)(s, 0), a non-double roll moves to some state (s,0)(s', 0), and a subsequent sequence of non-double rolls can return to (s,0)(s, 0) in varying numbers of steps. Since the gcd of possible return times is 1, the chain is aperiodic.

By the fundamental theorem of finite Markov chains, an irreducible aperiodic chain on a finite state space possesses a unique stationary distribution. \square

Transition Matrix Construction

Theorem 2 (Transition probabilities). The 120×120120 \times 120 transition matrix PP is defined as follows. For each state (s,d)S(s, d) \in \mathcal{S} and each dice outcome (a,b){1,2,3,4}2(a, b) \in \{1,2,3,4\}^2 (each occurring with probability 1/161/16):

  1. If a=ba = b (doubles) and d=2d = 2: the player moves to state (10,0)(10, 0) with certainty (three consecutive doubles rule).
  2. Otherwise, the player lands on square j=(s+a+b)mod40j = (s + a + b) \bmod 40 and the following redirection rules apply:
    • G2J (j=30j = 30): redirect to (10,d)(10, d') where d=d+1d' = d + 1 if a=ba = b, else d=0d' = 0.
    • Community Chest (j{2,17,33}j \in \{2, 17, 33\}): draw a card uniformly from 16 cards. With probability 1/161/16, move to GO (0); with probability 1/161/16, move to JAIL (10); with probability 14/1614/16, remain at jj.
    • Chance (j{7,22,36}j \in \{7, 22, 36\}): draw a card uniformly from 16 cards. The outcomes are: GO (0), JAIL (10), C1 (11), E2 (24), H2 (39), R1 (5) each with probability 1/161/16; next railroad with probability 2/162/16; next utility with probability 1/161/16; go back 3 squares with probability 1/161/16 (which may trigger a further Community Chest draw); remain at jj with probability 6/166/16.
  3. Set d=d+1d' = d + 1 if a=ba = b (and d<2d < 2), otherwise d=0d' = 0.

Proof. Each of the 16 equiprobable dice outcomes (a,b)(a, b) contributes probability 1/161/16 to the appropriate transitions. The card draw probabilities follow from the uniform distribution over 16 cards for both Community Chest and Chance decks. Since the redirections are deterministic given the card drawn, and card draws are independent of previous events, the transition probabilities are well-defined and sum to 1 from each state. \square

Marginal Distribution

Definition 3 (Marginal square probability). The marginal probability of occupying square ss in stationarity is

πs=d=02π(s,d).\pi_s = \sum_{d=0}^{2} \pi_{(s,d)}.

The three most visited squares are those with the largest values of πs\pi_s.

Editorial

The theoretical model is a Markov chain on states of the form “current square plus consecutive doubles count”, because those are the only pieces of information that affect the next move. In principle one can solve the stationary distribution exactly from that state graph.

The implementation takes the simulation route instead. It performs a very long random walk with a fixed seed, applies every Monopoly rule exactly as it occurs, and counts how often each square is visited. Each turn generates a candidate next state from the dice roll, and that state is then constrained by the special rules for three consecutive doubles, Go To Jail, Community Chest, and Chance. After enough turns, the empirical frequencies stabilize well enough that the top three squares produce the required modal string.

Pseudocode

Initialize the board position, the consecutive-doubles counter, and an array of visit counts.

Repeat for a very large number of turns:
    Roll two 4-sided dice
    Update the doubles counter

    If this is the third consecutive double:
        move directly to JAIL
    Otherwise:
        move forward by the dice total
        apply Go To Jail if needed
        apply Community Chest if needed
        apply Chance if needed, including next railroad, next utility, and go-back-three-squares effects

    Increase the visit count of the final square for this turn

Rank the 40 squares by visit count.
Return the top three square numbers written as a six-digit string.

Complexity Analysis

Time (exact method): O(S3)=O(1203)1.7×106O(|\mathcal{S}|^3) = O(120^3) \approx 1.7 \times 10^6 for Gaussian elimination or eigenvalue decomposition. Power iteration converges in O(S2T)O(|\mathcal{S}|^2 \cdot T) where TT is the number of iterations (typically T100T \sim 100 for convergence to machine precision).

Time (simulation): O(N)O(N) where NN is the number of simulated turns (typically N=107N = 10^7 for sufficient accuracy).

Space: O(S2)=O(14400)O(|\mathcal{S}|^2) = O(14400) for the full transition matrix, or O(S)=O(120)O(|\mathcal{S}|) = O(120) for the stationary vector alone.

Answer

101524\boxed{101524}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_084/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main(){
    // Problem 84: Monopoly Odds
    // Two 4-sided dice. Find the 3 most visited squares via Monte Carlo.
    // Answer: 101524

    const int GO = 0, JAIL = 10, G2J = 30;
    const int CC[] = {2, 17, 33};
    const int CH[] = {7, 22, 36};
    const int R[] = {5, 15, 25, 35};
    const int U[] = {12, 28};

    auto isCC = [&](int s){ return s==2||s==17||s==33; };
    auto isCH = [&](int s){ return s==7||s==22||s==36; };

    auto nextR = [&](int s) -> int {
        for(int r : R) if(s < r) return r;
        return R[0];
    };
    auto nextU = [&](int s) -> int {
        for(int u : U) if(s < u) return u;
        return U[0];
    };

    mt19937 rng(42);
    int SIDES = 4;
    long long visits[40] = {};
    int pos = 0;
    int doubles_count = 0;
    int N = 10000000;

    for(int t = 0; t < N; t++){
        int d1 = rng() % SIDES + 1;
        int d2 = rng() % SIDES + 1;
        bool is_double = (d1 == d2);

        if(is_double){
            doubles_count++;
        } else {
            doubles_count = 0;
        }

        if(doubles_count == 3){
            pos = JAIL;
            doubles_count = 0;
            visits[pos]++;
            continue;
        }

        pos = (pos + d1 + d2) % 40;

        if(pos == G2J){
            pos = JAIL;
        }
        else if(isCC(pos)){
            int card = rng() % 16;
            if(card == 0) pos = GO;
            else if(card == 1) pos = JAIL;
        }
        else if(isCH(pos)){
            int card = rng() % 16;
            switch(card){
                case 0: pos = GO; break;
                case 1: pos = JAIL; break;
                case 2: pos = 11; break;
                case 3: pos = 24; break;
                case 4: pos = 39; break;
                case 5: pos = 5; break;
                case 6: pos = nextR(pos); break;
                case 7: pos = nextR(pos); break;
                case 8: pos = nextU(pos); break;
                case 9:
                    pos = (pos - 3 + 40) % 40;
                    if(isCC(pos)){
                        int cc_card = rng() % 16;
                        if(cc_card == 0) pos = GO;
                        else if(cc_card == 1) pos = JAIL;
                    }
                    break;
                default: break;
            }
        }

        visits[pos]++;
    }

    vector<pair<long long,int>> freq;
    for(int i = 0; i < 40; i++)
        freq.push_back({visits[i], i});
    sort(freq.rbegin(), freq.rend());

    string ans;
    for(int k = 0; k < 3; k++){
        int sq = freq[k].second;
        if(sq < 10) ans += "0";
        ans += to_string(sq);
    }
    cout << ans << endl;

    return 0;
}