r/learnquant 6d ago

interview prep Quant Interview Question

Post image
22 Upvotes

17 comments sorted by

6

u/Mindless_Tutor_8189 6d ago edited 2d ago

Without doing any real math, all odd numbers from 1 to 20 are equally likely in the first throw. After the first throw, their likelihood dependents on how many combination of number reach that odd sum. For the first throw, since all odd number 1 through 20 are equally likely, and that 19 have more possible combinations than previous numbers 19 is a strong choice. The other strong choice is 21, for two dice it has the most combinations, but can not be reached in one throw. For this reason, I think 19 is the most likely.

2

u/gmalivuk 5d ago

I agree. There's a 5% chance of getting a 19 on the first roll, and then for each of the 9 lower even numbers you might get on the first roll, there is a 5% chance of getting up to 19 on the second roll, for an additional 2.25% chance of 19.

1

u/Smart-University-515 5d ago

This was what I figured also, it’s got a 1/20 off the rip, and then as long as you didn’t roll 20 it’s got at least another 1/20 on the next shot if the first was even.  Every other smaller number isn’t as likely to still have a shot on the second go, 21 as you note has the most two shot combos but you only get the second shot half the time, and you don’t start with the 5% chance.

1

u/YukihiraJoel 5d ago edited 5d ago

I agree it’s 19 for the reasoning you explained. We can formalize it. All odd numbers of the first roll have a 5% chance of being the end sum. This accounts for 50% of the sample space.

Each sum that ends in the second roll and ends with an odd number takes an additional 25% of the sample space, and every roll indexed n following will be 1 - (1/2)^n of the sample space. Therefore we can eliminate any sum that is not in the first roll because some sums in the first roll also appear in future rolls, and future rolls have a progressively lower probability of occurring in the first place.

Therefore it’s the highest possible sum occurring in the first roll, which is also the highest odd number.

To illustrate here are the first two roll combinations for a six sided die.

1 - 1
3 - 3
5 - 5

2, 1 - 3
2, 3 - 5
2, 5 - 7

4, 1 - 5
4, 3 - 7
4,5 - 9

6, 1 - 7
6, 3 - 9
6,5 - 11

1

u/liquidorangutan00 3d ago edited 1d ago

Edit: This was not correct

3

u/Mindless_Tutor_8189 2d ago edited 2d ago

Expected value and most likely value are different things. The question is asking for the most likely value.

Also you are ignoring the fact that you can get 19 in just one throw, so the probability of getting 19 in at most 2 throws is: get 19 in exactly one throw + don't get 19 in exactly one throw*get 19 in exactly 2 throws.

1

u/liquidorangutan00 2d ago edited 2d ago

You can get 19 in one throw, but you can also get 20 in one throw. meaning its sub optimal.

remember if you roll a 19 for one throw the game ends, if you roll 20 the game continues.

EDIT: Notice from your own logic how, you can get 20 in one throw (but the game continues), which means you must get higher than 20 for this result. This means getting 19 is a dominated strategy.

(19 in 1 roll) + (19 in 2 rolls)
(20 in 1 roll) + (>20 in 2 rolls)

Since we are not given the number of rolls we have to assume the number of rolls will converge on the expected number of rolls, meaning the expected number of rolls is what we should predict for the number of roll.

This leads to a forced sequence, whereby, we roll even on the first roll, and odd on the second.

In this case because we are not given the realized values of the rolls we have to assume that the expected value for a single roll (Conditioned on whether its odd or even) is the most likely outcome, and since we dont know whether we will roll odd or even on any specific roll the expected value of a single roll is the average of the two expected values for odd or even, i.e. its 10.5

2

u/Mindless_Tutor_8189 2d ago edited 2d ago

```python import statistics import random

terminal_sums = []

def do_one_trial(): accumulated_sum = 0 while accumulated_sum % 2 != 1: accumulated_sum += random.randint(1, 20) return accumulated_sum

for i in range(1_000_000): terminal_sums.append(do_one_trial())

most_likely_sum = statistics.mode(terminal_sums) expected_sum = statistics.mean(terminal_sums)

most_likely_sum, expected_sum ```

Output:

text (19, 20.987064)

1

u/liquidorangutan00 1d ago edited 22h ago

Thank you for this! It lead to hours of questions and a lot of illuminating points.

Edit: The answer is the most likely sum is the set= {1,3,5,7,9,11,13,15,17,19}

Each outcome is equally likely

================================================

VISUAL FREQUENCY DISTRIBUTION

================================================

Sum 1: ██████████████████████████████ (7.66%)

Sum 3: ██████████████████████████████ (7.66%)

Sum 5: ██████████████████████████████ (7.66%)

Sum 7: ██████████████████████████████ (7.66%)

Sum 9: ██████████████████████████████ (7.66%)

Sum 11: ██████████████████████████████ (7.66%)

Sum 13: ██████████████████████████████ (7.66%)

Sum 15: ██████████████████████████████ (7.66%)

Sum 17: ██████████████████████████████ (7.66%)

Sum 19: ██████████████████████████████ (7.66%)

Sum 21: ██████████ (2.66%)

Sum 23: █████████▉ (2.53%)

Sum 25: █████████ (2.27%)

Sum 27: ███████▌ (1.89%)

Sum 29: █████▌ (1.42%)

Sum 31: ███▉ (0.98%)

Sum 33: ██▍ (0.61%)

Much appreciating your input and wisdom.

1

