Betting on a Low Dice Total
Updated
Problem statement
You are offered a bet. You roll n fair six-sided dice and add up the numbers they show. If the total is at most t, you are paid a dollars. Otherwise, you pay b dollars.
Return the expected profit of one game, in dollars. A positive answer means the bet makes money on average, so you should play. A negative answer means you should not.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
diceBetExpectedValue(n: int, t: int, a: int, b: int) → doubleExamples
Example 1
n = 10t = 30a = 10b = 1return = 1.2546505173404714This is an interview bet: ten dice, paid $10 for a total of 30 or less, pay $1 otherwise.
There are 6^10 = 60,466,176 equally likely rolls, and 12,393,645 of them total 30 or less. So the chance of winning is p = 12,393,645 / 60,466,176, about 0.20497.
The expected profit is 10 × p - 1 × (1 - p) = 11p - 1, about 1.2547. It is positive, so you should play.
Example 2
n = 12t = 29a = 10b = 1return = -0.8176788416386709This is the twelve-dice version: a total under 30 means a total of at most 29.
Of the 6^12 = 2,176,782,336 rolls, 36,079,407 total 29 or less, so p is about 0.016575. The expected profit is 11p - 1, about -0.81768. Twelve dice average 42, so a total under 30 is rare. Do not play.
Example 3
n = 2t = 4a = 3b = 1return = -0.3333333333333333Two dice total 4 or less in 6 of the 36 rolls: (1,1), (1,2), (2,1), (1,3), (2,2) and (3,1). So p = 1/6.
The expected profit is 3 × 1/6 - 1 × 5/6 = -1/3, about -0.33333.
Constraints
1 <= n <= 1000 <= t <= 6000 <= a <= 10^40 <= b <= 10^4
More Susquehanna International Group (SIG) Phone Screen questions
- Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
- Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
- Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
- Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
- Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
- Catching the Bus to the MoviePHONE SCREEN · Seen Jan 2026
- Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
- Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
- One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
- Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025
Similar questions at other companies
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Starting Value with the Longest Collatz ChainZipRecruiter · PHONE SCREENZipRecruiter interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Count Staircase WaysGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- New 21 Game ProbabilityUiPath · PHONE SCREEN
- Count Stepping Numbers In RangeAmazon · PHONE SCREEN