ITPEC FE Subject B April 2025 Question 16

From the answer group below, select the correct combination of answers to be inserted into A through C in the program.

Craps is a casino dice game in which players bet on the outcomes of the roll of a pair dice. In the rules of the game, a player rolls two dice and finds their sum. There possible outcomes could lead to a win or loss.

1.If the sum is 7 or 11, the player wins.2.If the sum is 2, 3 or 12, the player loses.3.Otherwise (the sum is 4, 5, 6, 8, 9 or 10), the player neither wins nor loses. However, the player continues rolling the dice until they either roll the same (initial) sum again (in which case they win the game) or roll a sum of 7 (in which case they lose the game).

The following program approximates the chance of winning a game of Craps using Monte Carlo method and outputs it. The Monte Carlo method is a technique used to estimate the probability of certain outcomes of an experiment by running multiple trial runs, using random numbers. In the program, the playing Craps is illustrated simply by generating random numbers rather than actually rolling a pair of dice. The function random_int(1, 6) generates a random integer number between 1 and 6, and returns it.
The program also calculates and outputs the relative error of the measured approximate probability of winning Craps. In general, the relative error Er is calculated using the following formula:

Er = | (Pm – Pt) / Pt |

where Pm denotes the measured approximate probability and Pt denotes the theoretical probability. The theoretical probability of winning Craps is known to be 244/495.

[Program]
integer: wins_sum ← 0
integer: lose_sum ← 0
integer: n ← 10000
integer: i, dice1, dice2, sum, newsum
real: result, pt ← (244 ÷ 495)
for (increase i from 1 to n by 1)
dice1 ← random_int(1, 6)
dice2 ← random_int(1, 6)
sum ← dice1 + dice2
if (sum = 7 or sum = 11)
wins_sum ← wins_sum + 1
elseif (sum = 2 or sum = 3 or sum = 12)
lose_sum ← lose_sum + 1
else
do
dice1 ← random_int(1, 6)
dice2 ← random_int(1, 6)
newsum ← dice1 + dice2
if (newsum = sum)
wins_sum ← wins_sum + 1
elseif (newsum = 7)
lose_sum ← lose_sum + 1
endif
while (A)
endif
endfor
result ← B
output result, absolute value of (C)

Answer group

OptionABC

Explanation

A: newsum ≠ sum and newsum ≠ 7, B: wins_sum ÷ n, C: (result - pt) ÷ pt — keep rolling while neither ending has come up, estimate the win probability as wins per game, and put it into the relative-error formula.

  • •Blank A: the point phase ends on the first roll equal to the point (a win) or to 7 (a loss). A do-while repeats while its condition is true, so the condition is the negation of newsum = sum or newsum = 7, which by De Morgan is newsum ≠ sum and newsum ≠ 7.
  • •Blank B: each of the n = 10000 games ends in exactly one win or one loss, so wins_sum ÷ n is the measured probability Pm.
  • •Blank C: Er = |(Pm − Pt) / Pt| with result as Pm and pt as Pt; the output statement already applies the absolute value.

Answer (c)

Why not others:

  • •(e), (f), (g) and (h) — with or the condition is false only when newsum equals both the point and 7, which cannot happen because the point is never 7; the loop never exits, and every later 7 or point roll is counted again
  • •(a), (b), (e) and (f) — wins_sum ÷ lose_sum is the win-to-loss ratio, about 244 ÷ 251 ≈ 0.97, not the probability of winning, which is about 0.49
  • •(b), (d), (f) and (h) — result ÷ pt is the ratio Pm / Pt, close to 1 when the estimate is good; relative error needs the difference Pm − Pt, which is close to 0

Key rule: A loop that runs until X or Y continues while not X and not Y (De Morgan), and a Monte Carlo probability is successes divided by the number of trials.

Math & Data Science · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.