PDA

View Full Version : Necco Odds


arbuthnot
06-16-2005, 02:11 PM
I am working through a roll of Necco wafers, and I just had three liquorice Neccos in a row.

This must be rare:

8 flavors.

A wafer of a given flavor exists. The chances of the next wafer being the same flavor are 1 in 8. Same for the next wafer.

1/8 is 0.125.

Therefore, the chances of three wafers of the same flavor, given a single wafer of that flavor to start, are 0.125 x 0.125 = 0.015625, or 1/64, or 1.56%

Now, Neccos are packaged by weight--2.20oz per roll. But that's about 40 wafers. Let's say 40 wafers/roll. We can ignore wafers 39 and 40, as they cannot be followed by two additional wafers.

This means 38 chances to have three wafers of the same flavor in a row. 38 x .015625 = 0.59375, or 19/32, or 59.375%.

That's actually not that rare. You have only a slightly worse chance of getting three Necco wafers of the same flavor in a row, in a given roll of Necco wafers, than Ruben Patterson of the Portland Trail Blazers had of making a given free throw during this year's NBA season.

Unless I'm missing something. Am I missing something?

LetYouDown
06-16-2005, 02:26 PM
Say the first 4 wafers are the same. Does this count twice? If you get 5 in a row, does it count 3 times? You're counting them obviously. Odds change if you say 3 and only 3.

arbuthnot
06-16-2005, 02:50 PM
4 in a row counts twice. We are interested in any possible combination of three in a row.

eephus
06-16-2005, 02:55 PM
[ QUOTE ]
Say the first 4 wafers are the same. Does this count twice? If you get 5 in a row, does it count 3 times? You're counting them obviously. Odds change if you say 3 and only 3.

[/ QUOTE ]

Hi. arbuthnot was kind enough to post my crazy question here.

I want to know what the odds are of ANY three-wafer set of the same flavor showing up.

I think I have it right. If you have a roll of 40 all-chocolate Necco wafers, after all, you have 38 sets of three chocolate wafers. Right?

The problem is that if wafer 1 is not chocolate, you only lose the first possible trio (wafers 1/2/3). Same w/wafer 40 (38/39/40). But if wafer 2 or wafer 39 is not chocolate, you lose two possibilities per wafer (1/2/3, 2/3/4 and 37/38/39, 38/39/40).

Any other wafer, from 3 through 38, you lose three possible sets per nonchocolate wafer.

This makes me think there is a subtlety to this that I haven't taken into account.

LetYouDown
06-16-2005, 02:58 PM
Well, that seems to be the reason that your number is so high...

MikeL05
06-16-2005, 04:03 PM
Compare your math to rolling a die. There are 6 sides, so chances of rolling a SIX is .166667. Now, if you roll it 6 times, it's not the case that you'll hit 1.0 SIXes. You'll hit on average 1.0 SIXes. Likewise, multiplying your percentage (which I believe is right) by 38, you've hit upon .59. This is not your chance of hitting one string of three in a row; this is the average number of 3-in-a-row sets you'll hit in one package.

What I think you need to do is take your probability and subtract it from 1.00. So 1.00 - .0156 = .984. Now raise this number .984 to the exponent "n", where "n" is the number of wafers.

So .984^38 = probability of NOT getting a set of 3 in a row.

1.00 - that = probability of hitting at least one set in 38 wafers.

TomCollins
06-16-2005, 05:32 PM
If you have a roll of 10,000 wafers, does this mean you have a 10,000 x 0.015625 chance of getting 3 in a row?

gaming_mouse
06-16-2005, 05:46 PM
I'm pretty sure that both solutions proposed so far are incorrect. The problem with the "1 - P(NOT)" method is that you do not have independence among the various sets of 3.

I believe you need to solve this using a recurrence relation, but I forget the details of the method. BruceZ or pzhon would know.

In any case, it is at least a moderately difficult problem, IIRC.

gm

gaming_mouse
06-16-2005, 08:11 PM
Also, a quick sim of 1 million trials produced an answer of about 6.3%, which seems reasonable.

gaming_mouse
06-16-2005, 08:37 PM
Link To Bruce's Derivation of the General Formula (http://archiveserver.twoplustwo.com/showthreaded.php?Cat=&Number=293644&page=&view=&sb =5&o=)

The exact answer is 6.16%, which agrees with the sim results.