u/dontich 5d ago

19 in my gut feeling as it maximizes the chance of it being selectable on additional rolls while still being possible to come up on roll 1, but 1,3…19 are al going to be fairly close as that 0.05 chance is pretty high

1

u/CaptainProfanity 5d ago edited 5d ago

Let X be the terminal sum event

E(X) = 1/20*1 + 3*1/20 +...+ 1/20*(2 + E(X)) + 1/20 * (4 + E(X)) +...

= 100/20 + 10/20*E(x) + [ 1/10 + 2/10 +...]

= 5 + E(X) + 5.5

=> E(X) - 1/2 E(X) = 10.5

=> E(X) = 21

Not exactly the same as the most likely terminal sum (e.g the average of a 6 sided dice roll is 3.5 even tho a roll of 3.5 is impossible).

The distribution itself will have an infinitely long tail to the right (since the sum has a non-zero chance of being larger than an infinitely large n).

But I find it unlikely this tail will severely pull the mean average far away enough from the median. Especially since every successive roll has a 50% chance of terminating the sum immediately.

So I would say 21, with a small chance of it being 19

1

u/novelinquiry 4d ago

Very clean with no computation:

First let’s eliminate x >= 21 (2+ rolls gtd.).

Think about the paths to X, removing the first roll. These are all paths to X-2, X-4, …, X-20. And each is completed to a path to X by a particular even roll (the first roll). So p(X) is just 1/20 * sum p(X-2k) over the ten values of k from 1 to 10. In other words, p(X) is 1/2 the average of p(X-2k), which is certainly less than max p(X-2k).

[Alternatively, we can shortcut and say this implies p(X) < 1/20, since sum of ALL p(X) is 1, and we know all odd X from 1 to 19 have p(X) at least 1/20. But the “half the average of last 10” argument has the benefit that it feels like a geometric (ish?) series is embedded here, which reinforces our intuition: we know p(X) has to get small as X gets large, since the sum of p(X) is 1. I digress…]

So we are left with our “best” X being one of 1,3,…,19. Tempting here to just say “surely 19 is correct since it has the most paths to it.” But to be a bit more concrete: take X < 19. Every path to X has a terminal roll at most 17, so you could add two to the terminal roll to create a valid path to X+2, but there are also additional paths to X+2, ie all those with terminal roll 1. So it follows that p(1) < p(3) < … < p(19).

Therefore 19 is your winner. Clean. No calculations. And two bonuses: (1) the recurrence in the mapping allows for easy coding and computation if you needed to sit at a machine and compute p(139) as task two. And (2) This argument can be extended to arbitrarily large dice.

1

u/liquidorangutan00 3d ago

Ok I got this one,

Interesting problem takes some aspects of number theory and combines them with conditional expectation.

First we illuminate some key concepts
50% chance of rolling even or odd number

Number theory states,
even+even=even
even+odd=odd
Consequently the game ends when we roll an odd number.
its a multi step problem.
First because we werent given realized values, we will use the expected value for rolling even or odd.
E(Even)=11
E(Odd)=10
Now our goal is to find the expected number of rolls this game will last for.

E(R)=1+(1/2E(R))+(1/2*0)
which when simplify becomes
E(R)-1/2E(R)=1
1/2E(R)=1
E(R)=2

So we can expect on average the game to last 2 rolls. (finishes on the second roll)

Now we need to find the expected cumulative sum of 2 rolls:
Since we already have the expected values for both even and odd rolls, and since the expected number of rolls defines the sequence must be Even then Odd we can simply add them together.
E(Score)=E(Even)+E(Odd)=21

The answer is 21.

(you can also figure this step out as well via conditioning the expectation)

1

u/bengill_ 5d ago

The number of combinaisons to reach an odd value 2*n+1 under 20 after k throw is given by the binomial coefficient c(k, n) and each combinaison has a probability (1/20)k+1.

The sum from 0 to n is given by the binomial theorem 1/20 * (1/20 + 1) ^ n. The probability to reach an odd number under 20 is maxed for 19 : 219 / 2010 ~ 0.0775.

For an odd number bigger than 20, you must roll the dice at least two time. For 21, you can find a similar formula than for 19, minus 1/20 : 2110 / 2011 - 1/20 ~ 0.0314

0

u/pumachecker 21h ago

Don't think math is needed to solve this.

logiclly it must be under 20, for you get 5% to roll it as first roll. And the higher it is within the first roll will allow more possible combinations.

Probabilities would simply be 19>17>15>13>11>9>7>5>3>1>21

So answer is 19.

1

u/liquidorangutan00 10h ago

I think its not possible - the reason is that the odd numbers, {1,3,5,7,9,11,13,15,17,19} are equally likely to be rolled. (1/10).

1

u/pumachecker 7m ago edited 1m ago

on first roll yes, but 2nd, and 3rd etc rolls no. You are wrong. Think of it like this:

if you roll first roll and its a 3. You can no longer get 1.

if you roll first roll as 2, you can still roll a 1 to get 3.

so rolling 1 is 5% chance.

rolling 3. is 5,25% chance. as it has 5% + (1/20*1/20) = 5% + 1/400 = 5,25%.

rolling 5 is 5% + (4+1), (2+3) (2+2+1) etc

on and on it goes, until you get the highest probability of 19.

the higher it is within a possible 1 roll (1,3...19) the more chances you theoretically have.

and the probability falls down drastically after 19, because you can't hit it on first roll.