Siegmund
06-16-2005, 08:47 PM
If we imagine a very long roll of wafers, we can say that 1/64 of the wafers will be immediately followed by at least two identical wafers. In a 10,000-wafer roll we can safely conclude there'll be rouughly 150 matches. That's not the question the original poster asked, of course; but we can get a rough estimate by saying that we expect about 38/64 matches in a roll of 40, and then reduce this a bit more for the chance of streaks of four or two sets of three in one roll.


If you want an exact answer, yes, a recurrence relation works to count the total number of stacks of size n that have no threepeats: x[1]=8, y[1] = 0; x(i)= 7*(x[i-1]+y[i-1]); y(i) = x[i-1].

Are you sorry you asked? Out of 1329227995784915872903807060280344576 possible 40-wafer sequences, 774855372983096359078760714768858504 of them have no sequences of three identical wafers. So: if every sequence is equally likely, 51.95% of rolls have no sets, 48.05% have one or more sets.

pzhon
06-16-2005, 09:04 PM
I think you made at least one and possibly two fence-post errors. You can convert a sequence of 40 flavors into a sequence of 39 change/no change events. Then, 3 identical flavors in a row is a sequence of 2 "no change" events in a row, not 3.

gaming_mouse
06-16-2005, 09:16 PM
[ QUOTE ]
I think you made at least one and possibly two fence-post errors.

[/ QUOTE ]

What's a fence-post error?

[ QUOTE ]
You can convert a sequence of 40 flavors into a sequence of 39 change/no change events. Then, 3 identical flavors in a row is a sequence of 2 "no change" events in a row, not 3.

[/ QUOTE ]

I like that trick, but I'm not sure how that negates the results of my sim or of Bruce's method? Btw, since the question being asked seems to have changed over the course of the thread, I should clarify:

I calculated the chance of at least one streak of 3 licorice wafers in a row, where the chance of each wafer being licorice is 1/8, independently. I think I did that correctly, but let me know if not.

gm

pzhon
06-16-2005, 09:39 PM
[ QUOTE ]
Out of 1329227995784915872903807060280344576 possible 40-wafer sequences, 774855372983096359078760714768858504 of them have no sequences of three identical wafers. So: if every sequence is equally likely, 51.95% of rolls have no sets, 48.05% have one or more sets.

[/ QUOTE ]
Your count agrees with mine, but the quotient should be 58.29% with no sets, and 41.71% with one or more sets.

Here is the distribution of the number of sets in the sense of the original poster, where a streak of 6 in a row counts as 4 sets of 3:

0: .582936
1: .285553
2: .0966622
3: .0266832
...
37: 8.42594 x 10^-35
38: 6.01853 x 10^-36

I used the following transfer matrix T:

7/8 7/8 7/8
1/8 0 0
0 x/8 x/8

The above are the coefficients of x^n in row(1,1,1) T^39 column(1,0,0).

Of course, the expected number of sets is 38/64.

pzhon
06-16-2005, 09:58 PM
[ QUOTE ]
[ QUOTE ]
I think you made at least one and possibly two fence-post errors.

[/ QUOTE ]

What's a fence-post error?

[/ QUOTE ]
It means being off by 1, e.g., iterating a loop once too often in a program or failing to include the last element. If you have 10 lengths of fence for a straight fence, you don't need 10 fence posts. You need 11.

[ QUOTE ]
I calculated the chance of at least one streak of 3 licorice wafers in a row, where the chance of each wafer being licorice is 1/8, independently. I think I did that correctly, but let me know if not.

[/ QUOTE ]
I believe the original poster wanted to know about streaks of any flavor, not just licorice.

I get 6.34585% for the probability of a streak of locorice wafers of length at least 3 out of 40, by BruceZ's method and by a transfer matrix. I get 6.18469% by both methods in a roll of 39, so I think there might be an arithmetic error in your computation. Perhaps it is a round-off error.

0.0634585 = 84350775414536497477575025431563999/1329227995784915872903807060280344576

gaming_mouse
06-16-2005, 10:17 PM
[ QUOTE ]

It means being off by 1, e.g., iterating a loop once too often in a program or failing to include the last element. If you have 10 lengths of fence for a straight fence, you don't need 10 fence posts. You need 11.

[/ QUOTE ]

That's a great term. I make those all the time /images/graemlins/smile.gif

[ QUOTE ]

I get 6.34585% for the probability of a streak of locorice wafers of length at least 3 out of 40, by BruceZ's method and by a transfer matrix. I get 6.18469% by both methods in a roll of 39, so I think there might be an arithmetic error in your computation. Perhaps it is a round-off error.

0.0634585 = 84350775414536497477575025431563999/1329227995784915872903807060280344576

[/ QUOTE ]

I ran the sim again with 2 million trials, and got .0636. I'm sure you are right and that I made a fence post error in my application of BruceZ's method in excel.

Thanks,
gm

gaming_mouse
06-16-2005, 10:24 PM
[ QUOTE ]
x[1]=8, y[1] = 0; x(i)= 7*(x[i-1]+y[i-1])

[/ QUOTE ]

Where does x[1] come from? Are there 3 flavors? (EDIT: That makes no sense. It would be 8 flavors)

Also, I don't follow the rucursion relation. Could you explain the concept? (EDIT: I'm realizing that you were solving a different problem than I was....)

Siegmund
06-17-2005, 03:14 AM
Since your answer was very close to 1/8 our answer, it seems to have gotten you the right place.

The recurrence relation I was using was for counting the number of rolls in which no colour ever appears three times. Such a roll can either have the last two candies the same colour, or different.

X(1)=8 and Y(1)=0: there are 8 rolls of length one where the last candy doesn't match the previous one (there IS no previous one), and one where it does.
Y(i)=X(i-1): each sequence that ends in an unpaired candy can be extended to a longer sequences that ends in a pair in one way.
X(i)=7(X(i-1)+Y(i-1)): a new sequence ending with an unpaired candy can be made in 7 ways for any shorter sequence, whether the short sequence was paired or not.
The OP wishes to know (X(40)+Y(40))/8^40 = (X(40)+X(39))/8^40. (The Y's turn out not to contribute anything to the complexity of the recurrence relation, but it's not as easy to put into words where X(i)=7X(i-1)+7X(i-2) comes from.)

eephus
06-17-2005, 11:46 AM
>>I believe the original poster wanted to know about streaks of any flavor, not just licorice.

correct. i realize now that i wasn't overly clear about that.

so, am i correct in thinking the following?

1. (1 x 1/8 x 1/8) is the chance of drawing three like-flavored wafers in a row, given one draw from a random mixture of wafers, with equal numbers of each flavor therein.

2. therefore, (1 - 1/64) is the chance of NOT drawing three etc. etc.

3. (1 - 1/64)^38 (55%) is the chance of NOT drawing three wafers under the above conditions, given 38 tries.

4. therefore, if you make rolls of 40 wafers, a ballpark estimate of the percentage of rolls w/at least one sequence of like-flavored wafers is about 45%.

5. to fully solve the problem, you have to take into account that wafers 1, 2, 39, and 40 have less impact by being different from their neighbors than do wafers 3 through 38.

is this correct?

thanks!

BruceZ
06-18-2005, 02:16 AM
[ QUOTE ]
3. (1 - 1/64)^38 (55%) is the chance of NOT drawing three wafers under the above conditions, given 38 tries.

[/ QUOTE ]

This is incorrect, except as an approximation. Because the events of wafers starting a run are not independent, these probabilities cannot be multiplied.

BruceZ
06-18-2005, 02:33 AM
[ QUOTE ]
So: if every sequence is equally likely, 51.95% of rolls have no sets, 48.05% have one or more sets.

[/ QUOTE ]

As pzhon has pointed out, 41.7% have one or more sequences of 3 identical.

Since my post that gaming mouse referenced, I have posted a better recursion which gives the probabilities directly without having to sum a column of probabilities at the end. Let P(n) be the probability of a sequence of 3 identical flavors out of 8 flavors by the nth wafer. Then:

P(1) = 0
P(2) = 0
P(3) = (1/8)^2
P(4) = P(3) + 7/8*(1/8)^2
P(n) = P(n-1) + [1 - P(n-3)]*7/8*(1/8)^2 for n > 4

P(40) =~ 41.7%

That is, the probability that it happens in n wafers is the probability that it happens in n-1 wafers plus the probability that it happens first on the nth wafer. To happen first on the nth wafer, it must not happen by wafer n-3, and then wafer n-2 must be different from n-3 which has probability 7/8, and wafer n-1 and n must match wafer n-2 with probability (1/8)^2.