2 Monkeys on a computer











up vote
44
down vote

favorite
4












(a) Two monkeys are typing capital letters (A-Z) randomly. The first stops typing when the word COCONUT appears as seven successive letters. The second stops typing when TUNOCOC appears; TUNOCOC is simply COCONUT spelt backwards. Which monkey is expected to type more?



(b) A monkey is typing capital letters (A-Z) randomly. Two squirrels observe the sequence of letters thus generated. The first squirrel wins if COCONUT appears (as seven successive letters) before TUNOCOC. The second squirrel wins if TUNOCOC appears before COCONUT. Which squirrel is more likely to win?



Is there any way to solve it without using markov chains?










share|improve this question









New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 7




    @mukyuu How do people win if dogs are running? It's called betting...
    – LocustHorde
    2 days ago






  • 4




    Welcome to puzzling :) This question is better suited to MATH.SE
    – ABcDexter
    2 days ago








  • 4




    @EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
    – jafe
    2 days ago






  • 1




    @jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
    – Eric Duminil
    2 days ago






  • 2




    Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
    – Weckar E.
    2 days ago















up vote
44
down vote

favorite
4












(a) Two monkeys are typing capital letters (A-Z) randomly. The first stops typing when the word COCONUT appears as seven successive letters. The second stops typing when TUNOCOC appears; TUNOCOC is simply COCONUT spelt backwards. Which monkey is expected to type more?



(b) A monkey is typing capital letters (A-Z) randomly. Two squirrels observe the sequence of letters thus generated. The first squirrel wins if COCONUT appears (as seven successive letters) before TUNOCOC. The second squirrel wins if TUNOCOC appears before COCONUT. Which squirrel is more likely to win?



Is there any way to solve it without using markov chains?










share|improve this question









New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 7




    @mukyuu How do people win if dogs are running? It's called betting...
    – LocustHorde
    2 days ago






  • 4




    Welcome to puzzling :) This question is better suited to MATH.SE
    – ABcDexter
    2 days ago








  • 4




    @EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
    – jafe
    2 days ago






  • 1




    @jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
    – Eric Duminil
    2 days ago






  • 2




    Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
    – Weckar E.
    2 days ago













up vote
44
down vote

favorite
4









up vote
44
down vote

favorite
4






4





(a) Two monkeys are typing capital letters (A-Z) randomly. The first stops typing when the word COCONUT appears as seven successive letters. The second stops typing when TUNOCOC appears; TUNOCOC is simply COCONUT spelt backwards. Which monkey is expected to type more?



(b) A monkey is typing capital letters (A-Z) randomly. Two squirrels observe the sequence of letters thus generated. The first squirrel wins if COCONUT appears (as seven successive letters) before TUNOCOC. The second squirrel wins if TUNOCOC appears before COCONUT. Which squirrel is more likely to win?



Is there any way to solve it without using markov chains?










share|improve this question









New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











(a) Two monkeys are typing capital letters (A-Z) randomly. The first stops typing when the word COCONUT appears as seven successive letters. The second stops typing when TUNOCOC appears; TUNOCOC is simply COCONUT spelt backwards. Which monkey is expected to type more?



(b) A monkey is typing capital letters (A-Z) randomly. Two squirrels observe the sequence of letters thus generated. The first squirrel wins if COCONUT appears (as seven successive letters) before TUNOCOC. The second squirrel wins if TUNOCOC appears before COCONUT. Which squirrel is more likely to win?



Is there any way to solve it without using markov chains?







mathematics probability






share|improve this question









New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Dedwards

329315




329315






New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









anmol porwal

32125




32125




New contributor




anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






anmol porwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 7




    @mukyuu How do people win if dogs are running? It's called betting...
    – LocustHorde
    2 days ago






  • 4




    Welcome to puzzling :) This question is better suited to MATH.SE
    – ABcDexter
    2 days ago








  • 4




    @EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
    – jafe
    2 days ago






  • 1




    @jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
    – Eric Duminil
    2 days ago






  • 2




    Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
    – Weckar E.
    2 days ago














  • 7




    @mukyuu How do people win if dogs are running? It's called betting...
    – LocustHorde
    2 days ago






  • 4




    Welcome to puzzling :) This question is better suited to MATH.SE
    – ABcDexter
    2 days ago








  • 4




    @EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
    – jafe
    2 days ago






  • 1




    @jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
    – Eric Duminil
    2 days ago






  • 2




    Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
    – Weckar E.
    2 days ago








7




7




@mukyuu How do people win if dogs are running? It's called betting...
– LocustHorde
2 days ago




@mukyuu How do people win if dogs are running? It's called betting...
– LocustHorde
2 days ago




4




4




Welcome to puzzling :) This question is better suited to MATH.SE
– ABcDexter
2 days ago






Welcome to puzzling :) This question is better suited to MATH.SE
– ABcDexter
2 days ago






4




4




@EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
– jafe
2 days ago




@EricDuminil I think they'd be equivalent if (b) had two monkeys typing and each squirrel was watching a different monkey. It's a different scenario when both are watching the same monkey.
– jafe
2 days ago




1




1




@jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
– Eric Duminil
2 days ago




@jafe: How so? The question seems to be the same for both (a) and (b): Is it more probable to type COCONUT or TUNOCOC first when typing a stream of random letters?
– Eric Duminil
2 days ago




2




2




Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
– Weckar E.
2 days ago




Please clarify: in a, do the monkeys generate separate input strings or do they co-operate on one?
– Weckar E.
2 days ago










13 Answers
13






active

oldest

votes

















up vote
30
down vote













(a) I claim that the expected typing length are the same for both monkeys. I guess something in my argument will be incorrect, as jafe's answer has 9 approvals, but finding that incorrectness would be helpful to me.



I prove that the probabilty that a monkey ends his typing after exactly $n$ letters is the same for both monkeys, which then implies that the expected typing lengths are the same.



In order for the typing to end after letter number $n$, the last seven letters must be exactly the monkey's preferred word "COCONUT" / "TUNOCOC" and that word cannot ever have appeared before in the text. That word appearing before can be of two kinds:




  1. It could share some letters with the last 7, or

  2. be completely contained in the first $n-7$ letters.


It's easy to see that for the first monkey, case 1 can not happen: If the word "COCONUT" shared some of its letters with the last 7 letters, then the last letter "T" would have to appear a second time in "COCONUT" (besides last place), which it doesn't.



The argument is slightly more complicated for the second monkey, as the last letter ("C") of "TUNOCOC" does appear a second time in it. But "TUNOC" is not the ending part of "TUNOCOC", so also for the second monkey case 1. cannot happen.



Let's recap: In order for each monkey to end typing after exactly $n$ letters, the text it produced must fullfill two criteria:




  • A) The last seven letters must be exactly the monkey's preferred word
    "COCONUT"/"TUNOCOC", and

  • B) The previous $n-7$ letters cannot contain
    the monkey's preferred word.


This is an equivalence: Any sequence of $n$ letters that fulfills A and B (for any of the two monkeys) is a sequence that has that monkey stop after exactly $n$ letters, and vice versa.



Since each letter typed is independent of others, the events that A or B aply to a sequence of $n$ letters (for a given monkey) are also independent, so the respective probabilities can be multiplied. If we use indices $1$ and $2$ to apply for the first and second monkey, we obviuously get



$$ p_1(A)=p_2(A)=left(frac1{26}right)^7$$



Calculating $p_{1/2}(B)$ directly is much harder, but they are the same: Both consider sequences of $n-7$ independent, uniformly distributed letters, and if and only if such a sequence does (does not) contain the word "COCONUT", then the reversed sequence (which is again a sequence of $n-7$ independent, uniformly distributed letters) does (does not) contain the word "TUNOCOC".



So we get



$$p_1(B) = p_2 (B)$$ and this proves my initial claim: The probability that the typing ends after exactly $n$ letters is $p_1(A)p_1(B)$ for the first monkey and $p_2(A)p_2(B)$ for the second, and they are the same.



+++++++



I cannot say why jafe's argument is incorrect, it is very compelling, and as I said initially, it may very well be that it is correct and something I said is incorrect. I just don't see what that may be, in either case.



ADDITION after more thinking and reading the comments:



I think the flaw in jafe's argument is in double counting after "COCOCO". If the next letter is "N", this is counted as 'good' for both the ending "COCO" and continuation "NUT" and the intitial "COCO" and continution "CONUT". However, both can only lead to the same end result "COCOCONUT", the additional "CONUT" option is not really additional.






share|improve this answer










New contributor




Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 3




    The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
    – Evargalo
    2 days ago








  • 2




    How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
    – Ingix
    2 days ago












  • Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
    – Ingix
    2 days ago










  • Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
    – jafe
    2 days ago






  • 1




    I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
    – Evargalo
    2 days ago


















up vote
26
down vote













(a)

Edit: This is incorrect, see comments




The TUNOCOC monkey is expected to type more.


Regardless of the previous letters, the TUNOCOC monkey has 1/26 chance of getting the next letter right. Clearly the COCONUT monkey has at least this, but turns out it does even better: Once it has typed COCO, it has two ways to get the correct result (NUT or CONUT).







share|improve this answer



















  • 4




    Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
    – Ingix
    2 days ago






  • 3




    I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
    – Pieter B
    2 days ago






  • 1




    PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
    – elias
    2 days ago






  • 2




    This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
    – Eric Duminil
    2 days ago






  • 2




    I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
    – jafe
    2 days ago




















up vote
13
down vote













@Ingix provides a good proof, one certainly worthy of the tick, but one that could perhaps use some reinforcement. The answer is that the N number of letters would have the same expected value. A few points that might help @jafe realise the flaw in his proof.




  1. The order of independent events occurs has no directional bias. For example, drawing a King Of Hearts followed by an Ace Of Hearts, from a 52 card deck is no more probable than an Ace followed by a King.

  2. Whilst the COCOCONUT argument might seem to hold water, it's first important to realise that the probability of that 9 letter sequence is the same as the probability of DOCOCONUT, or for that matter TUTUNOCOC having the initial CO does not gain anything to the probability as there's still a 1/26 chance of getting the next letter correct.

  3. The apparent gain of the fallback that COCOCONUT gives you is offset by the amount of extra letters that you have to type. If you get the sequence COCOCONUX, you have wasted 9 letters, whereas TUNOCOX only wastes 7. (And COCOCONUX is far more improbable than TUNOCOX).


TLDR: the order of independent variables has no favoured direction.



(P.S. This is my first stack answer, so feel free to give any constructive feedback)






share|improve this answer










New contributor




WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 2




    Makes sense! Welcome to Puzzling.
    – jafe
    2 days ago










  • I'm still confused about this, but your 3) point seems very good to me
    – George Menoutis
    2 days ago










  • Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
    – Ong Yu Hann
    2 days ago












  • Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
    – WittierDinosaur
    2 days ago




















up vote
10
down vote













(a) has been adequately answered by




Ingix.




In (b), though:




The second squirrel is more likely to win.




Consider:




A simpler example, where instead of typing "COCONUT" or "TUNOCOC", the monkeys are trying to type "AB" or "CA". Also, the keyboard only has "A", "B", and "C" keys. Consider what happens after the first three keystrokes, for which there are 27 possibilities.




In this case:




In 5 out of the 27 possiblities, "AB" appears and "CA" does not. Similarly, in 5 of the possiblities, "CA" appears and "AB" does not. But there's also one possibility, "CAB", where both appear, and squirrel 2 wins. In this instance, the "A" is useful for both, but it was useful for the second squirrel earlier. The "setup" for the first squirrel to match will often result in the second squirrel already having matched.




Now consider:




A similar thing is true of "COCONUT" versus "TUNOCOC". The first squirrel wants "COC" as a setup, but if "COC" does appear, it's often at the tail end (pun intended) of the second squirrel's victory.







share|improve this answer























  • It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
    – Eric Duminil
    2 days ago












  • @Duminil correct. Even simulating a single play-through would be fairly expensive.
    – Sneftel
    2 days ago


















up vote
6
down vote













To settle down which monkey is faster on average, I'll use Markov chains and Mathematica. Define a state $i$, for $i = 0..6$, as that the monkey 1 has currently written $i$ correct subsequent characters of COCONUT, but has never written all of COCONUT. Define a state 7 as the monkey 1 having written COCONUT at least once. Since state 7 cannot be escaped, we say that it is absorptive (other states are transient). The transition matrix for monkey 1 is:



P1 = {
{25, 1, 0, 0, 0, 0, 0, 0},
{24, 1, 1, 0, 0, 0, 0, 0},
{25, 0, 0, 1, 0, 0, 0, 0},
{24, 1, 0, 0, 1, 0, 0, 0},
{24, 0, 0, 1, 0, 1, 0, 0},
{24, 1, 0, 0, 0, 0, 1, 0},
{24, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 26}
} / 26;


Here $P1_{ij}$ is the probability that the monkey 1 transitions from state $i$ to state $j$ on pushing a key. The Markov chain can be visualized as a graph:



p1 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P1];
Graph[Table[StringTake["COCONUT", x], {x, 0, 7}], p1,
VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


Markov chain for monkey 1



Next up, we extract the sub-matrix which does not contain the absorptive state:



Q1 = P1[[1 ;; 7, 1 ;; 7]];


As described here, the expected time for the monkey 1 to write COCONUT (expected time to absorption) starting from state $i$ is given by



t1 = Inverse[IdentityMatrix[7] - Q1].{1, 1, 1, 1, 1, 1, 1};


The exact solution is given by:



-      8031810176
C 8031810150
CO 8031809500
COC 8031792574
COCO 8031352524
COCON 8019928800
COCONU 7722894400


The transition matrix for monkey 2 is given by:



P2 = {
{25, 1, 0, 0, 0, 0, 0, 0},
{24, 1, 1, 0, 0, 0, 0, 0},
{24, 1, 0, 1, 0, 0, 0, 0},
{24, 1, 0, 0, 1, 0, 0, 0},
{24, 1, 0, 0, 0, 1, 0, 0},
{24, 1, 0, 0, 0, 0, 1, 0},
{24, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 26}
} / 26;


The Markov chain for monkey 2 visualized as a graph:



p2 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P2];
Graph[Table[StringTake["TUNOCOC", x], {x, 0, 7}], p2,
VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


Markov chain for monkey 2



By following the same procedure as for monkey 1, we solve $t2$ as:



-      8031810176
T 8031810150
TU 8031809500
TUN 8031792600
TUNO 8031353200
TUNOC 8019928800
TUNOCO 7722894400


Because the monkeys start from the situation when nothing has been written yet, we see that the expected time for them to write their word is the same: 8031810176.



This result can also be obtained directly in Mathematica:



d1 = FirstPassageTimeDistribution[p1, 8];
Mean[d1]





share|improve this answer










New contributor




kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 1




    Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
    – Ingix
    yesterday






  • 1




    It means the expected time is simply 26**7. How anticlimactic! :)
    – Eric Duminil
    18 hours ago


















up vote
2
down vote













I tried to make a C# program to do that for me:



class Program
{
static void Main(string args)
{
Log("Le scimmie si preparano alla sfida");

Monkey monkey1 = new Monkey("COCONUT");
Monkey monkey2 = new Monkey("TUNOCOC");
int counter = 0;

while (true)
{
counter++;
Log("Le scimmie digitano una lettera per la {0}° volta.", counter);

monkey1.PressLetter();
monkey2.PressLetter();

if(monkey1.IsTargetReached() && monkey2.IsTargetReached())
{
Log("Entrambe le scimmie hanno vinto!");
break;
}
else if (monkey1.IsTargetReached())
{
Log("La scimmia "{0}" ha vinto!", monkey1.Target);
break;
}
else if (monkey2.IsTargetReached())
{
Log("La scimmia "{0}" ha vinto!", monkey2.Target);
break;
}
}
Log("Le scimmie si prendono il meritato riposo dopo {0} turni!", counter);
}

private static void Log(string message, params object args)
{
Console.WriteLine(DateTime.Now + " - " + string.Format(message, args));
}
}

public class Monkey
{
private Random Random { get; set; }
public string Target { get; set; }
public string Text { get; set; }

public Monkey(string target)
{
Target = target;
Text = "";
Random = new Random();
}

public void PressLetter()
{
int num = Random.Next(0, 26);
char let = (char)('a' + num);
string lastLetter = let.ToString().ToUpper();
Text += lastLetter;
}

public bool IsTargetReached()
{
return Text.IndexOf(Target) > -1;
}
}



After millions of Monkeys' tries, I ended up thinking that they have
the same possibilities.




Anyway my computer still didn't successfully solve the problem.






share|improve this answer








New contributor




Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 2




    That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
    – Sneftel
    2 days ago






  • 2




    You might want to reduce the alphabet you are using...
    – Evargalo
    2 days ago










  • +1; this works if you reduce the alphabet.
    – Tim C
    yesterday


















up vote
2
down vote













I have tried to create a Markov chain modelling problem a). I haven't even tried to solve it, but the model (i.e. the states and the transitions) should be correct (with one caveat which I'll explain at the end).



First, a simplification: I have reduced the problem to getting either the string A-A-B (as in CO-CO-NUT) or B-A-A (as in TUN-OC-OC), using an alphabet that only includes 3 letters: A, B, and C.



Here's what I've got. This is for AAB:




Markov chain for AAB




As you can see, I have separated the state "Only one A" from the state "AA". It is noteworthy that there is no way to go from "AA" to "A".



And this is for BAA:




enter image description here




I'm not sure what this leads to. I was hoping there would be some visible hint about the solution (like: both chains are very similar, with just one difference that tilts the balance in favour of one of them), but this doesn't seem to be the case.



To be honest, I'm not even sure my simplification from COCONUT to AAB is correct, because in my case A and B are equally likely (both of them are just a letter which is typed with probability P = 1/3), whereas CO and NUT are not (CO is only 2 letters long, NUT is 3). This means that solving my chains could, or could not, help solving the original problem.



Hopefully someone can pick up from here.






share|improve this answer




























    up vote
    2
    down vote













    I'll try to make the argument that the answer to both parts is:




    The two are just as likely.




    We start from the simple fact that the probability that a window of 7 letters reads COCONUT, or TUNOCOC, or anything else, is equal. (It's 26^(-7), as @Ingix said.). Crucially, it's completely independent of any letters that appear before or after the window, simply because these letters are not in the window...



    Now, let's start with (b). We look at letters 1-7. If they say COCONUT, the first squirrel wins. If they say TUNOCOC (at the same probability!), the second one wins. If they say neither, we move on to letters 2-8 and do the same. At this point, letter 1 is completely irrelevant. You see how we move on and on through the letters, until there's a winner, and the chances of either squirrels to win never differ from each other.



    Further clarification:




    • Of course, if letters 2-7 happened to be COCONU, the first squirrel is in a very good position. Similarly (and in the same probability), if they were TUNOCO, the second squirrel is in a good position. But this is symmetrical, so no one has an overall advantage.

    • Of course, if letters 1-7 were TUNOCOC, the chance to get COCONUT at letters 5-11 increases, but this doesn't matter since, in this instance, the game has already finished...

    • In other words, if we were to ask "Which of the two words are we more likely to see at letters 5-11?" (see @abl's comment below), the answer would be TUNOCOC. But the difference is only due to a situation in which the game has already finished. And this is just not the question in hand.


    Part (a) is a very similar. We look at letters 1-7 of both monkeys. If the first monkey typed COCONUT, it wins. If the second one types TUNOCOC, it wins. If neither won, we move on to look at letters 2-8 of both, and so on.



    No Markov chains :)






    share|improve this answer



















    • 1




      Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
      – abl
      yesterday












    • @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
      – Angkor
      14 hours ago








    • 4




      @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
      – abl
      11 hours ago






    • 1




      @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
      – abl
      6 hours ago






    • 1




      @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
      – abl
      6 hours ago


















    up vote
    1
    down vote













    There's good arguments for both sides. Here's code that prove it definitely:



    import numpy as np

    def main():
    m1 = np.array([
    [25, 1, 0, 0, 0, 0, 0, 0],
    [24, 1, 1, 0, 0, 0, 0, 0],
    [25, 0, 0, 1, 0, 0, 0, 0],
    [24, 1, 0, 0, 1, 0, 0, 0],
    [24, 0, 0, 1, 0, 1, 0, 0],
    [24, 1, 0, 0, 0, 0, 1, 0],
    [24, 1, 0, 0, 0, 0, 0, 1],
    [0, 0, 0, 0, 0, 0, 0, 26]], dtype='object')

    m2 = np.array([
    [25, 1, 0, 0, 0, 0, 0, 0],
    [24, 1, 1, 0, 0, 0, 0, 0],
    [24, 1, 0, 1, 0, 0, 0, 0],
    [24, 1, 0, 0, 1, 0, 0, 0],
    [24, 1, 0, 0, 0, 1, 0, 0],
    [24, 1, 0, 0, 0, 0, 1, 0],
    [24, 1, 0, 0, 0, 0, 0, 1],
    [0, 0, 0, 0, 0, 0, 0, 26]], dtype = 'object')

    p1 = np.array([1,0,0,0,0,0,0,0])
    p2 = np.array([1,0,0,0,0,0,0,0])

    for i in range(1000):
    p1 = p1.dot(m1)
    p2 = p2.dot(m2)

    #this shows that how often the two monkes have 1,2,3 letters correct vary
    #but it doesn't affact past the 4th letter
    #print(i,p2 - p1)

    if p1[7] == p2[7]:
    print("after {} steps, both monkeys have equal chances".format(i))
    elif p2[7] > p1[7]:
    print("crap, this whole arguments just got destroyed")
    else:
    print("after {} steps, coconut monkey has {} more ways to have won".format(i, p1[7] - p2[7]))

    main()


    I ran it up to:




    after 99999 steps, both monkeys have equal chances




    No matter the number of steps, both monkeys have equal chances. Even though one monkey is more likely to have exactly the last 1,2, or 3 letters correct.



    (mind-boggling)






    share|improve this answer




























      up vote
      0
      down vote













      Monkey problem



      The crux the problem is the following: do repeated groups influence the expected characters needed to complete a sequence? The answer is




      No, repeated groups bear no influence on the result




      Let's reduce the problem to something similar - AAB vs ABC with only these letters being on the keyboard.



      The probability of obtaining AAB in a sequence is:




      starting at 1: P(A) * P(A) * P(B) = (1/3 * 1/3 * 1/3) +

      starting at 2: P(!A) * P(A) * P(A) * P(B) = 2/3 * (1/3 * 1/3 * 1/3) +

      starting at 3: P(!A) * P(!A) * P(A) * P(A) * P(B) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




      The probability of obtaining ABC in a sequence is:




      starting at 1: P(A) * P(B) * P(C) = (1/3 * 1/3 * 1/3) +

      starting at 2: P(!A) * P(A) * P(B) * P(C) = 2/3 * (1/3 * 1/3 * 1/3) +

      starting at 3: P(!A) * P(!A) * P(A) * P(B) * P(C) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




      This makes it easy to see that




      No matter how you shuffle the desired sequence around, the only thing that influences the probability of it occurring is the length of the sequence.




      Alternative proof:
      All of the possible sequences of 4 letters are:




      AAAA ABAA ACAA BAAA BBAA BCAA CAAA CBAA CCAA

      AAAB ABAB ACAB BAAB BBAB BCAB CAAB CBAB CCAB

      AAAC ABAC ACAC BAAC BBAC BCAC CAAC CBAC CCAC

      AABA ABBA ACBA BABA BBBA BCBA CABA CBBA CCBA

      AABB ABBB ACBB BABB BBBB BCBB CABB CBBB CCBB

      AABC ABBC ACBC BABC BBBC BCBC CABC CBBC CCBC

      AACA ABCA ACCA BACA BBCA BCCA CACA CBCA CCCA

      AACB ABCB ACCB BACB BBCB BCCB CACB CBCB CCCB

      AACC ABCC ACCC BACC BBCC BCCC CACC CBCC CCCC




      And here is the same table with the uninteresting sequences cut out:




      XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      AAAB XXXX XXXX BAAB XXXX XXXX CAAB XXXX XXXX

      XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      AABA XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      AABB XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      AABC XXXX XXXX BABC XXXX XXXX CABC XXXX XXXX

      XXXX ABCA XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      XXXX ABCB XXXX XXXX XXXX XXXX XXXX XXXX XXXX

      XXXX ABCC XXXX XXXX XXXX XXXX XXXX XXXX XXXX




      There are




      3 sequences where AAB starts at position 1: AABA, AABB, AABC

      3 sequences where AAB starts at position 2: AAAB, BAAB, CAAB

      3 sequences where ABC starts at position 1: ABCA, ABCB, ABCC

      3 sequences where ABC starts at position 2: AABC, BABC, CABC




      Thus the answer to the monkey problem is that




      both monkeys have the same chance of finishing first




      Squirrel problem



      Let's consider the string typed by the monkey after a long (infinite) time and make some simplifications that don't affect the outcome to understand the problem better.




      Replace any letter not in COCONUT with X

      Replace all groups of COC with A

      Replace all remaining C's with X

      Replace all remaining O's with B, N's with C, U's with D and T's with E




      The problem now is:




      in the new string will we more likely first find ABCDE or EDCBA?




      And the solution:




      If A, B, C, D and E had the same chances of occurring, the answer would be "both are equally likely", but C, D and E have normal chances of occurring, A has a very low chance of occurring, B has a slightly lower than normal chance.

      Considering a simplified case - 2 letters - P and Q with P occurring more often than Q, PQ has more chances of appearing first than QP.
      This means EDCBA is more likely to appear first than ABCDE.




      Looking at it from a different angle:




      When the unlikely event that A appears in the string, it is equally likely that it is followed by a B as it is that it is preceded by one.

      In the even more unlikely event that an AB or BA appears in the string, it is equally likely that it is followed by a C as it is that it is preceded by one.

      ...

      Which makes it equally likely that ABCDE and EDCBA appear in the string, so when an A appears in either of these sequences, it is equally likely that it starts the ABCDE sequence as it is that it ends the EDCBA sequence.




      Thus, the answer to the squirrel problem is that




      the second squirrel's sequence (TUNOCOC) appears first







      share|improve this answer




























        up vote
        0
        down vote













        I have created the simulation in C# based on Marco's idea.
        The alphabet is reduced and the performance is improved:



        public class Monkey
        {
        private static readonly char alphabet = "ACNOTUXY".ToCharArray();
        private static readonly Random random = new Random();

        public Monkey(string Target)
        {
        target = Target.ToCharArray();
        length = target.Length;
        input = new char[length];
        inputPosition = 0;
        }

        private readonly char target;
        private readonly int length;
        private readonly char input;
        private int inputPosition;

        public bool TargetReached { get; private set; }

        public void PressKey()
        {
        var key = alphabet[random.Next(0, 8)];
        input[inputPosition] = key;
        inputPosition = ++inputPosition % length;
        TargetReached = IsTargetReached();
        }

        private bool IsTargetReached()
        {
        for (var i = 0; i < length; i++)
        {
        if (input[i] != target[i]) return false;
        }
        return true;
        }
        }

        public class Simulator
        {
        private int ties;
        private int monkey1Wins;
        private int monkey2Wins;

        public void Run(int numberOfCompetitons)
        {
        for (var i = 0; i < numberOfCompetitons; i++)
        {
        RunCompetition();
        }
        }

        private void RunCompetition()
        {
        var monkey1 = new Monkey("COCONUT");
        var monkey2 = new Monkey("TUNOCOC");

        while (true)
        {
        monkey1.PressKey();
        monkey2.PressKey();

        if (monkey1.TargetReached && monkey2.TargetReached)
        {
        ties++;
        Console.WriteLine("It's a TIE!");
        break;
        }
        if (monkey1.TargetReached)
        {
        monkey1Wins++;
        Console.WriteLine("Monkey 1 WON!");
        break;
        }
        if (monkey2.TargetReached)
        {
        monkey2Wins++;
        Console.WriteLine("Monkey 2 WON!");
        break;
        }
        }
        }

        public void ShowSummary()
        {
        Console.WriteLine();
        Console.WriteLine($"{ties} TIES");
        Console.WriteLine($
        "Monkey 1: {monkey1Wins} WINS");
        Console.WriteLine($"Monkey 2: {monkey2Wins} WINS");
        }
        }

        internal class Program
        {
        private static void Main()
        {
        var simulator = new Simulator();
        simulator.Run(1000);
        simulator.ShowSummary();
        Console.ReadKey();
        }
        }


        Sample output:



        ...
        Monkey 1 WON!
        Monkey 1 WON!
        Monkey 2 WON!
        Monkey 1 WON!
        Monkey 2 WON!
        Monkey 2 WON!
        Monkey 1 WON!
        Monkey 1 WON!
        Monkey 2 WON!



        0 TIES

        Monkey 1: 498 WINS

        Monkey 2: 502 WINS


        So it seems pretty tied to me







        share|improve this answer










        New contributor




        Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.

























          up vote
          0
          down vote













          For problem (b)



          Not really a satisfactory answer, but...




          At first sight the only difference between "COCONUT" and "TUNOCOC", that could tilt the chances to one side or the other, is that they have more overlap in one order than in the other. "COCONUT" followed by "TUNOCOC" can be overlapped only in the form "COCONUTUNOCOC", while, the other way around, they can be overlapped like "TUNOCOCOCONUT" or like "TUNOCOCONUT".


          If we assume that this is really the only relevant difference, we can try to replicate it with an alphabet small enough to run a simulation. So let's say that the alphabet has only the letters "A", "B" and "X", that the first squirrel is betting on "AAB" and the second on "BAA". Note that those strings show the same property that "AAB" can overlap with "BAA" only in the form "AABAA", but in the other way around it can be either "BAAAB" or "BAAB".


          This is certainly simple enough to simulate. So I wrote a short program that simulates the game 10 million times and calculates the percentage of success of each squirrel. I ran the program several times, and the percentages, while they obviously show some variation, seem to be always in the range of 38.4 - 38.5% of wins for the first squirrel, and 61.5 - 61.6% of wins for the second squirrel.


          If we can extrapolate that to the original problem (not sure that we can) we would expect the second squirrel to have a greater chance at winning, even if by a much smaller margin than in the simulation. Now we only need to find a proper explanation of why.


          The program (in Java):


          public class Monkeys {

          private enum Squirrel {
          FIRST_SQUIRREL,
          SECOND_SQUIRREL
          }

          private static final Random random = new Random();
          private static final char letters = "ABX".toCharArray();

          public static void main(String args) {

          int winsF = 0;
          int winsS = 0;
          int iterations = 10000000;

          for (int i = 0; i < iterations; i++) {

          Squirrel winner = playGame();
          if (winner == Squirrel.FIRST_SQUIRREL) {
          winsF++;
          } else if (winner == Squirrel.SECOND_SQUIRREL) {
          winsS++;
          }
          }

          System.out.println("First squirrel wins: " + ((double) winsF) / (winsF + winsS));
          System.out.println("Second squirrel wins: " + ((double) winsS) / (winsF + winsS));

          }

          private static Squirrel playGame() {
          StringBuilder sb = new StringBuilder();
          while (true) {
          if (sb.length() >= 3) {
          if (sb.substring(sb.length() - 3, sb.length()).equals("AAB")) {
          return Squirrel.FIRST_SQUIRREL;
          }
          if (sb.substring(sb.length() - 3, sb.length()).equals("BAA")) {
          return Squirrel.SECOND_SQUIRREL;
          }
          }
          sb.append(letters[random.nextInt(letters.length)]);
          }
          }
          }






          share|improve this answer








          New contributor




          abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

























            up vote
            -1
            down vote













            Similar to Marco Salerno's answer, I wrote a computer program to solve the monkey problem.



            static void Coconuts(int iterations)
            {
            Tuple<double, double> outcomes = new Tuple<double, double>[iterations];
            char alphabet = new char { 'C', 'O', 'N', 'U', 'T' };
            string target1 = "COCONUT";
            string target2 = "TUNOCOC";
            for(int i = 0; i < iterations; i++)
            {
            outcomes[i] = new Tuple<double, double>(RandomLettersToTarget(alphabet, target1), RandomLettersToTarget(alphabet, target2));
            Console.WriteLine($"{outcomes[i].Item1:0.0}t{outcomes[i].Item2:0.0}");
            }

            double average1 = outcomes.Select(pair => pair.Item1).Average();
            double average2 = outcomes.Select(pair => pair.Item2).Average();

            Console.WriteLine($"Average durations are {average1:00000.0}, {average2:00000.0}");
            }

            static int RandomLettersToTarget(char alphabet, string target, int stepsToInsanity = 100000000)
            {
            string soFar = "";
            int steps = 0;
            while(steps < stepsToInsanity)
            {
            soFar += alphabet[rng.Next(0, alphabet.Length)];
            if(soFar.Length >= target.Length)
            {
            soFar = soFar.Substring(soFar.Length - target.Length, target.Length);
            }
            if(target.Equals(soFar))
            {
            return steps;
            }
            steps++;
            }
            return stepsToInsanity;
            }


            With the reduced alphabet (containing only 5 letters) this program does complete, and the results over thousands of iterations




            show no clear winner. Thus, I conclude that each monkey has equal probability of winning the first game.







            share|improve this answer























              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "559"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              noCode: true, onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });






              anmol porwal is a new contributor. Be nice, and check out our Code of Conduct.










               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f75627%2f2-monkeys-on-a-computer%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              13 Answers
              13






              active

              oldest

              votes








              13 Answers
              13






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              30
              down vote













              (a) I claim that the expected typing length are the same for both monkeys. I guess something in my argument will be incorrect, as jafe's answer has 9 approvals, but finding that incorrectness would be helpful to me.



              I prove that the probabilty that a monkey ends his typing after exactly $n$ letters is the same for both monkeys, which then implies that the expected typing lengths are the same.



              In order for the typing to end after letter number $n$, the last seven letters must be exactly the monkey's preferred word "COCONUT" / "TUNOCOC" and that word cannot ever have appeared before in the text. That word appearing before can be of two kinds:




              1. It could share some letters with the last 7, or

              2. be completely contained in the first $n-7$ letters.


              It's easy to see that for the first monkey, case 1 can not happen: If the word "COCONUT" shared some of its letters with the last 7 letters, then the last letter "T" would have to appear a second time in "COCONUT" (besides last place), which it doesn't.



              The argument is slightly more complicated for the second monkey, as the last letter ("C") of "TUNOCOC" does appear a second time in it. But "TUNOC" is not the ending part of "TUNOCOC", so also for the second monkey case 1. cannot happen.



              Let's recap: In order for each monkey to end typing after exactly $n$ letters, the text it produced must fullfill two criteria:




              • A) The last seven letters must be exactly the monkey's preferred word
                "COCONUT"/"TUNOCOC", and

              • B) The previous $n-7$ letters cannot contain
                the monkey's preferred word.


              This is an equivalence: Any sequence of $n$ letters that fulfills A and B (for any of the two monkeys) is a sequence that has that monkey stop after exactly $n$ letters, and vice versa.



              Since each letter typed is independent of others, the events that A or B aply to a sequence of $n$ letters (for a given monkey) are also independent, so the respective probabilities can be multiplied. If we use indices $1$ and $2$ to apply for the first and second monkey, we obviuously get



              $$ p_1(A)=p_2(A)=left(frac1{26}right)^7$$



              Calculating $p_{1/2}(B)$ directly is much harder, but they are the same: Both consider sequences of $n-7$ independent, uniformly distributed letters, and if and only if such a sequence does (does not) contain the word "COCONUT", then the reversed sequence (which is again a sequence of $n-7$ independent, uniformly distributed letters) does (does not) contain the word "TUNOCOC".



              So we get



              $$p_1(B) = p_2 (B)$$ and this proves my initial claim: The probability that the typing ends after exactly $n$ letters is $p_1(A)p_1(B)$ for the first monkey and $p_2(A)p_2(B)$ for the second, and they are the same.



              +++++++



              I cannot say why jafe's argument is incorrect, it is very compelling, and as I said initially, it may very well be that it is correct and something I said is incorrect. I just don't see what that may be, in either case.



              ADDITION after more thinking and reading the comments:



              I think the flaw in jafe's argument is in double counting after "COCOCO". If the next letter is "N", this is counted as 'good' for both the ending "COCO" and continuation "NUT" and the intitial "COCO" and continution "CONUT". However, both can only lead to the same end result "COCOCONUT", the additional "CONUT" option is not really additional.






              share|improve this answer










              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 3




                The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
                – Evargalo
                2 days ago








              • 2




                How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
                – Ingix
                2 days ago












              • Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
                – Ingix
                2 days ago










              • Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
                – jafe
                2 days ago






              • 1




                I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
                – Evargalo
                2 days ago















              up vote
              30
              down vote













              (a) I claim that the expected typing length are the same for both monkeys. I guess something in my argument will be incorrect, as jafe's answer has 9 approvals, but finding that incorrectness would be helpful to me.



              I prove that the probabilty that a monkey ends his typing after exactly $n$ letters is the same for both monkeys, which then implies that the expected typing lengths are the same.



              In order for the typing to end after letter number $n$, the last seven letters must be exactly the monkey's preferred word "COCONUT" / "TUNOCOC" and that word cannot ever have appeared before in the text. That word appearing before can be of two kinds:




              1. It could share some letters with the last 7, or

              2. be completely contained in the first $n-7$ letters.


              It's easy to see that for the first monkey, case 1 can not happen: If the word "COCONUT" shared some of its letters with the last 7 letters, then the last letter "T" would have to appear a second time in "COCONUT" (besides last place), which it doesn't.



              The argument is slightly more complicated for the second monkey, as the last letter ("C") of "TUNOCOC" does appear a second time in it. But "TUNOC" is not the ending part of "TUNOCOC", so also for the second monkey case 1. cannot happen.



              Let's recap: In order for each monkey to end typing after exactly $n$ letters, the text it produced must fullfill two criteria:




              • A) The last seven letters must be exactly the monkey's preferred word
                "COCONUT"/"TUNOCOC", and

              • B) The previous $n-7$ letters cannot contain
                the monkey's preferred word.


              This is an equivalence: Any sequence of $n$ letters that fulfills A and B (for any of the two monkeys) is a sequence that has that monkey stop after exactly $n$ letters, and vice versa.



              Since each letter typed is independent of others, the events that A or B aply to a sequence of $n$ letters (for a given monkey) are also independent, so the respective probabilities can be multiplied. If we use indices $1$ and $2$ to apply for the first and second monkey, we obviuously get



              $$ p_1(A)=p_2(A)=left(frac1{26}right)^7$$



              Calculating $p_{1/2}(B)$ directly is much harder, but they are the same: Both consider sequences of $n-7$ independent, uniformly distributed letters, and if and only if such a sequence does (does not) contain the word "COCONUT", then the reversed sequence (which is again a sequence of $n-7$ independent, uniformly distributed letters) does (does not) contain the word "TUNOCOC".



              So we get



              $$p_1(B) = p_2 (B)$$ and this proves my initial claim: The probability that the typing ends after exactly $n$ letters is $p_1(A)p_1(B)$ for the first monkey and $p_2(A)p_2(B)$ for the second, and they are the same.



              +++++++



              I cannot say why jafe's argument is incorrect, it is very compelling, and as I said initially, it may very well be that it is correct and something I said is incorrect. I just don't see what that may be, in either case.



              ADDITION after more thinking and reading the comments:



              I think the flaw in jafe's argument is in double counting after "COCOCO". If the next letter is "N", this is counted as 'good' for both the ending "COCO" and continuation "NUT" and the intitial "COCO" and continution "CONUT". However, both can only lead to the same end result "COCOCONUT", the additional "CONUT" option is not really additional.






              share|improve this answer










              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 3




                The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
                – Evargalo
                2 days ago








              • 2




                How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
                – Ingix
                2 days ago












              • Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
                – Ingix
                2 days ago










              • Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
                – jafe
                2 days ago






              • 1




                I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
                – Evargalo
                2 days ago













              up vote
              30
              down vote










              up vote
              30
              down vote









              (a) I claim that the expected typing length are the same for both monkeys. I guess something in my argument will be incorrect, as jafe's answer has 9 approvals, but finding that incorrectness would be helpful to me.



              I prove that the probabilty that a monkey ends his typing after exactly $n$ letters is the same for both monkeys, which then implies that the expected typing lengths are the same.



              In order for the typing to end after letter number $n$, the last seven letters must be exactly the monkey's preferred word "COCONUT" / "TUNOCOC" and that word cannot ever have appeared before in the text. That word appearing before can be of two kinds:




              1. It could share some letters with the last 7, or

              2. be completely contained in the first $n-7$ letters.


              It's easy to see that for the first monkey, case 1 can not happen: If the word "COCONUT" shared some of its letters with the last 7 letters, then the last letter "T" would have to appear a second time in "COCONUT" (besides last place), which it doesn't.



              The argument is slightly more complicated for the second monkey, as the last letter ("C") of "TUNOCOC" does appear a second time in it. But "TUNOC" is not the ending part of "TUNOCOC", so also for the second monkey case 1. cannot happen.



              Let's recap: In order for each monkey to end typing after exactly $n$ letters, the text it produced must fullfill two criteria:




              • A) The last seven letters must be exactly the monkey's preferred word
                "COCONUT"/"TUNOCOC", and

              • B) The previous $n-7$ letters cannot contain
                the monkey's preferred word.


              This is an equivalence: Any sequence of $n$ letters that fulfills A and B (for any of the two monkeys) is a sequence that has that monkey stop after exactly $n$ letters, and vice versa.



              Since each letter typed is independent of others, the events that A or B aply to a sequence of $n$ letters (for a given monkey) are also independent, so the respective probabilities can be multiplied. If we use indices $1$ and $2$ to apply for the first and second monkey, we obviuously get



              $$ p_1(A)=p_2(A)=left(frac1{26}right)^7$$



              Calculating $p_{1/2}(B)$ directly is much harder, but they are the same: Both consider sequences of $n-7$ independent, uniformly distributed letters, and if and only if such a sequence does (does not) contain the word "COCONUT", then the reversed sequence (which is again a sequence of $n-7$ independent, uniformly distributed letters) does (does not) contain the word "TUNOCOC".



              So we get



              $$p_1(B) = p_2 (B)$$ and this proves my initial claim: The probability that the typing ends after exactly $n$ letters is $p_1(A)p_1(B)$ for the first monkey and $p_2(A)p_2(B)$ for the second, and they are the same.



              +++++++



              I cannot say why jafe's argument is incorrect, it is very compelling, and as I said initially, it may very well be that it is correct and something I said is incorrect. I just don't see what that may be, in either case.



              ADDITION after more thinking and reading the comments:



              I think the flaw in jafe's argument is in double counting after "COCOCO". If the next letter is "N", this is counted as 'good' for both the ending "COCO" and continuation "NUT" and the intitial "COCO" and continution "CONUT". However, both can only lead to the same end result "COCOCONUT", the additional "CONUT" option is not really additional.






              share|improve this answer










              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              (a) I claim that the expected typing length are the same for both monkeys. I guess something in my argument will be incorrect, as jafe's answer has 9 approvals, but finding that incorrectness would be helpful to me.



              I prove that the probabilty that a monkey ends his typing after exactly $n$ letters is the same for both monkeys, which then implies that the expected typing lengths are the same.



              In order for the typing to end after letter number $n$, the last seven letters must be exactly the monkey's preferred word "COCONUT" / "TUNOCOC" and that word cannot ever have appeared before in the text. That word appearing before can be of two kinds:




              1. It could share some letters with the last 7, or

              2. be completely contained in the first $n-7$ letters.


              It's easy to see that for the first monkey, case 1 can not happen: If the word "COCONUT" shared some of its letters with the last 7 letters, then the last letter "T" would have to appear a second time in "COCONUT" (besides last place), which it doesn't.



              The argument is slightly more complicated for the second monkey, as the last letter ("C") of "TUNOCOC" does appear a second time in it. But "TUNOC" is not the ending part of "TUNOCOC", so also for the second monkey case 1. cannot happen.



              Let's recap: In order for each monkey to end typing after exactly $n$ letters, the text it produced must fullfill two criteria:




              • A) The last seven letters must be exactly the monkey's preferred word
                "COCONUT"/"TUNOCOC", and

              • B) The previous $n-7$ letters cannot contain
                the monkey's preferred word.


              This is an equivalence: Any sequence of $n$ letters that fulfills A and B (for any of the two monkeys) is a sequence that has that monkey stop after exactly $n$ letters, and vice versa.



              Since each letter typed is independent of others, the events that A or B aply to a sequence of $n$ letters (for a given monkey) are also independent, so the respective probabilities can be multiplied. If we use indices $1$ and $2$ to apply for the first and second monkey, we obviuously get



              $$ p_1(A)=p_2(A)=left(frac1{26}right)^7$$



              Calculating $p_{1/2}(B)$ directly is much harder, but they are the same: Both consider sequences of $n-7$ independent, uniformly distributed letters, and if and only if such a sequence does (does not) contain the word "COCONUT", then the reversed sequence (which is again a sequence of $n-7$ independent, uniformly distributed letters) does (does not) contain the word "TUNOCOC".



              So we get



              $$p_1(B) = p_2 (B)$$ and this proves my initial claim: The probability that the typing ends after exactly $n$ letters is $p_1(A)p_1(B)$ for the first monkey and $p_2(A)p_2(B)$ for the second, and they are the same.



              +++++++



              I cannot say why jafe's argument is incorrect, it is very compelling, and as I said initially, it may very well be that it is correct and something I said is incorrect. I just don't see what that may be, in either case.



              ADDITION after more thinking and reading the comments:



              I think the flaw in jafe's argument is in double counting after "COCOCO". If the next letter is "N", this is counted as 'good' for both the ending "COCO" and continuation "NUT" and the intitial "COCO" and continution "CONUT". However, both can only lead to the same end result "COCOCONUT", the additional "CONUT" option is not really additional.







              share|improve this answer










              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer








              edited 2 days ago





















              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 days ago









              Ingix

              40124




              40124




              New contributor




              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Ingix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              • 3




                The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
                – Evargalo
                2 days ago








              • 2




                How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
                – Ingix
                2 days ago












              • Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
                – Ingix
                2 days ago










              • Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
                – jafe
                2 days ago






              • 1




                I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
                – Evargalo
                2 days ago














              • 3




                The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
                – Evargalo
                2 days ago








              • 2




                How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
                – Ingix
                2 days ago












              • Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
                – Ingix
                2 days ago










              • Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
                – jafe
                2 days ago






              • 1




                I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
                – Evargalo
                2 days ago








              3




              3




              The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
              – Evargalo
              2 days ago






              The caveat is that you show that the proba for each monkey to end after $n$ letters is the same assuming that they both type at least $n$ letters. But the monkey A has a higher probability of having finished beforehand.
              – Evargalo
              2 days ago






              2




              2




              How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
              – Ingix
              2 days ago






              How can that be? If the first monkey has a higher probabilty to finish beforehand than monkey 2, it has to have a higher probabilty to have finished after exactly $k$ letters for some $k < n$, and then my argument applies again. In addition, I do not assume that they have typed at least $n$ letters, I have given exact condtions for that to be true and shown that they have equal probability.
              – Ingix
              2 days ago














              Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
              – Ingix
              2 days ago




              Again, if you think that the first monkey has a higher probabilty to finish beforehand, which do you think is the first letter index at which the first monkey has a higher probability to have finished?
              – Ingix
              2 days ago












              Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
              – jafe
              2 days ago




              Very interesting. Looking at it from this angle, I can't find fault with your reasoning. Hmm...
              – jafe
              2 days ago




              1




              1




              I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
              – Evargalo
              2 days ago




              I am now convinced that this is the correct answer. Very confusing problem, but the flaw is in the other reasoning (see my comment down Viktor Mellgren's answer)
              – Evargalo
              2 days ago










              up vote
              26
              down vote













              (a)

              Edit: This is incorrect, see comments




              The TUNOCOC monkey is expected to type more.


              Regardless of the previous letters, the TUNOCOC monkey has 1/26 chance of getting the next letter right. Clearly the COCONUT monkey has at least this, but turns out it does even better: Once it has typed COCO, it has two ways to get the correct result (NUT or CONUT).







              share|improve this answer



















              • 4




                Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
                – Ingix
                2 days ago






              • 3




                I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
                – Pieter B
                2 days ago






              • 1




                PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
                – elias
                2 days ago






              • 2




                This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
                – Eric Duminil
                2 days ago






              • 2




                I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
                – jafe
                2 days ago

















              up vote
              26
              down vote













              (a)

              Edit: This is incorrect, see comments




              The TUNOCOC monkey is expected to type more.


              Regardless of the previous letters, the TUNOCOC monkey has 1/26 chance of getting the next letter right. Clearly the COCONUT monkey has at least this, but turns out it does even better: Once it has typed COCO, it has two ways to get the correct result (NUT or CONUT).







              share|improve this answer



















              • 4




                Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
                – Ingix
                2 days ago






              • 3




                I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
                – Pieter B
                2 days ago






              • 1




                PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
                – elias
                2 days ago






              • 2




                This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
                – Eric Duminil
                2 days ago






              • 2




                I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
                – jafe
                2 days ago















              up vote
              26
              down vote










              up vote
              26
              down vote









              (a)

              Edit: This is incorrect, see comments




              The TUNOCOC monkey is expected to type more.


              Regardless of the previous letters, the TUNOCOC monkey has 1/26 chance of getting the next letter right. Clearly the COCONUT monkey has at least this, but turns out it does even better: Once it has typed COCO, it has two ways to get the correct result (NUT or CONUT).







              share|improve this answer














              (a)

              Edit: This is incorrect, see comments




              The TUNOCOC monkey is expected to type more.


              Regardless of the previous letters, the TUNOCOC monkey has 1/26 chance of getting the next letter right. Clearly the COCONUT monkey has at least this, but turns out it does even better: Once it has typed COCO, it has two ways to get the correct result (NUT or CONUT).








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 11 hours ago

























              answered 2 days ago









              jafe

              13.7k34141




              13.7k34141








              • 4




                Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
                – Ingix
                2 days ago






              • 3




                I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
                – Pieter B
                2 days ago






              • 1




                PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
                – elias
                2 days ago






              • 2




                This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
                – Eric Duminil
                2 days ago






              • 2




                I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
                – jafe
                2 days ago
















              • 4




                Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
                – Ingix
                2 days ago






              • 3




                I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
                – Pieter B
                2 days ago






              • 1




                PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
                – elias
                2 days ago






              • 2




                This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
                – Eric Duminil
                2 days ago






              • 2




                I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
                – jafe
                2 days ago










              4




              4




              Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
              – Ingix
              2 days ago




              Sounds very compelling, still I think it is wrong, see my solution below. Would be very interested in you (and everybody else, of course) to check my approach.
              – Ingix
              2 days ago




              3




              3




              I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
              – Pieter B
              2 days ago




              I reduced the problem to the monkeys typing FFA or AFF which I think is equivalent. Then I made a computer simulation where I had them imput random characters and select a winner. The simulation does NOT support your answer. They both were winner the same amount of times.
              – Pieter B
              2 days ago




              1




              1




              PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
              – elias
              2 days ago




              PieterB & Evargalo, what is the characterset of the typewriter in the FFA example? I think it needs a third 'wrong' character.
              – elias
              2 days ago




              2




              2




              This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
              – Eric Duminil
              2 days ago




              This answer indeed appears to be wrong but I don't know why. ¯_(ツ)_/¯
              – Eric Duminil
              2 days ago




              2




              2




              I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
              – jafe
              2 days ago






              I listed out all combinations of C,O,U,N,T for up to 11 letters. Indeed both COCONUT and TUNOCOC show up the same number of times for each letter count. D'oh!
              – jafe
              2 days ago












              up vote
              13
              down vote













              @Ingix provides a good proof, one certainly worthy of the tick, but one that could perhaps use some reinforcement. The answer is that the N number of letters would have the same expected value. A few points that might help @jafe realise the flaw in his proof.




              1. The order of independent events occurs has no directional bias. For example, drawing a King Of Hearts followed by an Ace Of Hearts, from a 52 card deck is no more probable than an Ace followed by a King.

              2. Whilst the COCOCONUT argument might seem to hold water, it's first important to realise that the probability of that 9 letter sequence is the same as the probability of DOCOCONUT, or for that matter TUTUNOCOC having the initial CO does not gain anything to the probability as there's still a 1/26 chance of getting the next letter correct.

              3. The apparent gain of the fallback that COCOCONUT gives you is offset by the amount of extra letters that you have to type. If you get the sequence COCOCONUX, you have wasted 9 letters, whereas TUNOCOX only wastes 7. (And COCOCONUX is far more improbable than TUNOCOX).


              TLDR: the order of independent variables has no favoured direction.



              (P.S. This is my first stack answer, so feel free to give any constructive feedback)






              share|improve this answer










              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 2




                Makes sense! Welcome to Puzzling.
                – jafe
                2 days ago










              • I'm still confused about this, but your 3) point seems very good to me
                – George Menoutis
                2 days ago










              • Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
                – Ong Yu Hann
                2 days ago












              • Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
                – WittierDinosaur
                2 days ago

















              up vote
              13
              down vote













              @Ingix provides a good proof, one certainly worthy of the tick, but one that could perhaps use some reinforcement. The answer is that the N number of letters would have the same expected value. A few points that might help @jafe realise the flaw in his proof.




              1. The order of independent events occurs has no directional bias. For example, drawing a King Of Hearts followed by an Ace Of Hearts, from a 52 card deck is no more probable than an Ace followed by a King.

              2. Whilst the COCOCONUT argument might seem to hold water, it's first important to realise that the probability of that 9 letter sequence is the same as the probability of DOCOCONUT, or for that matter TUTUNOCOC having the initial CO does not gain anything to the probability as there's still a 1/26 chance of getting the next letter correct.

              3. The apparent gain of the fallback that COCOCONUT gives you is offset by the amount of extra letters that you have to type. If you get the sequence COCOCONUX, you have wasted 9 letters, whereas TUNOCOX only wastes 7. (And COCOCONUX is far more improbable than TUNOCOX).


              TLDR: the order of independent variables has no favoured direction.



              (P.S. This is my first stack answer, so feel free to give any constructive feedback)






              share|improve this answer










              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 2




                Makes sense! Welcome to Puzzling.
                – jafe
                2 days ago










              • I'm still confused about this, but your 3) point seems very good to me
                – George Menoutis
                2 days ago










              • Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
                – Ong Yu Hann
                2 days ago












              • Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
                – WittierDinosaur
                2 days ago















              up vote
              13
              down vote










              up vote
              13
              down vote









              @Ingix provides a good proof, one certainly worthy of the tick, but one that could perhaps use some reinforcement. The answer is that the N number of letters would have the same expected value. A few points that might help @jafe realise the flaw in his proof.




              1. The order of independent events occurs has no directional bias. For example, drawing a King Of Hearts followed by an Ace Of Hearts, from a 52 card deck is no more probable than an Ace followed by a King.

              2. Whilst the COCOCONUT argument might seem to hold water, it's first important to realise that the probability of that 9 letter sequence is the same as the probability of DOCOCONUT, or for that matter TUTUNOCOC having the initial CO does not gain anything to the probability as there's still a 1/26 chance of getting the next letter correct.

              3. The apparent gain of the fallback that COCOCONUT gives you is offset by the amount of extra letters that you have to type. If you get the sequence COCOCONUX, you have wasted 9 letters, whereas TUNOCOX only wastes 7. (And COCOCONUX is far more improbable than TUNOCOX).


              TLDR: the order of independent variables has no favoured direction.



              (P.S. This is my first stack answer, so feel free to give any constructive feedback)






              share|improve this answer










              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              @Ingix provides a good proof, one certainly worthy of the tick, but one that could perhaps use some reinforcement. The answer is that the N number of letters would have the same expected value. A few points that might help @jafe realise the flaw in his proof.




              1. The order of independent events occurs has no directional bias. For example, drawing a King Of Hearts followed by an Ace Of Hearts, from a 52 card deck is no more probable than an Ace followed by a King.

              2. Whilst the COCOCONUT argument might seem to hold water, it's first important to realise that the probability of that 9 letter sequence is the same as the probability of DOCOCONUT, or for that matter TUTUNOCOC having the initial CO does not gain anything to the probability as there's still a 1/26 chance of getting the next letter correct.

              3. The apparent gain of the fallback that COCOCONUT gives you is offset by the amount of extra letters that you have to type. If you get the sequence COCOCONUX, you have wasted 9 letters, whereas TUNOCOX only wastes 7. (And COCOCONUX is far more improbable than TUNOCOX).


              TLDR: the order of independent variables has no favoured direction.



              (P.S. This is my first stack answer, so feel free to give any constructive feedback)







              share|improve this answer










              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer








              edited 2 days ago





















              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 days ago









              WittierDinosaur

              1314




              1314




              New contributor




              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              WittierDinosaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              • 2




                Makes sense! Welcome to Puzzling.
                – jafe
                2 days ago










              • I'm still confused about this, but your 3) point seems very good to me
                – George Menoutis
                2 days ago










              • Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
                – Ong Yu Hann
                2 days ago












              • Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
                – WittierDinosaur
                2 days ago
















              • 2




                Makes sense! Welcome to Puzzling.
                – jafe
                2 days ago










              • I'm still confused about this, but your 3) point seems very good to me
                – George Menoutis
                2 days ago










              • Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
                – Ong Yu Hann
                2 days ago












              • Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
                – WittierDinosaur
                2 days ago










              2




              2




              Makes sense! Welcome to Puzzling.
              – jafe
              2 days ago




              Makes sense! Welcome to Puzzling.
              – jafe
              2 days ago












              I'm still confused about this, but your 3) point seems very good to me
              – George Menoutis
              2 days ago




              I'm still confused about this, but your 3) point seems very good to me
              – George Menoutis
              2 days ago












              Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
              – Ong Yu Hann
              2 days ago






              Welcome to Puzzling! Yup, your first two points are exactly right. As for the wastage of letters, I don't think it's really a good argument. I'm not sure it works that way. IMO the reason why COCOCONUT is a false benefit, is because when considering the probability of the events happening, you are assuming the letters before the last 7 are essentially random. This means each letter has 26 possibilities. As such, the combination of CO- as a prefix to COCONUT is already considered within the probability count. To factor it in again is double counting.
              – Ong Yu Hann
              2 days ago














              Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
              – WittierDinosaur
              2 days ago






              Thanks for your feedback @Ong Yu Hann. The difference between the 3rd point and the others is that the first 2 are easily provable mathematical facts. The 3rd is simply to help people logically understand why COCOCOCO doesn't provide a probabilistic benefit.
              – WittierDinosaur
              2 days ago












              up vote
              10
              down vote













              (a) has been adequately answered by




              Ingix.




              In (b), though:




              The second squirrel is more likely to win.




              Consider:




              A simpler example, where instead of typing "COCONUT" or "TUNOCOC", the monkeys are trying to type "AB" or "CA". Also, the keyboard only has "A", "B", and "C" keys. Consider what happens after the first three keystrokes, for which there are 27 possibilities.




              In this case:




              In 5 out of the 27 possiblities, "AB" appears and "CA" does not. Similarly, in 5 of the possiblities, "CA" appears and "AB" does not. But there's also one possibility, "CAB", where both appear, and squirrel 2 wins. In this instance, the "A" is useful for both, but it was useful for the second squirrel earlier. The "setup" for the first squirrel to match will often result in the second squirrel already having matched.




              Now consider:




              A similar thing is true of "COCONUT" versus "TUNOCOC". The first squirrel wants "COC" as a setup, but if "COC" does appear, it's often at the tail end (pun intended) of the second squirrel's victory.







              share|improve this answer























              • It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
                – Eric Duminil
                2 days ago












              • @Duminil correct. Even simulating a single play-through would be fairly expensive.
                – Sneftel
                2 days ago















              up vote
              10
              down vote













              (a) has been adequately answered by




              Ingix.




              In (b), though:




              The second squirrel is more likely to win.




              Consider:




              A simpler example, where instead of typing "COCONUT" or "TUNOCOC", the monkeys are trying to type "AB" or "CA". Also, the keyboard only has "A", "B", and "C" keys. Consider what happens after the first three keystrokes, for which there are 27 possibilities.




              In this case:




              In 5 out of the 27 possiblities, "AB" appears and "CA" does not. Similarly, in 5 of the possiblities, "CA" appears and "AB" does not. But there's also one possibility, "CAB", where both appear, and squirrel 2 wins. In this instance, the "A" is useful for both, but it was useful for the second squirrel earlier. The "setup" for the first squirrel to match will often result in the second squirrel already having matched.




              Now consider:




              A similar thing is true of "COCONUT" versus "TUNOCOC". The first squirrel wants "COC" as a setup, but if "COC" does appear, it's often at the tail end (pun intended) of the second squirrel's victory.







              share|improve this answer























              • It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
                – Eric Duminil
                2 days ago












              • @Duminil correct. Even simulating a single play-through would be fairly expensive.
                – Sneftel
                2 days ago













              up vote
              10
              down vote










              up vote
              10
              down vote









              (a) has been adequately answered by




              Ingix.




              In (b), though:




              The second squirrel is more likely to win.




              Consider:




              A simpler example, where instead of typing "COCONUT" or "TUNOCOC", the monkeys are trying to type "AB" or "CA". Also, the keyboard only has "A", "B", and "C" keys. Consider what happens after the first three keystrokes, for which there are 27 possibilities.




              In this case:




              In 5 out of the 27 possiblities, "AB" appears and "CA" does not. Similarly, in 5 of the possiblities, "CA" appears and "AB" does not. But there's also one possibility, "CAB", where both appear, and squirrel 2 wins. In this instance, the "A" is useful for both, but it was useful for the second squirrel earlier. The "setup" for the first squirrel to match will often result in the second squirrel already having matched.




              Now consider:




              A similar thing is true of "COCONUT" versus "TUNOCOC". The first squirrel wants "COC" as a setup, but if "COC" does appear, it's often at the tail end (pun intended) of the second squirrel's victory.







              share|improve this answer














              (a) has been adequately answered by




              Ingix.




              In (b), though:




              The second squirrel is more likely to win.




              Consider:




              A simpler example, where instead of typing "COCONUT" or "TUNOCOC", the monkeys are trying to type "AB" or "CA". Also, the keyboard only has "A", "B", and "C" keys. Consider what happens after the first three keystrokes, for which there are 27 possibilities.




              In this case:




              In 5 out of the 27 possiblities, "AB" appears and "CA" does not. Similarly, in 5 of the possiblities, "CA" appears and "AB" does not. But there's also one possibility, "CAB", where both appear, and squirrel 2 wins. In this instance, the "A" is useful for both, but it was useful for the second squirrel earlier. The "setup" for the first squirrel to match will often result in the second squirrel already having matched.




              Now consider:




              A similar thing is true of "COCONUT" versus "TUNOCOC". The first squirrel wants "COC" as a setup, but if "COC" does appear, it's often at the tail end (pun intended) of the second squirrel's victory.








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago

























              answered 2 days ago









              Sneftel

              1,5431019




              1,5431019












              • It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
                – Eric Duminil
                2 days ago












              • @Duminil correct. Even simulating a single play-through would be fairly expensive.
                – Sneftel
                2 days ago


















              • It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
                – Eric Duminil
                2 days ago












              • @Duminil correct. Even simulating a single play-through would be fairly expensive.
                – Sneftel
                2 days ago
















              It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
              – Eric Duminil
              2 days ago






              It sounds plausible. But it would also mean that if there's any bias, it will be probably too small to be detected by random simulations, right?
              – Eric Duminil
              2 days ago














              @Duminil correct. Even simulating a single play-through would be fairly expensive.
              – Sneftel
              2 days ago




              @Duminil correct. Even simulating a single play-through would be fairly expensive.
              – Sneftel
              2 days ago










              up vote
              6
              down vote













              To settle down which monkey is faster on average, I'll use Markov chains and Mathematica. Define a state $i$, for $i = 0..6$, as that the monkey 1 has currently written $i$ correct subsequent characters of COCONUT, but has never written all of COCONUT. Define a state 7 as the monkey 1 having written COCONUT at least once. Since state 7 cannot be escaped, we say that it is absorptive (other states are transient). The transition matrix for monkey 1 is:



              P1 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {25, 0, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 0, 0, 1, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              Here $P1_{ij}$ is the probability that the monkey 1 transitions from state $i$ to state $j$ on pushing a key. The Markov chain can be visualized as a graph:



              p1 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P1];
              Graph[Table[StringTake["COCONUT", x], {x, 0, 7}], p1,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 1



              Next up, we extract the sub-matrix which does not contain the absorptive state:



              Q1 = P1[[1 ;; 7, 1 ;; 7]];


              As described here, the expected time for the monkey 1 to write COCONUT (expected time to absorption) starting from state $i$ is given by



              t1 = Inverse[IdentityMatrix[7] - Q1].{1, 1, 1, 1, 1, 1, 1};


              The exact solution is given by:



              -      8031810176
              C 8031810150
              CO 8031809500
              COC 8031792574
              COCO 8031352524
              COCON 8019928800
              COCONU 7722894400


              The transition matrix for monkey 2 is given by:



              P2 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {24, 1, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 1, 0, 0, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              The Markov chain for monkey 2 visualized as a graph:



              p2 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P2];
              Graph[Table[StringTake["TUNOCOC", x], {x, 0, 7}], p2,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 2



              By following the same procedure as for monkey 1, we solve $t2$ as:



              -      8031810176
              T 8031810150
              TU 8031809500
              TUN 8031792600
              TUNO 8031353200
              TUNOC 8019928800
              TUNOCO 7722894400


              Because the monkeys start from the situation when nothing has been written yet, we see that the expected time for them to write their word is the same: 8031810176.



              This result can also be obtained directly in Mathematica:



              d1 = FirstPassageTimeDistribution[p1, 8];
              Mean[d1]





              share|improve this answer










              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 1




                Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
                – Ingix
                yesterday






              • 1




                It means the expected time is simply 26**7. How anticlimactic! :)
                – Eric Duminil
                18 hours ago















              up vote
              6
              down vote













              To settle down which monkey is faster on average, I'll use Markov chains and Mathematica. Define a state $i$, for $i = 0..6$, as that the monkey 1 has currently written $i$ correct subsequent characters of COCONUT, but has never written all of COCONUT. Define a state 7 as the monkey 1 having written COCONUT at least once. Since state 7 cannot be escaped, we say that it is absorptive (other states are transient). The transition matrix for monkey 1 is:



              P1 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {25, 0, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 0, 0, 1, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              Here $P1_{ij}$ is the probability that the monkey 1 transitions from state $i$ to state $j$ on pushing a key. The Markov chain can be visualized as a graph:



              p1 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P1];
              Graph[Table[StringTake["COCONUT", x], {x, 0, 7}], p1,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 1



              Next up, we extract the sub-matrix which does not contain the absorptive state:



              Q1 = P1[[1 ;; 7, 1 ;; 7]];


              As described here, the expected time for the monkey 1 to write COCONUT (expected time to absorption) starting from state $i$ is given by



              t1 = Inverse[IdentityMatrix[7] - Q1].{1, 1, 1, 1, 1, 1, 1};


              The exact solution is given by:



              -      8031810176
              C 8031810150
              CO 8031809500
              COC 8031792574
              COCO 8031352524
              COCON 8019928800
              COCONU 7722894400


              The transition matrix for monkey 2 is given by:



              P2 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {24, 1, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 1, 0, 0, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              The Markov chain for monkey 2 visualized as a graph:



              p2 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P2];
              Graph[Table[StringTake["TUNOCOC", x], {x, 0, 7}], p2,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 2



              By following the same procedure as for monkey 1, we solve $t2$ as:



              -      8031810176
              T 8031810150
              TU 8031809500
              TUN 8031792600
              TUNO 8031353200
              TUNOC 8019928800
              TUNOCO 7722894400


              Because the monkeys start from the situation when nothing has been written yet, we see that the expected time for them to write their word is the same: 8031810176.



              This result can also be obtained directly in Mathematica:



              d1 = FirstPassageTimeDistribution[p1, 8];
              Mean[d1]





              share|improve this answer










              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 1




                Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
                – Ingix
                yesterday






              • 1




                It means the expected time is simply 26**7. How anticlimactic! :)
                – Eric Duminil
                18 hours ago













              up vote
              6
              down vote










              up vote
              6
              down vote









              To settle down which monkey is faster on average, I'll use Markov chains and Mathematica. Define a state $i$, for $i = 0..6$, as that the monkey 1 has currently written $i$ correct subsequent characters of COCONUT, but has never written all of COCONUT. Define a state 7 as the monkey 1 having written COCONUT at least once. Since state 7 cannot be escaped, we say that it is absorptive (other states are transient). The transition matrix for monkey 1 is:



              P1 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {25, 0, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 0, 0, 1, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              Here $P1_{ij}$ is the probability that the monkey 1 transitions from state $i$ to state $j$ on pushing a key. The Markov chain can be visualized as a graph:



              p1 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P1];
              Graph[Table[StringTake["COCONUT", x], {x, 0, 7}], p1,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 1



              Next up, we extract the sub-matrix which does not contain the absorptive state:



              Q1 = P1[[1 ;; 7, 1 ;; 7]];


              As described here, the expected time for the monkey 1 to write COCONUT (expected time to absorption) starting from state $i$ is given by



              t1 = Inverse[IdentityMatrix[7] - Q1].{1, 1, 1, 1, 1, 1, 1};


              The exact solution is given by:



              -      8031810176
              C 8031810150
              CO 8031809500
              COC 8031792574
              COCO 8031352524
              COCON 8019928800
              COCONU 7722894400


              The transition matrix for monkey 2 is given by:



              P2 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {24, 1, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 1, 0, 0, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              The Markov chain for monkey 2 visualized as a graph:



              p2 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P2];
              Graph[Table[StringTake["TUNOCOC", x], {x, 0, 7}], p2,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 2



              By following the same procedure as for monkey 1, we solve $t2$ as:



              -      8031810176
              T 8031810150
              TU 8031809500
              TUN 8031792600
              TUNO 8031353200
              TUNOC 8019928800
              TUNOCO 7722894400


              Because the monkeys start from the situation when nothing has been written yet, we see that the expected time for them to write their word is the same: 8031810176.



              This result can also be obtained directly in Mathematica:



              d1 = FirstPassageTimeDistribution[p1, 8];
              Mean[d1]





              share|improve this answer










              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              To settle down which monkey is faster on average, I'll use Markov chains and Mathematica. Define a state $i$, for $i = 0..6$, as that the monkey 1 has currently written $i$ correct subsequent characters of COCONUT, but has never written all of COCONUT. Define a state 7 as the monkey 1 having written COCONUT at least once. Since state 7 cannot be escaped, we say that it is absorptive (other states are transient). The transition matrix for monkey 1 is:



              P1 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {25, 0, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 0, 0, 1, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              Here $P1_{ij}$ is the probability that the monkey 1 transitions from state $i$ to state $j$ on pushing a key. The Markov chain can be visualized as a graph:



              p1 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P1];
              Graph[Table[StringTake["COCONUT", x], {x, 0, 7}], p1,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 1



              Next up, we extract the sub-matrix which does not contain the absorptive state:



              Q1 = P1[[1 ;; 7, 1 ;; 7]];


              As described here, the expected time for the monkey 1 to write COCONUT (expected time to absorption) starting from state $i$ is given by



              t1 = Inverse[IdentityMatrix[7] - Q1].{1, 1, 1, 1, 1, 1, 1};


              The exact solution is given by:



              -      8031810176
              C 8031810150
              CO 8031809500
              COC 8031792574
              COCO 8031352524
              COCON 8019928800
              COCONU 7722894400


              The transition matrix for monkey 2 is given by:



              P2 = {
              {25, 1, 0, 0, 0, 0, 0, 0},
              {24, 1, 1, 0, 0, 0, 0, 0},
              {24, 1, 0, 1, 0, 0, 0, 0},
              {24, 1, 0, 0, 1, 0, 0, 0},
              {24, 1, 0, 0, 0, 1, 0, 0},
              {24, 1, 0, 0, 0, 0, 1, 0},
              {24, 1, 0, 0, 0, 0, 0, 1},
              {0, 0, 0, 0, 0, 0, 0, 26}
              } / 26;


              The Markov chain for monkey 2 visualized as a graph:



              p2 = DiscreteMarkovProcess[{1, 0, 0, 0, 0, 0, 0, 0}, P2];
              Graph[Table[StringTake["TUNOCOC", x], {x, 0, 7}], p2,
              VertexSize -> 0.6, GraphLayout -> {VertexLayout -> "CircularEmbedding" }]


              Markov chain for monkey 2



              By following the same procedure as for monkey 1, we solve $t2$ as:



              -      8031810176
              T 8031810150
              TU 8031809500
              TUN 8031792600
              TUNO 8031353200
              TUNOC 8019928800
              TUNOCO 7722894400


              Because the monkeys start from the situation when nothing has been written yet, we see that the expected time for them to write their word is the same: 8031810176.



              This result can also be obtained directly in Mathematica:



              d1 = FirstPassageTimeDistribution[p1, 8];
              Mean[d1]






              share|improve this answer










              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer








              edited yesterday





















              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered yesterday









              kaba

              1612




              1612




              New contributor




              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              kaba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              • 1




                Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
                – Ingix
                yesterday






              • 1




                It means the expected time is simply 26**7. How anticlimactic! :)
                – Eric Duminil
                18 hours ago














              • 1




                Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
                – Ingix
                yesterday






              • 1




                It means the expected time is simply 26**7. How anticlimactic! :)
                – Eric Duminil
                18 hours ago








              1




              1




              Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
              – Ingix
              yesterday




              Thanks for doing the work of establishing the Markov matrices and doing the calculations! It should be noted that the discussed effects about the repeated sub-words "CO" and "OC" can be seen: the expected value vectors start and and end the same, but have different values for COC/TUN and COCO/TUNO. The differences just vanish again in the end. The reason for this is IMO that COCONUT can not overlap with itself in a text (like e.g. NUTNU could). That means that for all such words of the same length (say "TOBACCO"), the expected time should be exactly the same.
              – Ingix
              yesterday




              1




              1




              It means the expected time is simply 26**7. How anticlimactic! :)
              – Eric Duminil
              18 hours ago




              It means the expected time is simply 26**7. How anticlimactic! :)
              – Eric Duminil
              18 hours ago










              up vote
              2
              down vote













              I tried to make a C# program to do that for me:



              class Program
              {
              static void Main(string args)
              {
              Log("Le scimmie si preparano alla sfida");

              Monkey monkey1 = new Monkey("COCONUT");
              Monkey monkey2 = new Monkey("TUNOCOC");
              int counter = 0;

              while (true)
              {
              counter++;
              Log("Le scimmie digitano una lettera per la {0}° volta.", counter);

              monkey1.PressLetter();
              monkey2.PressLetter();

              if(monkey1.IsTargetReached() && monkey2.IsTargetReached())
              {
              Log("Entrambe le scimmie hanno vinto!");
              break;
              }
              else if (monkey1.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey1.Target);
              break;
              }
              else if (monkey2.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey2.Target);
              break;
              }
              }
              Log("Le scimmie si prendono il meritato riposo dopo {0} turni!", counter);
              }

              private static void Log(string message, params object args)
              {
              Console.WriteLine(DateTime.Now + " - " + string.Format(message, args));
              }
              }

              public class Monkey
              {
              private Random Random { get; set; }
              public string Target { get; set; }
              public string Text { get; set; }

              public Monkey(string target)
              {
              Target = target;
              Text = "";
              Random = new Random();
              }

              public void PressLetter()
              {
              int num = Random.Next(0, 26);
              char let = (char)('a' + num);
              string lastLetter = let.ToString().ToUpper();
              Text += lastLetter;
              }

              public bool IsTargetReached()
              {
              return Text.IndexOf(Target) > -1;
              }
              }



              After millions of Monkeys' tries, I ended up thinking that they have
              the same possibilities.




              Anyway my computer still didn't successfully solve the problem.






              share|improve this answer








              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 2




                That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
                – Sneftel
                2 days ago






              • 2




                You might want to reduce the alphabet you are using...
                – Evargalo
                2 days ago










              • +1; this works if you reduce the alphabet.
                – Tim C
                yesterday















              up vote
              2
              down vote













              I tried to make a C# program to do that for me:



              class Program
              {
              static void Main(string args)
              {
              Log("Le scimmie si preparano alla sfida");

              Monkey monkey1 = new Monkey("COCONUT");
              Monkey monkey2 = new Monkey("TUNOCOC");
              int counter = 0;

              while (true)
              {
              counter++;
              Log("Le scimmie digitano una lettera per la {0}° volta.", counter);

              monkey1.PressLetter();
              monkey2.PressLetter();

              if(monkey1.IsTargetReached() && monkey2.IsTargetReached())
              {
              Log("Entrambe le scimmie hanno vinto!");
              break;
              }
              else if (monkey1.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey1.Target);
              break;
              }
              else if (monkey2.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey2.Target);
              break;
              }
              }
              Log("Le scimmie si prendono il meritato riposo dopo {0} turni!", counter);
              }

              private static void Log(string message, params object args)
              {
              Console.WriteLine(DateTime.Now + " - " + string.Format(message, args));
              }
              }

              public class Monkey
              {
              private Random Random { get; set; }
              public string Target { get; set; }
              public string Text { get; set; }

              public Monkey(string target)
              {
              Target = target;
              Text = "";
              Random = new Random();
              }

              public void PressLetter()
              {
              int num = Random.Next(0, 26);
              char let = (char)('a' + num);
              string lastLetter = let.ToString().ToUpper();
              Text += lastLetter;
              }

              public bool IsTargetReached()
              {
              return Text.IndexOf(Target) > -1;
              }
              }



              After millions of Monkeys' tries, I ended up thinking that they have
              the same possibilities.




              Anyway my computer still didn't successfully solve the problem.






              share|improve this answer








              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.














              • 2




                That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
                – Sneftel
                2 days ago






              • 2




                You might want to reduce the alphabet you are using...
                – Evargalo
                2 days ago










              • +1; this works if you reduce the alphabet.
                – Tim C
                yesterday













              up vote
              2
              down vote










              up vote
              2
              down vote









              I tried to make a C# program to do that for me:



              class Program
              {
              static void Main(string args)
              {
              Log("Le scimmie si preparano alla sfida");

              Monkey monkey1 = new Monkey("COCONUT");
              Monkey monkey2 = new Monkey("TUNOCOC");
              int counter = 0;

              while (true)
              {
              counter++;
              Log("Le scimmie digitano una lettera per la {0}° volta.", counter);

              monkey1.PressLetter();
              monkey2.PressLetter();

              if(monkey1.IsTargetReached() && monkey2.IsTargetReached())
              {
              Log("Entrambe le scimmie hanno vinto!");
              break;
              }
              else if (monkey1.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey1.Target);
              break;
              }
              else if (monkey2.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey2.Target);
              break;
              }
              }
              Log("Le scimmie si prendono il meritato riposo dopo {0} turni!", counter);
              }

              private static void Log(string message, params object args)
              {
              Console.WriteLine(DateTime.Now + " - " + string.Format(message, args));
              }
              }

              public class Monkey
              {
              private Random Random { get; set; }
              public string Target { get; set; }
              public string Text { get; set; }

              public Monkey(string target)
              {
              Target = target;
              Text = "";
              Random = new Random();
              }

              public void PressLetter()
              {
              int num = Random.Next(0, 26);
              char let = (char)('a' + num);
              string lastLetter = let.ToString().ToUpper();
              Text += lastLetter;
              }

              public bool IsTargetReached()
              {
              return Text.IndexOf(Target) > -1;
              }
              }



              After millions of Monkeys' tries, I ended up thinking that they have
              the same possibilities.




              Anyway my computer still didn't successfully solve the problem.






              share|improve this answer








              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              I tried to make a C# program to do that for me:



              class Program
              {
              static void Main(string args)
              {
              Log("Le scimmie si preparano alla sfida");

              Monkey monkey1 = new Monkey("COCONUT");
              Monkey monkey2 = new Monkey("TUNOCOC");
              int counter = 0;

              while (true)
              {
              counter++;
              Log("Le scimmie digitano una lettera per la {0}° volta.", counter);

              monkey1.PressLetter();
              monkey2.PressLetter();

              if(monkey1.IsTargetReached() && monkey2.IsTargetReached())
              {
              Log("Entrambe le scimmie hanno vinto!");
              break;
              }
              else if (monkey1.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey1.Target);
              break;
              }
              else if (monkey2.IsTargetReached())
              {
              Log("La scimmia "{0}" ha vinto!", monkey2.Target);
              break;
              }
              }
              Log("Le scimmie si prendono il meritato riposo dopo {0} turni!", counter);
              }

              private static void Log(string message, params object args)
              {
              Console.WriteLine(DateTime.Now + " - " + string.Format(message, args));
              }
              }

              public class Monkey
              {
              private Random Random { get; set; }
              public string Target { get; set; }
              public string Text { get; set; }

              public Monkey(string target)
              {
              Target = target;
              Text = "";
              Random = new Random();
              }

              public void PressLetter()
              {
              int num = Random.Next(0, 26);
              char let = (char)('a' + num);
              string lastLetter = let.ToString().ToUpper();
              Text += lastLetter;
              }

              public bool IsTargetReached()
              {
              return Text.IndexOf(Target) > -1;
              }
              }



              After millions of Monkeys' tries, I ended up thinking that they have
              the same possibilities.




              Anyway my computer still didn't successfully solve the problem.







              share|improve this answer








              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 days ago









              Marco Salerno

              1292




              1292




              New contributor




              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Marco Salerno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              • 2




                That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
                – Sneftel
                2 days ago






              • 2




                You might want to reduce the alphabet you are using...
                – Evargalo
                2 days ago










              • +1; this works if you reduce the alphabet.
                – Tim C
                yesterday














              • 2




                That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
                – Sneftel
                2 days ago






              • 2




                You might want to reduce the alphabet you are using...
                – Evargalo
                2 days ago










              • +1; this works if you reduce the alphabet.
                – Tim C
                yesterday








              2




              2




              That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
              – Sneftel
              2 days ago




              That's not surprising. The expected number of keystrokes before either monkey wins is well into the billions.
              – Sneftel
              2 days ago




              2




              2




              You might want to reduce the alphabet you are using...
              – Evargalo
              2 days ago




              You might want to reduce the alphabet you are using...
              – Evargalo
              2 days ago












              +1; this works if you reduce the alphabet.
              – Tim C
              yesterday




              +1; this works if you reduce the alphabet.
              – Tim C
              yesterday










              up vote
              2
              down vote













              I have tried to create a Markov chain modelling problem a). I haven't even tried to solve it, but the model (i.e. the states and the transitions) should be correct (with one caveat which I'll explain at the end).



              First, a simplification: I have reduced the problem to getting either the string A-A-B (as in CO-CO-NUT) or B-A-A (as in TUN-OC-OC), using an alphabet that only includes 3 letters: A, B, and C.



              Here's what I've got. This is for AAB:




              Markov chain for AAB




              As you can see, I have separated the state "Only one A" from the state "AA". It is noteworthy that there is no way to go from "AA" to "A".



              And this is for BAA:




              enter image description here




              I'm not sure what this leads to. I was hoping there would be some visible hint about the solution (like: both chains are very similar, with just one difference that tilts the balance in favour of one of them), but this doesn't seem to be the case.



              To be honest, I'm not even sure my simplification from COCONUT to AAB is correct, because in my case A and B are equally likely (both of them are just a letter which is typed with probability P = 1/3), whereas CO and NUT are not (CO is only 2 letters long, NUT is 3). This means that solving my chains could, or could not, help solving the original problem.



              Hopefully someone can pick up from here.






              share|improve this answer

























                up vote
                2
                down vote













                I have tried to create a Markov chain modelling problem a). I haven't even tried to solve it, but the model (i.e. the states and the transitions) should be correct (with one caveat which I'll explain at the end).



                First, a simplification: I have reduced the problem to getting either the string A-A-B (as in CO-CO-NUT) or B-A-A (as in TUN-OC-OC), using an alphabet that only includes 3 letters: A, B, and C.



                Here's what I've got. This is for AAB:




                Markov chain for AAB




                As you can see, I have separated the state "Only one A" from the state "AA". It is noteworthy that there is no way to go from "AA" to "A".



                And this is for BAA:




                enter image description here




                I'm not sure what this leads to. I was hoping there would be some visible hint about the solution (like: both chains are very similar, with just one difference that tilts the balance in favour of one of them), but this doesn't seem to be the case.



                To be honest, I'm not even sure my simplification from COCONUT to AAB is correct, because in my case A and B are equally likely (both of them are just a letter which is typed with probability P = 1/3), whereas CO and NUT are not (CO is only 2 letters long, NUT is 3). This means that solving my chains could, or could not, help solving the original problem.



                Hopefully someone can pick up from here.






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  I have tried to create a Markov chain modelling problem a). I haven't even tried to solve it, but the model (i.e. the states and the transitions) should be correct (with one caveat which I'll explain at the end).



                  First, a simplification: I have reduced the problem to getting either the string A-A-B (as in CO-CO-NUT) or B-A-A (as in TUN-OC-OC), using an alphabet that only includes 3 letters: A, B, and C.



                  Here's what I've got. This is for AAB:




                  Markov chain for AAB




                  As you can see, I have separated the state "Only one A" from the state "AA". It is noteworthy that there is no way to go from "AA" to "A".



                  And this is for BAA:




                  enter image description here




                  I'm not sure what this leads to. I was hoping there would be some visible hint about the solution (like: both chains are very similar, with just one difference that tilts the balance in favour of one of them), but this doesn't seem to be the case.



                  To be honest, I'm not even sure my simplification from COCONUT to AAB is correct, because in my case A and B are equally likely (both of them are just a letter which is typed with probability P = 1/3), whereas CO and NUT are not (CO is only 2 letters long, NUT is 3). This means that solving my chains could, or could not, help solving the original problem.



                  Hopefully someone can pick up from here.






                  share|improve this answer












                  I have tried to create a Markov chain modelling problem a). I haven't even tried to solve it, but the model (i.e. the states and the transitions) should be correct (with one caveat which I'll explain at the end).



                  First, a simplification: I have reduced the problem to getting either the string A-A-B (as in CO-CO-NUT) or B-A-A (as in TUN-OC-OC), using an alphabet that only includes 3 letters: A, B, and C.



                  Here's what I've got. This is for AAB:




                  Markov chain for AAB




                  As you can see, I have separated the state "Only one A" from the state "AA". It is noteworthy that there is no way to go from "AA" to "A".



                  And this is for BAA:




                  enter image description here




                  I'm not sure what this leads to. I was hoping there would be some visible hint about the solution (like: both chains are very similar, with just one difference that tilts the balance in favour of one of them), but this doesn't seem to be the case.



                  To be honest, I'm not even sure my simplification from COCONUT to AAB is correct, because in my case A and B are equally likely (both of them are just a letter which is typed with probability P = 1/3), whereas CO and NUT are not (CO is only 2 letters long, NUT is 3). This means that solving my chains could, or could not, help solving the original problem.



                  Hopefully someone can pick up from here.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  Fabio Turati

                  1656




                  1656






















                      up vote
                      2
                      down vote













                      I'll try to make the argument that the answer to both parts is:




                      The two are just as likely.




                      We start from the simple fact that the probability that a window of 7 letters reads COCONUT, or TUNOCOC, or anything else, is equal. (It's 26^(-7), as @Ingix said.). Crucially, it's completely independent of any letters that appear before or after the window, simply because these letters are not in the window...



                      Now, let's start with (b). We look at letters 1-7. If they say COCONUT, the first squirrel wins. If they say TUNOCOC (at the same probability!), the second one wins. If they say neither, we move on to letters 2-8 and do the same. At this point, letter 1 is completely irrelevant. You see how we move on and on through the letters, until there's a winner, and the chances of either squirrels to win never differ from each other.



                      Further clarification:




                      • Of course, if letters 2-7 happened to be COCONU, the first squirrel is in a very good position. Similarly (and in the same probability), if they were TUNOCO, the second squirrel is in a good position. But this is symmetrical, so no one has an overall advantage.

                      • Of course, if letters 1-7 were TUNOCOC, the chance to get COCONUT at letters 5-11 increases, but this doesn't matter since, in this instance, the game has already finished...

                      • In other words, if we were to ask "Which of the two words are we more likely to see at letters 5-11?" (see @abl's comment below), the answer would be TUNOCOC. But the difference is only due to a situation in which the game has already finished. And this is just not the question in hand.


                      Part (a) is a very similar. We look at letters 1-7 of both monkeys. If the first monkey typed COCONUT, it wins. If the second one types TUNOCOC, it wins. If neither won, we move on to look at letters 2-8 of both, and so on.



                      No Markov chains :)






                      share|improve this answer



















                      • 1




                        Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                        – abl
                        yesterday












                      • @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                        – Angkor
                        14 hours ago








                      • 4




                        @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                        – abl
                        11 hours ago






                      • 1




                        @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                        – abl
                        6 hours ago






                      • 1




                        @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                        – abl
                        6 hours ago















                      up vote
                      2
                      down vote













                      I'll try to make the argument that the answer to both parts is:




                      The two are just as likely.




                      We start from the simple fact that the probability that a window of 7 letters reads COCONUT, or TUNOCOC, or anything else, is equal. (It's 26^(-7), as @Ingix said.). Crucially, it's completely independent of any letters that appear before or after the window, simply because these letters are not in the window...



                      Now, let's start with (b). We look at letters 1-7. If they say COCONUT, the first squirrel wins. If they say TUNOCOC (at the same probability!), the second one wins. If they say neither, we move on to letters 2-8 and do the same. At this point, letter 1 is completely irrelevant. You see how we move on and on through the letters, until there's a winner, and the chances of either squirrels to win never differ from each other.



                      Further clarification:




                      • Of course, if letters 2-7 happened to be COCONU, the first squirrel is in a very good position. Similarly (and in the same probability), if they were TUNOCO, the second squirrel is in a good position. But this is symmetrical, so no one has an overall advantage.

                      • Of course, if letters 1-7 were TUNOCOC, the chance to get COCONUT at letters 5-11 increases, but this doesn't matter since, in this instance, the game has already finished...

                      • In other words, if we were to ask "Which of the two words are we more likely to see at letters 5-11?" (see @abl's comment below), the answer would be TUNOCOC. But the difference is only due to a situation in which the game has already finished. And this is just not the question in hand.


                      Part (a) is a very similar. We look at letters 1-7 of both monkeys. If the first monkey typed COCONUT, it wins. If the second one types TUNOCOC, it wins. If neither won, we move on to look at letters 2-8 of both, and so on.



                      No Markov chains :)






                      share|improve this answer



















                      • 1




                        Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                        – abl
                        yesterday












                      • @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                        – Angkor
                        14 hours ago








                      • 4




                        @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                        – abl
                        11 hours ago






                      • 1




                        @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                        – abl
                        6 hours ago






                      • 1




                        @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                        – abl
                        6 hours ago













                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote









                      I'll try to make the argument that the answer to both parts is:




                      The two are just as likely.




                      We start from the simple fact that the probability that a window of 7 letters reads COCONUT, or TUNOCOC, or anything else, is equal. (It's 26^(-7), as @Ingix said.). Crucially, it's completely independent of any letters that appear before or after the window, simply because these letters are not in the window...



                      Now, let's start with (b). We look at letters 1-7. If they say COCONUT, the first squirrel wins. If they say TUNOCOC (at the same probability!), the second one wins. If they say neither, we move on to letters 2-8 and do the same. At this point, letter 1 is completely irrelevant. You see how we move on and on through the letters, until there's a winner, and the chances of either squirrels to win never differ from each other.



                      Further clarification:




                      • Of course, if letters 2-7 happened to be COCONU, the first squirrel is in a very good position. Similarly (and in the same probability), if they were TUNOCO, the second squirrel is in a good position. But this is symmetrical, so no one has an overall advantage.

                      • Of course, if letters 1-7 were TUNOCOC, the chance to get COCONUT at letters 5-11 increases, but this doesn't matter since, in this instance, the game has already finished...

                      • In other words, if we were to ask "Which of the two words are we more likely to see at letters 5-11?" (see @abl's comment below), the answer would be TUNOCOC. But the difference is only due to a situation in which the game has already finished. And this is just not the question in hand.


                      Part (a) is a very similar. We look at letters 1-7 of both monkeys. If the first monkey typed COCONUT, it wins. If the second one types TUNOCOC, it wins. If neither won, we move on to look at letters 2-8 of both, and so on.



                      No Markov chains :)






                      share|improve this answer














                      I'll try to make the argument that the answer to both parts is:




                      The two are just as likely.




                      We start from the simple fact that the probability that a window of 7 letters reads COCONUT, or TUNOCOC, or anything else, is equal. (It's 26^(-7), as @Ingix said.). Crucially, it's completely independent of any letters that appear before or after the window, simply because these letters are not in the window...



                      Now, let's start with (b). We look at letters 1-7. If they say COCONUT, the first squirrel wins. If they say TUNOCOC (at the same probability!), the second one wins. If they say neither, we move on to letters 2-8 and do the same. At this point, letter 1 is completely irrelevant. You see how we move on and on through the letters, until there's a winner, and the chances of either squirrels to win never differ from each other.



                      Further clarification:




                      • Of course, if letters 2-7 happened to be COCONU, the first squirrel is in a very good position. Similarly (and in the same probability), if they were TUNOCO, the second squirrel is in a good position. But this is symmetrical, so no one has an overall advantage.

                      • Of course, if letters 1-7 were TUNOCOC, the chance to get COCONUT at letters 5-11 increases, but this doesn't matter since, in this instance, the game has already finished...

                      • In other words, if we were to ask "Which of the two words are we more likely to see at letters 5-11?" (see @abl's comment below), the answer would be TUNOCOC. But the difference is only due to a situation in which the game has already finished. And this is just not the question in hand.


                      Part (a) is a very similar. We look at letters 1-7 of both monkeys. If the first monkey typed COCONUT, it wins. If the second one types TUNOCOC, it wins. If neither won, we move on to look at letters 2-8 of both, and so on.



                      No Markov chains :)







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 7 hours ago

























                      answered yesterday









                      Angkor

                      1,129316




                      1,129316








                      • 1




                        Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                        – abl
                        yesterday












                      • @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                        – Angkor
                        14 hours ago








                      • 4




                        @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                        – abl
                        11 hours ago






                      • 1




                        @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                        – abl
                        6 hours ago






                      • 1




                        @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                        – abl
                        6 hours ago














                      • 1




                        Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                        – abl
                        yesterday












                      • @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                        – Angkor
                        14 hours ago








                      • 4




                        @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                        – abl
                        11 hours ago






                      • 1




                        @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                        – abl
                        6 hours ago






                      • 1




                        @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                        – abl
                        6 hours ago








                      1




                      1




                      Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                      – abl
                      yesterday






                      Except that in (b) the probabilities are not independent across windows. The probability of letters 5-11 being COCONUT, conditional to the fact that you reached this window, are lower than the equivalent for TUNOCOC, simply because you have to account for the case "TUNOCOCONUT" (in which case you wouldn't reach window 5-11). Maybe you can believe the discussion now :)
                      – abl
                      yesterday














                      @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                      – Angkor
                      14 hours ago






                      @abl Sorry, but this is just not true... Are you saying that, typing randomly, one is more likely to type COCONUT than TUNOCOC? These are just two 7-letter sequences, and they're just as likely. Arguments like "consider the case X" are not really valid, because there are so many other cases to consider too. The trick is to be able to consider all cases together with a general argument.
                      – Angkor
                      14 hours ago






                      4




                      4




                      @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                      – abl
                      11 hours ago




                      @Angkor Maybe I didn't explain myself well. Consider all possible sequences that start with "****TUNOCOC...". It's obvious that there are just as many of those as sequences of the form "****COCONUT...", i.e. both situations are equally probable, right? Note that all sequences of the form "****TUNOCOC..." are a win for squirrel 2. And all sequences of the form "****COCONUT..." are a win for squirrel 1, except for those that start with "TUNOCOCONUT..." which are a win for squirrel 2. There's an asymmetry here, so at the very least we can say that those are not "just two 7-letter sequences".
                      – abl
                      11 hours ago




                      1




                      1




                      @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                      – abl
                      6 hours ago




                      @Angkor Point taken, I apologize if I was out of tone. Imagine that the alphabet has only two letters, A and B. The squirrels bet for AAB and BAA respectively. The first three letters are typed. Each squirrel has 1/8 chances of winning at the third letter. If none of them wins, then the sequence is one of AAA, ABA, ABB, BAB, BBA, BBB, with equal probability. At the fourth letter, the possibilities (with equal probability) are AAAA, AAAB, ABAA, ABAB, ABBA, ABBB, BABA, BABB, BBAA, BBAB, BBBA, BBBB. Squirrel 1 wins with AAAB. Squirrel 2 wins with ABAA or BBAA, twice the chance.
                      – abl
                      6 hours ago




                      1




                      1




                      @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                      – abl
                      6 hours ago




                      @Angkor, also, this simplified case is simple enough to be simulated, which I did (see my answer) and the simulation over several million games shows the second squirrel has better chances.
                      – abl
                      6 hours ago










                      up vote
                      1
                      down vote













                      There's good arguments for both sides. Here's code that prove it definitely:



                      import numpy as np

                      def main():
                      m1 = np.array([
                      [25, 1, 0, 0, 0, 0, 0, 0],
                      [24, 1, 1, 0, 0, 0, 0, 0],
                      [25, 0, 0, 1, 0, 0, 0, 0],
                      [24, 1, 0, 0, 1, 0, 0, 0],
                      [24, 0, 0, 1, 0, 1, 0, 0],
                      [24, 1, 0, 0, 0, 0, 1, 0],
                      [24, 1, 0, 0, 0, 0, 0, 1],
                      [0, 0, 0, 0, 0, 0, 0, 26]], dtype='object')

                      m2 = np.array([
                      [25, 1, 0, 0, 0, 0, 0, 0],
                      [24, 1, 1, 0, 0, 0, 0, 0],
                      [24, 1, 0, 1, 0, 0, 0, 0],
                      [24, 1, 0, 0, 1, 0, 0, 0],
                      [24, 1, 0, 0, 0, 1, 0, 0],
                      [24, 1, 0, 0, 0, 0, 1, 0],
                      [24, 1, 0, 0, 0, 0, 0, 1],
                      [0, 0, 0, 0, 0, 0, 0, 26]], dtype = 'object')

                      p1 = np.array([1,0,0,0,0,0,0,0])
                      p2 = np.array([1,0,0,0,0,0,0,0])

                      for i in range(1000):
                      p1 = p1.dot(m1)
                      p2 = p2.dot(m2)

                      #this shows that how often the two monkes have 1,2,3 letters correct vary
                      #but it doesn't affact past the 4th letter
                      #print(i,p2 - p1)

                      if p1[7] == p2[7]:
                      print("after {} steps, both monkeys have equal chances".format(i))
                      elif p2[7] > p1[7]:
                      print("crap, this whole arguments just got destroyed")
                      else:
                      print("after {} steps, coconut monkey has {} more ways to have won".format(i, p1[7] - p2[7]))

                      main()


                      I ran it up to:




                      after 99999 steps, both monkeys have equal chances




                      No matter the number of steps, both monkeys have equal chances. Even though one monkey is more likely to have exactly the last 1,2, or 3 letters correct.



                      (mind-boggling)






                      share|improve this answer

























                        up vote
                        1
                        down vote













                        There's good arguments for both sides. Here's code that prove it definitely:



                        import numpy as np

                        def main():
                        m1 = np.array([
                        [25, 1, 0, 0, 0, 0, 0, 0],
                        [24, 1, 1, 0, 0, 0, 0, 0],
                        [25, 0, 0, 1, 0, 0, 0, 0],
                        [24, 1, 0, 0, 1, 0, 0, 0],
                        [24, 0, 0, 1, 0, 1, 0, 0],
                        [24, 1, 0, 0, 0, 0, 1, 0],
                        [24, 1, 0, 0, 0, 0, 0, 1],
                        [0, 0, 0, 0, 0, 0, 0, 26]], dtype='object')

                        m2 = np.array([
                        [25, 1, 0, 0, 0, 0, 0, 0],
                        [24, 1, 1, 0, 0, 0, 0, 0],
                        [24, 1, 0, 1, 0, 0, 0, 0],
                        [24, 1, 0, 0, 1, 0, 0, 0],
                        [24, 1, 0, 0, 0, 1, 0, 0],
                        [24, 1, 0, 0, 0, 0, 1, 0],
                        [24, 1, 0, 0, 0, 0, 0, 1],
                        [0, 0, 0, 0, 0, 0, 0, 26]], dtype = 'object')

                        p1 = np.array([1,0,0,0,0,0,0,0])
                        p2 = np.array([1,0,0,0,0,0,0,0])

                        for i in range(1000):
                        p1 = p1.dot(m1)
                        p2 = p2.dot(m2)

                        #this shows that how often the two monkes have 1,2,3 letters correct vary
                        #but it doesn't affact past the 4th letter
                        #print(i,p2 - p1)

                        if p1[7] == p2[7]:
                        print("after {} steps, both monkeys have equal chances".format(i))
                        elif p2[7] > p1[7]:
                        print("crap, this whole arguments just got destroyed")
                        else:
                        print("after {} steps, coconut monkey has {} more ways to have won".format(i, p1[7] - p2[7]))

                        main()


                        I ran it up to:




                        after 99999 steps, both monkeys have equal chances




                        No matter the number of steps, both monkeys have equal chances. Even though one monkey is more likely to have exactly the last 1,2, or 3 letters correct.



                        (mind-boggling)






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          There's good arguments for both sides. Here's code that prove it definitely:



                          import numpy as np

                          def main():
                          m1 = np.array([
                          [25, 1, 0, 0, 0, 0, 0, 0],
                          [24, 1, 1, 0, 0, 0, 0, 0],
                          [25, 0, 0, 1, 0, 0, 0, 0],
                          [24, 1, 0, 0, 1, 0, 0, 0],
                          [24, 0, 0, 1, 0, 1, 0, 0],
                          [24, 1, 0, 0, 0, 0, 1, 0],
                          [24, 1, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 26]], dtype='object')

                          m2 = np.array([
                          [25, 1, 0, 0, 0, 0, 0, 0],
                          [24, 1, 1, 0, 0, 0, 0, 0],
                          [24, 1, 0, 1, 0, 0, 0, 0],
                          [24, 1, 0, 0, 1, 0, 0, 0],
                          [24, 1, 0, 0, 0, 1, 0, 0],
                          [24, 1, 0, 0, 0, 0, 1, 0],
                          [24, 1, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 26]], dtype = 'object')

                          p1 = np.array([1,0,0,0,0,0,0,0])
                          p2 = np.array([1,0,0,0,0,0,0,0])

                          for i in range(1000):
                          p1 = p1.dot(m1)
                          p2 = p2.dot(m2)

                          #this shows that how often the two monkes have 1,2,3 letters correct vary
                          #but it doesn't affact past the 4th letter
                          #print(i,p2 - p1)

                          if p1[7] == p2[7]:
                          print("after {} steps, both monkeys have equal chances".format(i))
                          elif p2[7] > p1[7]:
                          print("crap, this whole arguments just got destroyed")
                          else:
                          print("after {} steps, coconut monkey has {} more ways to have won".format(i, p1[7] - p2[7]))

                          main()


                          I ran it up to:




                          after 99999 steps, both monkeys have equal chances




                          No matter the number of steps, both monkeys have equal chances. Even though one monkey is more likely to have exactly the last 1,2, or 3 letters correct.



                          (mind-boggling)






                          share|improve this answer












                          There's good arguments for both sides. Here's code that prove it definitely:



                          import numpy as np

                          def main():
                          m1 = np.array([
                          [25, 1, 0, 0, 0, 0, 0, 0],
                          [24, 1, 1, 0, 0, 0, 0, 0],
                          [25, 0, 0, 1, 0, 0, 0, 0],
                          [24, 1, 0, 0, 1, 0, 0, 0],
                          [24, 0, 0, 1, 0, 1, 0, 0],
                          [24, 1, 0, 0, 0, 0, 1, 0],
                          [24, 1, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 26]], dtype='object')

                          m2 = np.array([
                          [25, 1, 0, 0, 0, 0, 0, 0],
                          [24, 1, 1, 0, 0, 0, 0, 0],
                          [24, 1, 0, 1, 0, 0, 0, 0],
                          [24, 1, 0, 0, 1, 0, 0, 0],
                          [24, 1, 0, 0, 0, 1, 0, 0],
                          [24, 1, 0, 0, 0, 0, 1, 0],
                          [24, 1, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 26]], dtype = 'object')

                          p1 = np.array([1,0,0,0,0,0,0,0])
                          p2 = np.array([1,0,0,0,0,0,0,0])

                          for i in range(1000):
                          p1 = p1.dot(m1)
                          p2 = p2.dot(m2)

                          #this shows that how often the two monkes have 1,2,3 letters correct vary
                          #but it doesn't affact past the 4th letter
                          #print(i,p2 - p1)

                          if p1[7] == p2[7]:
                          print("after {} steps, both monkeys have equal chances".format(i))
                          elif p2[7] > p1[7]:
                          print("crap, this whole arguments just got destroyed")
                          else:
                          print("after {} steps, coconut monkey has {} more ways to have won".format(i, p1[7] - p2[7]))

                          main()


                          I ran it up to:




                          after 99999 steps, both monkeys have equal chances




                          No matter the number of steps, both monkeys have equal chances. Even though one monkey is more likely to have exactly the last 1,2, or 3 letters correct.



                          (mind-boggling)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          Jeffrey

                          1215




                          1215






















                              up vote
                              0
                              down vote













                              Monkey problem



                              The crux the problem is the following: do repeated groups influence the expected characters needed to complete a sequence? The answer is




                              No, repeated groups bear no influence on the result




                              Let's reduce the problem to something similar - AAB vs ABC with only these letters being on the keyboard.



                              The probability of obtaining AAB in a sequence is:




                              starting at 1: P(A) * P(A) * P(B) = (1/3 * 1/3 * 1/3) +

                              starting at 2: P(!A) * P(A) * P(A) * P(B) = 2/3 * (1/3 * 1/3 * 1/3) +

                              starting at 3: P(!A) * P(!A) * P(A) * P(A) * P(B) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                              The probability of obtaining ABC in a sequence is:




                              starting at 1: P(A) * P(B) * P(C) = (1/3 * 1/3 * 1/3) +

                              starting at 2: P(!A) * P(A) * P(B) * P(C) = 2/3 * (1/3 * 1/3 * 1/3) +

                              starting at 3: P(!A) * P(!A) * P(A) * P(B) * P(C) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                              This makes it easy to see that




                              No matter how you shuffle the desired sequence around, the only thing that influences the probability of it occurring is the length of the sequence.




                              Alternative proof:
                              All of the possible sequences of 4 letters are:




                              AAAA ABAA ACAA BAAA BBAA BCAA CAAA CBAA CCAA

                              AAAB ABAB ACAB BAAB BBAB BCAB CAAB CBAB CCAB

                              AAAC ABAC ACAC BAAC BBAC BCAC CAAC CBAC CCAC

                              AABA ABBA ACBA BABA BBBA BCBA CABA CBBA CCBA

                              AABB ABBB ACBB BABB BBBB BCBB CABB CBBB CCBB

                              AABC ABBC ACBC BABC BBBC BCBC CABC CBBC CCBC

                              AACA ABCA ACCA BACA BBCA BCCA CACA CBCA CCCA

                              AACB ABCB ACCB BACB BBCB BCCB CACB CBCB CCCB

                              AACC ABCC ACCC BACC BBCC BCCC CACC CBCC CCCC




                              And here is the same table with the uninteresting sequences cut out:




                              XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              AAAB XXXX XXXX BAAB XXXX XXXX CAAB XXXX XXXX

                              XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              AABA XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              AABB XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              AABC XXXX XXXX BABC XXXX XXXX CABC XXXX XXXX

                              XXXX ABCA XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              XXXX ABCB XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                              XXXX ABCC XXXX XXXX XXXX XXXX XXXX XXXX XXXX




                              There are




                              3 sequences where AAB starts at position 1: AABA, AABB, AABC

                              3 sequences where AAB starts at position 2: AAAB, BAAB, CAAB

                              3 sequences where ABC starts at position 1: ABCA, ABCB, ABCC

                              3 sequences where ABC starts at position 2: AABC, BABC, CABC




                              Thus the answer to the monkey problem is that




                              both monkeys have the same chance of finishing first




                              Squirrel problem



                              Let's consider the string typed by the monkey after a long (infinite) time and make some simplifications that don't affect the outcome to understand the problem better.




                              Replace any letter not in COCONUT with X

                              Replace all groups of COC with A

                              Replace all remaining C's with X

                              Replace all remaining O's with B, N's with C, U's with D and T's with E




                              The problem now is:




                              in the new string will we more likely first find ABCDE or EDCBA?




                              And the solution:




                              If A, B, C, D and E had the same chances of occurring, the answer would be "both are equally likely", but C, D and E have normal chances of occurring, A has a very low chance of occurring, B has a slightly lower than normal chance.

                              Considering a simplified case - 2 letters - P and Q with P occurring more often than Q, PQ has more chances of appearing first than QP.
                              This means EDCBA is more likely to appear first than ABCDE.




                              Looking at it from a different angle:




                              When the unlikely event that A appears in the string, it is equally likely that it is followed by a B as it is that it is preceded by one.

                              In the even more unlikely event that an AB or BA appears in the string, it is equally likely that it is followed by a C as it is that it is preceded by one.

                              ...

                              Which makes it equally likely that ABCDE and EDCBA appear in the string, so when an A appears in either of these sequences, it is equally likely that it starts the ABCDE sequence as it is that it ends the EDCBA sequence.




                              Thus, the answer to the squirrel problem is that




                              the second squirrel's sequence (TUNOCOC) appears first







                              share|improve this answer

























                                up vote
                                0
                                down vote













                                Monkey problem



                                The crux the problem is the following: do repeated groups influence the expected characters needed to complete a sequence? The answer is




                                No, repeated groups bear no influence on the result




                                Let's reduce the problem to something similar - AAB vs ABC with only these letters being on the keyboard.



                                The probability of obtaining AAB in a sequence is:




                                starting at 1: P(A) * P(A) * P(B) = (1/3 * 1/3 * 1/3) +

                                starting at 2: P(!A) * P(A) * P(A) * P(B) = 2/3 * (1/3 * 1/3 * 1/3) +

                                starting at 3: P(!A) * P(!A) * P(A) * P(A) * P(B) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                The probability of obtaining ABC in a sequence is:




                                starting at 1: P(A) * P(B) * P(C) = (1/3 * 1/3 * 1/3) +

                                starting at 2: P(!A) * P(A) * P(B) * P(C) = 2/3 * (1/3 * 1/3 * 1/3) +

                                starting at 3: P(!A) * P(!A) * P(A) * P(B) * P(C) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                This makes it easy to see that




                                No matter how you shuffle the desired sequence around, the only thing that influences the probability of it occurring is the length of the sequence.




                                Alternative proof:
                                All of the possible sequences of 4 letters are:




                                AAAA ABAA ACAA BAAA BBAA BCAA CAAA CBAA CCAA

                                AAAB ABAB ACAB BAAB BBAB BCAB CAAB CBAB CCAB

                                AAAC ABAC ACAC BAAC BBAC BCAC CAAC CBAC CCAC

                                AABA ABBA ACBA BABA BBBA BCBA CABA CBBA CCBA

                                AABB ABBB ACBB BABB BBBB BCBB CABB CBBB CCBB

                                AABC ABBC ACBC BABC BBBC BCBC CABC CBBC CCBC

                                AACA ABCA ACCA BACA BBCA BCCA CACA CBCA CCCA

                                AACB ABCB ACCB BACB BBCB BCCB CACB CBCB CCCB

                                AACC ABCC ACCC BACC BBCC BCCC CACC CBCC CCCC




                                And here is the same table with the uninteresting sequences cut out:




                                XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                AAAB XXXX XXXX BAAB XXXX XXXX CAAB XXXX XXXX

                                XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                AABA XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                AABB XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                AABC XXXX XXXX BABC XXXX XXXX CABC XXXX XXXX

                                XXXX ABCA XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                XXXX ABCB XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                XXXX ABCC XXXX XXXX XXXX XXXX XXXX XXXX XXXX




                                There are




                                3 sequences where AAB starts at position 1: AABA, AABB, AABC

                                3 sequences where AAB starts at position 2: AAAB, BAAB, CAAB

                                3 sequences where ABC starts at position 1: ABCA, ABCB, ABCC

                                3 sequences where ABC starts at position 2: AABC, BABC, CABC




                                Thus the answer to the monkey problem is that




                                both monkeys have the same chance of finishing first




                                Squirrel problem



                                Let's consider the string typed by the monkey after a long (infinite) time and make some simplifications that don't affect the outcome to understand the problem better.




                                Replace any letter not in COCONUT with X

                                Replace all groups of COC with A

                                Replace all remaining C's with X

                                Replace all remaining O's with B, N's with C, U's with D and T's with E




                                The problem now is:




                                in the new string will we more likely first find ABCDE or EDCBA?




                                And the solution:




                                If A, B, C, D and E had the same chances of occurring, the answer would be "both are equally likely", but C, D and E have normal chances of occurring, A has a very low chance of occurring, B has a slightly lower than normal chance.

                                Considering a simplified case - 2 letters - P and Q with P occurring more often than Q, PQ has more chances of appearing first than QP.
                                This means EDCBA is more likely to appear first than ABCDE.




                                Looking at it from a different angle:




                                When the unlikely event that A appears in the string, it is equally likely that it is followed by a B as it is that it is preceded by one.

                                In the even more unlikely event that an AB or BA appears in the string, it is equally likely that it is followed by a C as it is that it is preceded by one.

                                ...

                                Which makes it equally likely that ABCDE and EDCBA appear in the string, so when an A appears in either of these sequences, it is equally likely that it starts the ABCDE sequence as it is that it ends the EDCBA sequence.




                                Thus, the answer to the squirrel problem is that




                                the second squirrel's sequence (TUNOCOC) appears first







                                share|improve this answer























                                  up vote
                                  0
                                  down vote










                                  up vote
                                  0
                                  down vote









                                  Monkey problem



                                  The crux the problem is the following: do repeated groups influence the expected characters needed to complete a sequence? The answer is




                                  No, repeated groups bear no influence on the result




                                  Let's reduce the problem to something similar - AAB vs ABC with only these letters being on the keyboard.



                                  The probability of obtaining AAB in a sequence is:




                                  starting at 1: P(A) * P(A) * P(B) = (1/3 * 1/3 * 1/3) +

                                  starting at 2: P(!A) * P(A) * P(A) * P(B) = 2/3 * (1/3 * 1/3 * 1/3) +

                                  starting at 3: P(!A) * P(!A) * P(A) * P(A) * P(B) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                  The probability of obtaining ABC in a sequence is:




                                  starting at 1: P(A) * P(B) * P(C) = (1/3 * 1/3 * 1/3) +

                                  starting at 2: P(!A) * P(A) * P(B) * P(C) = 2/3 * (1/3 * 1/3 * 1/3) +

                                  starting at 3: P(!A) * P(!A) * P(A) * P(B) * P(C) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                  This makes it easy to see that




                                  No matter how you shuffle the desired sequence around, the only thing that influences the probability of it occurring is the length of the sequence.




                                  Alternative proof:
                                  All of the possible sequences of 4 letters are:




                                  AAAA ABAA ACAA BAAA BBAA BCAA CAAA CBAA CCAA

                                  AAAB ABAB ACAB BAAB BBAB BCAB CAAB CBAB CCAB

                                  AAAC ABAC ACAC BAAC BBAC BCAC CAAC CBAC CCAC

                                  AABA ABBA ACBA BABA BBBA BCBA CABA CBBA CCBA

                                  AABB ABBB ACBB BABB BBBB BCBB CABB CBBB CCBB

                                  AABC ABBC ACBC BABC BBBC BCBC CABC CBBC CCBC

                                  AACA ABCA ACCA BACA BBCA BCCA CACA CBCA CCCA

                                  AACB ABCB ACCB BACB BBCB BCCB CACB CBCB CCCB

                                  AACC ABCC ACCC BACC BBCC BCCC CACC CBCC CCCC




                                  And here is the same table with the uninteresting sequences cut out:




                                  XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AAAB XXXX XXXX BAAB XXXX XXXX CAAB XXXX XXXX

                                  XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABA XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABB XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABC XXXX XXXX BABC XXXX XXXX CABC XXXX XXXX

                                  XXXX ABCA XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  XXXX ABCB XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  XXXX ABCC XXXX XXXX XXXX XXXX XXXX XXXX XXXX




                                  There are




                                  3 sequences where AAB starts at position 1: AABA, AABB, AABC

                                  3 sequences where AAB starts at position 2: AAAB, BAAB, CAAB

                                  3 sequences where ABC starts at position 1: ABCA, ABCB, ABCC

                                  3 sequences where ABC starts at position 2: AABC, BABC, CABC




                                  Thus the answer to the monkey problem is that




                                  both monkeys have the same chance of finishing first




                                  Squirrel problem



                                  Let's consider the string typed by the monkey after a long (infinite) time and make some simplifications that don't affect the outcome to understand the problem better.




                                  Replace any letter not in COCONUT with X

                                  Replace all groups of COC with A

                                  Replace all remaining C's with X

                                  Replace all remaining O's with B, N's with C, U's with D and T's with E




                                  The problem now is:




                                  in the new string will we more likely first find ABCDE or EDCBA?




                                  And the solution:




                                  If A, B, C, D and E had the same chances of occurring, the answer would be "both are equally likely", but C, D and E have normal chances of occurring, A has a very low chance of occurring, B has a slightly lower than normal chance.

                                  Considering a simplified case - 2 letters - P and Q with P occurring more often than Q, PQ has more chances of appearing first than QP.
                                  This means EDCBA is more likely to appear first than ABCDE.




                                  Looking at it from a different angle:




                                  When the unlikely event that A appears in the string, it is equally likely that it is followed by a B as it is that it is preceded by one.

                                  In the even more unlikely event that an AB or BA appears in the string, it is equally likely that it is followed by a C as it is that it is preceded by one.

                                  ...

                                  Which makes it equally likely that ABCDE and EDCBA appear in the string, so when an A appears in either of these sequences, it is equally likely that it starts the ABCDE sequence as it is that it ends the EDCBA sequence.




                                  Thus, the answer to the squirrel problem is that




                                  the second squirrel's sequence (TUNOCOC) appears first







                                  share|improve this answer












                                  Monkey problem



                                  The crux the problem is the following: do repeated groups influence the expected characters needed to complete a sequence? The answer is




                                  No, repeated groups bear no influence on the result




                                  Let's reduce the problem to something similar - AAB vs ABC with only these letters being on the keyboard.



                                  The probability of obtaining AAB in a sequence is:




                                  starting at 1: P(A) * P(A) * P(B) = (1/3 * 1/3 * 1/3) +

                                  starting at 2: P(!A) * P(A) * P(A) * P(B) = 2/3 * (1/3 * 1/3 * 1/3) +

                                  starting at 3: P(!A) * P(!A) * P(A) * P(A) * P(B) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                  The probability of obtaining ABC in a sequence is:




                                  starting at 1: P(A) * P(B) * P(C) = (1/3 * 1/3 * 1/3) +

                                  starting at 2: P(!A) * P(A) * P(B) * P(C) = 2/3 * (1/3 * 1/3 * 1/3) +

                                  starting at 3: P(!A) * P(!A) * P(A) * P(B) * P(C) = 2/3 * 2/3 * (1/3 * 1/3 * 1/3) + ...




                                  This makes it easy to see that




                                  No matter how you shuffle the desired sequence around, the only thing that influences the probability of it occurring is the length of the sequence.




                                  Alternative proof:
                                  All of the possible sequences of 4 letters are:




                                  AAAA ABAA ACAA BAAA BBAA BCAA CAAA CBAA CCAA

                                  AAAB ABAB ACAB BAAB BBAB BCAB CAAB CBAB CCAB

                                  AAAC ABAC ACAC BAAC BBAC BCAC CAAC CBAC CCAC

                                  AABA ABBA ACBA BABA BBBA BCBA CABA CBBA CCBA

                                  AABB ABBB ACBB BABB BBBB BCBB CABB CBBB CCBB

                                  AABC ABBC ACBC BABC BBBC BCBC CABC CBBC CCBC

                                  AACA ABCA ACCA BACA BBCA BCCA CACA CBCA CCCA

                                  AACB ABCB ACCB BACB BBCB BCCB CACB CBCB CCCB

                                  AACC ABCC ACCC BACC BBCC BCCC CACC CBCC CCCC




                                  And here is the same table with the uninteresting sequences cut out:




                                  XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AAAB XXXX XXXX BAAB XXXX XXXX CAAB XXXX XXXX

                                  XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABA XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABB XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  AABC XXXX XXXX BABC XXXX XXXX CABC XXXX XXXX

                                  XXXX ABCA XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  XXXX ABCB XXXX XXXX XXXX XXXX XXXX XXXX XXXX

                                  XXXX ABCC XXXX XXXX XXXX XXXX XXXX XXXX XXXX




                                  There are




                                  3 sequences where AAB starts at position 1: AABA, AABB, AABC

                                  3 sequences where AAB starts at position 2: AAAB, BAAB, CAAB

                                  3 sequences where ABC starts at position 1: ABCA, ABCB, ABCC

                                  3 sequences where ABC starts at position 2: AABC, BABC, CABC




                                  Thus the answer to the monkey problem is that




                                  both monkeys have the same chance of finishing first




                                  Squirrel problem



                                  Let's consider the string typed by the monkey after a long (infinite) time and make some simplifications that don't affect the outcome to understand the problem better.




                                  Replace any letter not in COCONUT with X

                                  Replace all groups of COC with A

                                  Replace all remaining C's with X

                                  Replace all remaining O's with B, N's with C, U's with D and T's with E




                                  The problem now is:




                                  in the new string will we more likely first find ABCDE or EDCBA?




                                  And the solution:




                                  If A, B, C, D and E had the same chances of occurring, the answer would be "both are equally likely", but C, D and E have normal chances of occurring, A has a very low chance of occurring, B has a slightly lower than normal chance.

                                  Considering a simplified case - 2 letters - P and Q with P occurring more often than Q, PQ has more chances of appearing first than QP.
                                  This means EDCBA is more likely to appear first than ABCDE.




                                  Looking at it from a different angle:




                                  When the unlikely event that A appears in the string, it is equally likely that it is followed by a B as it is that it is preceded by one.

                                  In the even more unlikely event that an AB or BA appears in the string, it is equally likely that it is followed by a C as it is that it is preceded by one.

                                  ...

                                  Which makes it equally likely that ABCDE and EDCBA appear in the string, so when an A appears in either of these sequences, it is equally likely that it starts the ABCDE sequence as it is that it ends the EDCBA sequence.




                                  Thus, the answer to the squirrel problem is that




                                  the second squirrel's sequence (TUNOCOC) appears first








                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered yesterday









                                  Tibos

                                  58628




                                  58628






















                                      up vote
                                      0
                                      down vote













                                      I have created the simulation in C# based on Marco's idea.
                                      The alphabet is reduced and the performance is improved:



                                      public class Monkey
                                      {
                                      private static readonly char alphabet = "ACNOTUXY".ToCharArray();
                                      private static readonly Random random = new Random();

                                      public Monkey(string Target)
                                      {
                                      target = Target.ToCharArray();
                                      length = target.Length;
                                      input = new char[length];
                                      inputPosition = 0;
                                      }

                                      private readonly char target;
                                      private readonly int length;
                                      private readonly char input;
                                      private int inputPosition;

                                      public bool TargetReached { get; private set; }

                                      public void PressKey()
                                      {
                                      var key = alphabet[random.Next(0, 8)];
                                      input[inputPosition] = key;
                                      inputPosition = ++inputPosition % length;
                                      TargetReached = IsTargetReached();
                                      }

                                      private bool IsTargetReached()
                                      {
                                      for (var i = 0; i < length; i++)
                                      {
                                      if (input[i] != target[i]) return false;
                                      }
                                      return true;
                                      }
                                      }

                                      public class Simulator
                                      {
                                      private int ties;
                                      private int monkey1Wins;
                                      private int monkey2Wins;

                                      public void Run(int numberOfCompetitons)
                                      {
                                      for (var i = 0; i < numberOfCompetitons; i++)
                                      {
                                      RunCompetition();
                                      }
                                      }

                                      private void RunCompetition()
                                      {
                                      var monkey1 = new Monkey("COCONUT");
                                      var monkey2 = new Monkey("TUNOCOC");

                                      while (true)
                                      {
                                      monkey1.PressKey();
                                      monkey2.PressKey();

                                      if (monkey1.TargetReached && monkey2.TargetReached)
                                      {
                                      ties++;
                                      Console.WriteLine("It's a TIE!");
                                      break;
                                      }
                                      if (monkey1.TargetReached)
                                      {
                                      monkey1Wins++;
                                      Console.WriteLine("Monkey 1 WON!");
                                      break;
                                      }
                                      if (monkey2.TargetReached)
                                      {
                                      monkey2Wins++;
                                      Console.WriteLine("Monkey 2 WON!");
                                      break;
                                      }
                                      }
                                      }

                                      public void ShowSummary()
                                      {
                                      Console.WriteLine();
                                      Console.WriteLine($"{ties} TIES");
                                      Console.WriteLine($
                                      "Monkey 1: {monkey1Wins} WINS");
                                      Console.WriteLine($"Monkey 2: {monkey2Wins} WINS");
                                      }
                                      }

                                      internal class Program
                                      {
                                      private static void Main()
                                      {
                                      var simulator = new Simulator();
                                      simulator.Run(1000);
                                      simulator.ShowSummary();
                                      Console.ReadKey();
                                      }
                                      }


                                      Sample output:



                                      ...
                                      Monkey 1 WON!
                                      Monkey 1 WON!
                                      Monkey 2 WON!
                                      Monkey 1 WON!
                                      Monkey 2 WON!
                                      Monkey 2 WON!
                                      Monkey 1 WON!
                                      Monkey 1 WON!
                                      Monkey 2 WON!



                                      0 TIES

                                      Monkey 1: 498 WINS

                                      Monkey 2: 502 WINS


                                      So it seems pretty tied to me







                                      share|improve this answer










                                      New contributor




                                      Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






















                                        up vote
                                        0
                                        down vote













                                        I have created the simulation in C# based on Marco's idea.
                                        The alphabet is reduced and the performance is improved:



                                        public class Monkey
                                        {
                                        private static readonly char alphabet = "ACNOTUXY".ToCharArray();
                                        private static readonly Random random = new Random();

                                        public Monkey(string Target)
                                        {
                                        target = Target.ToCharArray();
                                        length = target.Length;
                                        input = new char[length];
                                        inputPosition = 0;
                                        }

                                        private readonly char target;
                                        private readonly int length;
                                        private readonly char input;
                                        private int inputPosition;

                                        public bool TargetReached { get; private set; }

                                        public void PressKey()
                                        {
                                        var key = alphabet[random.Next(0, 8)];
                                        input[inputPosition] = key;
                                        inputPosition = ++inputPosition % length;
                                        TargetReached = IsTargetReached();
                                        }

                                        private bool IsTargetReached()
                                        {
                                        for (var i = 0; i < length; i++)
                                        {
                                        if (input[i] != target[i]) return false;
                                        }
                                        return true;
                                        }
                                        }

                                        public class Simulator
                                        {
                                        private int ties;
                                        private int monkey1Wins;
                                        private int monkey2Wins;

                                        public void Run(int numberOfCompetitons)
                                        {
                                        for (var i = 0; i < numberOfCompetitons; i++)
                                        {
                                        RunCompetition();
                                        }
                                        }

                                        private void RunCompetition()
                                        {
                                        var monkey1 = new Monkey("COCONUT");
                                        var monkey2 = new Monkey("TUNOCOC");

                                        while (true)
                                        {
                                        monkey1.PressKey();
                                        monkey2.PressKey();

                                        if (monkey1.TargetReached && monkey2.TargetReached)
                                        {
                                        ties++;
                                        Console.WriteLine("It's a TIE!");
                                        break;
                                        }
                                        if (monkey1.TargetReached)
                                        {
                                        monkey1Wins++;
                                        Console.WriteLine("Monkey 1 WON!");
                                        break;
                                        }
                                        if (monkey2.TargetReached)
                                        {
                                        monkey2Wins++;
                                        Console.WriteLine("Monkey 2 WON!");
                                        break;
                                        }
                                        }
                                        }

                                        public void ShowSummary()
                                        {
                                        Console.WriteLine();
                                        Console.WriteLine($"{ties} TIES");
                                        Console.WriteLine($
                                        "Monkey 1: {monkey1Wins} WINS");
                                        Console.WriteLine($"Monkey 2: {monkey2Wins} WINS");
                                        }
                                        }

                                        internal class Program
                                        {
                                        private static void Main()
                                        {
                                        var simulator = new Simulator();
                                        simulator.Run(1000);
                                        simulator.ShowSummary();
                                        Console.ReadKey();
                                        }
                                        }


                                        Sample output:



                                        ...
                                        Monkey 1 WON!
                                        Monkey 1 WON!
                                        Monkey 2 WON!
                                        Monkey 1 WON!
                                        Monkey 2 WON!
                                        Monkey 2 WON!
                                        Monkey 1 WON!
                                        Monkey 1 WON!
                                        Monkey 2 WON!



                                        0 TIES

                                        Monkey 1: 498 WINS

                                        Monkey 2: 502 WINS


                                        So it seems pretty tied to me







                                        share|improve this answer










                                        New contributor




                                        Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                        Check out our Code of Conduct.




















                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote









                                          I have created the simulation in C# based on Marco's idea.
                                          The alphabet is reduced and the performance is improved:



                                          public class Monkey
                                          {
                                          private static readonly char alphabet = "ACNOTUXY".ToCharArray();
                                          private static readonly Random random = new Random();

                                          public Monkey(string Target)
                                          {
                                          target = Target.ToCharArray();
                                          length = target.Length;
                                          input = new char[length];
                                          inputPosition = 0;
                                          }

                                          private readonly char target;
                                          private readonly int length;
                                          private readonly char input;
                                          private int inputPosition;

                                          public bool TargetReached { get; private set; }

                                          public void PressKey()
                                          {
                                          var key = alphabet[random.Next(0, 8)];
                                          input[inputPosition] = key;
                                          inputPosition = ++inputPosition % length;
                                          TargetReached = IsTargetReached();
                                          }

                                          private bool IsTargetReached()
                                          {
                                          for (var i = 0; i < length; i++)
                                          {
                                          if (input[i] != target[i]) return false;
                                          }
                                          return true;
                                          }
                                          }

                                          public class Simulator
                                          {
                                          private int ties;
                                          private int monkey1Wins;
                                          private int monkey2Wins;

                                          public void Run(int numberOfCompetitons)
                                          {
                                          for (var i = 0; i < numberOfCompetitons; i++)
                                          {
                                          RunCompetition();
                                          }
                                          }

                                          private void RunCompetition()
                                          {
                                          var monkey1 = new Monkey("COCONUT");
                                          var monkey2 = new Monkey("TUNOCOC");

                                          while (true)
                                          {
                                          monkey1.PressKey();
                                          monkey2.PressKey();

                                          if (monkey1.TargetReached && monkey2.TargetReached)
                                          {
                                          ties++;
                                          Console.WriteLine("It's a TIE!");
                                          break;
                                          }
                                          if (monkey1.TargetReached)
                                          {
                                          monkey1Wins++;
                                          Console.WriteLine("Monkey 1 WON!");
                                          break;
                                          }
                                          if (monkey2.TargetReached)
                                          {
                                          monkey2Wins++;
                                          Console.WriteLine("Monkey 2 WON!");
                                          break;
                                          }
                                          }
                                          }

                                          public void ShowSummary()
                                          {
                                          Console.WriteLine();
                                          Console.WriteLine($"{ties} TIES");
                                          Console.WriteLine($
                                          "Monkey 1: {monkey1Wins} WINS");
                                          Console.WriteLine($"Monkey 2: {monkey2Wins} WINS");
                                          }
                                          }

                                          internal class Program
                                          {
                                          private static void Main()
                                          {
                                          var simulator = new Simulator();
                                          simulator.Run(1000);
                                          simulator.ShowSummary();
                                          Console.ReadKey();
                                          }
                                          }


                                          Sample output:



                                          ...
                                          Monkey 1 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!
                                          Monkey 2 WON!
                                          Monkey 1 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!



                                          0 TIES

                                          Monkey 1: 498 WINS

                                          Monkey 2: 502 WINS


                                          So it seems pretty tied to me







                                          share|improve this answer










                                          New contributor




                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          I have created the simulation in C# based on Marco's idea.
                                          The alphabet is reduced and the performance is improved:



                                          public class Monkey
                                          {
                                          private static readonly char alphabet = "ACNOTUXY".ToCharArray();
                                          private static readonly Random random = new Random();

                                          public Monkey(string Target)
                                          {
                                          target = Target.ToCharArray();
                                          length = target.Length;
                                          input = new char[length];
                                          inputPosition = 0;
                                          }

                                          private readonly char target;
                                          private readonly int length;
                                          private readonly char input;
                                          private int inputPosition;

                                          public bool TargetReached { get; private set; }

                                          public void PressKey()
                                          {
                                          var key = alphabet[random.Next(0, 8)];
                                          input[inputPosition] = key;
                                          inputPosition = ++inputPosition % length;
                                          TargetReached = IsTargetReached();
                                          }

                                          private bool IsTargetReached()
                                          {
                                          for (var i = 0; i < length; i++)
                                          {
                                          if (input[i] != target[i]) return false;
                                          }
                                          return true;
                                          }
                                          }

                                          public class Simulator
                                          {
                                          private int ties;
                                          private int monkey1Wins;
                                          private int monkey2Wins;

                                          public void Run(int numberOfCompetitons)
                                          {
                                          for (var i = 0; i < numberOfCompetitons; i++)
                                          {
                                          RunCompetition();
                                          }
                                          }

                                          private void RunCompetition()
                                          {
                                          var monkey1 = new Monkey("COCONUT");
                                          var monkey2 = new Monkey("TUNOCOC");

                                          while (true)
                                          {
                                          monkey1.PressKey();
                                          monkey2.PressKey();

                                          if (monkey1.TargetReached && monkey2.TargetReached)
                                          {
                                          ties++;
                                          Console.WriteLine("It's a TIE!");
                                          break;
                                          }
                                          if (monkey1.TargetReached)
                                          {
                                          monkey1Wins++;
                                          Console.WriteLine("Monkey 1 WON!");
                                          break;
                                          }
                                          if (monkey2.TargetReached)
                                          {
                                          monkey2Wins++;
                                          Console.WriteLine("Monkey 2 WON!");
                                          break;
                                          }
                                          }
                                          }

                                          public void ShowSummary()
                                          {
                                          Console.WriteLine();
                                          Console.WriteLine($"{ties} TIES");
                                          Console.WriteLine($
                                          "Monkey 1: {monkey1Wins} WINS");
                                          Console.WriteLine($"Monkey 2: {monkey2Wins} WINS");
                                          }
                                          }

                                          internal class Program
                                          {
                                          private static void Main()
                                          {
                                          var simulator = new Simulator();
                                          simulator.Run(1000);
                                          simulator.ShowSummary();
                                          Console.ReadKey();
                                          }
                                          }


                                          Sample output:



                                          ...
                                          Monkey 1 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!
                                          Monkey 2 WON!
                                          Monkey 1 WON!
                                          Monkey 1 WON!
                                          Monkey 2 WON!



                                          0 TIES

                                          Monkey 1: 498 WINS

                                          Monkey 2: 502 WINS


                                          So it seems pretty tied to me








                                          share|improve this answer










                                          New contributor




                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          share|improve this answer



                                          share|improve this answer








                                          edited 17 hours ago





















                                          New contributor




                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          answered 17 hours ago









                                          Dusan

                                          1094




                                          1094




                                          New contributor




                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.





                                          New contributor





                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.






                                          Dusan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.






















                                              up vote
                                              0
                                              down vote













                                              For problem (b)



                                              Not really a satisfactory answer, but...




                                              At first sight the only difference between "COCONUT" and "TUNOCOC", that could tilt the chances to one side or the other, is that they have more overlap in one order than in the other. "COCONUT" followed by "TUNOCOC" can be overlapped only in the form "COCONUTUNOCOC", while, the other way around, they can be overlapped like "TUNOCOCOCONUT" or like "TUNOCOCONUT".


                                              If we assume that this is really the only relevant difference, we can try to replicate it with an alphabet small enough to run a simulation. So let's say that the alphabet has only the letters "A", "B" and "X", that the first squirrel is betting on "AAB" and the second on "BAA". Note that those strings show the same property that "AAB" can overlap with "BAA" only in the form "AABAA", but in the other way around it can be either "BAAAB" or "BAAB".


                                              This is certainly simple enough to simulate. So I wrote a short program that simulates the game 10 million times and calculates the percentage of success of each squirrel. I ran the program several times, and the percentages, while they obviously show some variation, seem to be always in the range of 38.4 - 38.5% of wins for the first squirrel, and 61.5 - 61.6% of wins for the second squirrel.


                                              If we can extrapolate that to the original problem (not sure that we can) we would expect the second squirrel to have a greater chance at winning, even if by a much smaller margin than in the simulation. Now we only need to find a proper explanation of why.


                                              The program (in Java):


                                              public class Monkeys {

                                              private enum Squirrel {
                                              FIRST_SQUIRREL,
                                              SECOND_SQUIRREL
                                              }

                                              private static final Random random = new Random();
                                              private static final char letters = "ABX".toCharArray();

                                              public static void main(String args) {

                                              int winsF = 0;
                                              int winsS = 0;
                                              int iterations = 10000000;

                                              for (int i = 0; i < iterations; i++) {

                                              Squirrel winner = playGame();
                                              if (winner == Squirrel.FIRST_SQUIRREL) {
                                              winsF++;
                                              } else if (winner == Squirrel.SECOND_SQUIRREL) {
                                              winsS++;
                                              }
                                              }

                                              System.out.println("First squirrel wins: " + ((double) winsF) / (winsF + winsS));
                                              System.out.println("Second squirrel wins: " + ((double) winsS) / (winsF + winsS));

                                              }

                                              private static Squirrel playGame() {
                                              StringBuilder sb = new StringBuilder();
                                              while (true) {
                                              if (sb.length() >= 3) {
                                              if (sb.substring(sb.length() - 3, sb.length()).equals("AAB")) {
                                              return Squirrel.FIRST_SQUIRREL;
                                              }
                                              if (sb.substring(sb.length() - 3, sb.length()).equals("BAA")) {
                                              return Squirrel.SECOND_SQUIRREL;
                                              }
                                              }
                                              sb.append(letters[random.nextInt(letters.length)]);
                                              }
                                              }
                                              }






                                              share|improve this answer








                                              New contributor




                                              abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.






















                                                up vote
                                                0
                                                down vote













                                                For problem (b)



                                                Not really a satisfactory answer, but...




                                                At first sight the only difference between "COCONUT" and "TUNOCOC", that could tilt the chances to one side or the other, is that they have more overlap in one order than in the other. "COCONUT" followed by "TUNOCOC" can be overlapped only in the form "COCONUTUNOCOC", while, the other way around, they can be overlapped like "TUNOCOCOCONUT" or like "TUNOCOCONUT".


                                                If we assume that this is really the only relevant difference, we can try to replicate it with an alphabet small enough to run a simulation. So let's say that the alphabet has only the letters "A", "B" and "X", that the first squirrel is betting on "AAB" and the second on "BAA". Note that those strings show the same property that "AAB" can overlap with "BAA" only in the form "AABAA", but in the other way around it can be either "BAAAB" or "BAAB".


                                                This is certainly simple enough to simulate. So I wrote a short program that simulates the game 10 million times and calculates the percentage of success of each squirrel. I ran the program several times, and the percentages, while they obviously show some variation, seem to be always in the range of 38.4 - 38.5% of wins for the first squirrel, and 61.5 - 61.6% of wins for the second squirrel.


                                                If we can extrapolate that to the original problem (not sure that we can) we would expect the second squirrel to have a greater chance at winning, even if by a much smaller margin than in the simulation. Now we only need to find a proper explanation of why.


                                                The program (in Java):


                                                public class Monkeys {

                                                private enum Squirrel {
                                                FIRST_SQUIRREL,
                                                SECOND_SQUIRREL
                                                }

                                                private static final Random random = new Random();
                                                private static final char letters = "ABX".toCharArray();

                                                public static void main(String args) {

                                                int winsF = 0;
                                                int winsS = 0;
                                                int iterations = 10000000;

                                                for (int i = 0; i < iterations; i++) {

                                                Squirrel winner = playGame();
                                                if (winner == Squirrel.FIRST_SQUIRREL) {
                                                winsF++;
                                                } else if (winner == Squirrel.SECOND_SQUIRREL) {
                                                winsS++;
                                                }
                                                }

                                                System.out.println("First squirrel wins: " + ((double) winsF) / (winsF + winsS));
                                                System.out.println("Second squirrel wins: " + ((double) winsS) / (winsF + winsS));

                                                }

                                                private static Squirrel playGame() {
                                                StringBuilder sb = new StringBuilder();
                                                while (true) {
                                                if (sb.length() >= 3) {
                                                if (sb.substring(sb.length() - 3, sb.length()).equals("AAB")) {
                                                return Squirrel.FIRST_SQUIRREL;
                                                }
                                                if (sb.substring(sb.length() - 3, sb.length()).equals("BAA")) {
                                                return Squirrel.SECOND_SQUIRREL;
                                                }
                                                }
                                                sb.append(letters[random.nextInt(letters.length)]);
                                                }
                                                }
                                                }






                                                share|improve this answer








                                                New contributor




                                                abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.




















                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  For problem (b)



                                                  Not really a satisfactory answer, but...




                                                  At first sight the only difference between "COCONUT" and "TUNOCOC", that could tilt the chances to one side or the other, is that they have more overlap in one order than in the other. "COCONUT" followed by "TUNOCOC" can be overlapped only in the form "COCONUTUNOCOC", while, the other way around, they can be overlapped like "TUNOCOCOCONUT" or like "TUNOCOCONUT".


                                                  If we assume that this is really the only relevant difference, we can try to replicate it with an alphabet small enough to run a simulation. So let's say that the alphabet has only the letters "A", "B" and "X", that the first squirrel is betting on "AAB" and the second on "BAA". Note that those strings show the same property that "AAB" can overlap with "BAA" only in the form "AABAA", but in the other way around it can be either "BAAAB" or "BAAB".


                                                  This is certainly simple enough to simulate. So I wrote a short program that simulates the game 10 million times and calculates the percentage of success of each squirrel. I ran the program several times, and the percentages, while they obviously show some variation, seem to be always in the range of 38.4 - 38.5% of wins for the first squirrel, and 61.5 - 61.6% of wins for the second squirrel.


                                                  If we can extrapolate that to the original problem (not sure that we can) we would expect the second squirrel to have a greater chance at winning, even if by a much smaller margin than in the simulation. Now we only need to find a proper explanation of why.


                                                  The program (in Java):


                                                  public class Monkeys {

                                                  private enum Squirrel {
                                                  FIRST_SQUIRREL,
                                                  SECOND_SQUIRREL
                                                  }

                                                  private static final Random random = new Random();
                                                  private static final char letters = "ABX".toCharArray();

                                                  public static void main(String args) {

                                                  int winsF = 0;
                                                  int winsS = 0;
                                                  int iterations = 10000000;

                                                  for (int i = 0; i < iterations; i++) {

                                                  Squirrel winner = playGame();
                                                  if (winner == Squirrel.FIRST_SQUIRREL) {
                                                  winsF++;
                                                  } else if (winner == Squirrel.SECOND_SQUIRREL) {
                                                  winsS++;
                                                  }
                                                  }

                                                  System.out.println("First squirrel wins: " + ((double) winsF) / (winsF + winsS));
                                                  System.out.println("Second squirrel wins: " + ((double) winsS) / (winsF + winsS));

                                                  }

                                                  private static Squirrel playGame() {
                                                  StringBuilder sb = new StringBuilder();
                                                  while (true) {
                                                  if (sb.length() >= 3) {
                                                  if (sb.substring(sb.length() - 3, sb.length()).equals("AAB")) {
                                                  return Squirrel.FIRST_SQUIRREL;
                                                  }
                                                  if (sb.substring(sb.length() - 3, sb.length()).equals("BAA")) {
                                                  return Squirrel.SECOND_SQUIRREL;
                                                  }
                                                  }
                                                  sb.append(letters[random.nextInt(letters.length)]);
                                                  }
                                                  }
                                                  }






                                                  share|improve this answer








                                                  New contributor




                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.









                                                  For problem (b)



                                                  Not really a satisfactory answer, but...




                                                  At first sight the only difference between "COCONUT" and "TUNOCOC", that could tilt the chances to one side or the other, is that they have more overlap in one order than in the other. "COCONUT" followed by "TUNOCOC" can be overlapped only in the form "COCONUTUNOCOC", while, the other way around, they can be overlapped like "TUNOCOCOCONUT" or like "TUNOCOCONUT".


                                                  If we assume that this is really the only relevant difference, we can try to replicate it with an alphabet small enough to run a simulation. So let's say that the alphabet has only the letters "A", "B" and "X", that the first squirrel is betting on "AAB" and the second on "BAA". Note that those strings show the same property that "AAB" can overlap with "BAA" only in the form "AABAA", but in the other way around it can be either "BAAAB" or "BAAB".


                                                  This is certainly simple enough to simulate. So I wrote a short program that simulates the game 10 million times and calculates the percentage of success of each squirrel. I ran the program several times, and the percentages, while they obviously show some variation, seem to be always in the range of 38.4 - 38.5% of wins for the first squirrel, and 61.5 - 61.6% of wins for the second squirrel.


                                                  If we can extrapolate that to the original problem (not sure that we can) we would expect the second squirrel to have a greater chance at winning, even if by a much smaller margin than in the simulation. Now we only need to find a proper explanation of why.


                                                  The program (in Java):


                                                  public class Monkeys {

                                                  private enum Squirrel {
                                                  FIRST_SQUIRREL,
                                                  SECOND_SQUIRREL
                                                  }

                                                  private static final Random random = new Random();
                                                  private static final char letters = "ABX".toCharArray();

                                                  public static void main(String args) {

                                                  int winsF = 0;
                                                  int winsS = 0;
                                                  int iterations = 10000000;

                                                  for (int i = 0; i < iterations; i++) {

                                                  Squirrel winner = playGame();
                                                  if (winner == Squirrel.FIRST_SQUIRREL) {
                                                  winsF++;
                                                  } else if (winner == Squirrel.SECOND_SQUIRREL) {
                                                  winsS++;
                                                  }
                                                  }

                                                  System.out.println("First squirrel wins: " + ((double) winsF) / (winsF + winsS));
                                                  System.out.println("Second squirrel wins: " + ((double) winsS) / (winsF + winsS));

                                                  }

                                                  private static Squirrel playGame() {
                                                  StringBuilder sb = new StringBuilder();
                                                  while (true) {
                                                  if (sb.length() >= 3) {
                                                  if (sb.substring(sb.length() - 3, sb.length()).equals("AAB")) {
                                                  return Squirrel.FIRST_SQUIRREL;
                                                  }
                                                  if (sb.substring(sb.length() - 3, sb.length()).equals("BAA")) {
                                                  return Squirrel.SECOND_SQUIRREL;
                                                  }
                                                  }
                                                  sb.append(letters[random.nextInt(letters.length)]);
                                                  }
                                                  }
                                                  }







                                                  share|improve this answer








                                                  New contributor




                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.









                                                  share|improve this answer



                                                  share|improve this answer






                                                  New contributor




                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.









                                                  answered 9 hours ago









                                                  abl

                                                  1364




                                                  1364




                                                  New contributor




                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.





                                                  New contributor





                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.






                                                  abl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                  Check out our Code of Conduct.






















                                                      up vote
                                                      -1
                                                      down vote













                                                      Similar to Marco Salerno's answer, I wrote a computer program to solve the monkey problem.



                                                      static void Coconuts(int iterations)
                                                      {
                                                      Tuple<double, double> outcomes = new Tuple<double, double>[iterations];
                                                      char alphabet = new char { 'C', 'O', 'N', 'U', 'T' };
                                                      string target1 = "COCONUT";
                                                      string target2 = "TUNOCOC";
                                                      for(int i = 0; i < iterations; i++)
                                                      {
                                                      outcomes[i] = new Tuple<double, double>(RandomLettersToTarget(alphabet, target1), RandomLettersToTarget(alphabet, target2));
                                                      Console.WriteLine($"{outcomes[i].Item1:0.0}t{outcomes[i].Item2:0.0}");
                                                      }

                                                      double average1 = outcomes.Select(pair => pair.Item1).Average();
                                                      double average2 = outcomes.Select(pair => pair.Item2).Average();

                                                      Console.WriteLine($"Average durations are {average1:00000.0}, {average2:00000.0}");
                                                      }

                                                      static int RandomLettersToTarget(char alphabet, string target, int stepsToInsanity = 100000000)
                                                      {
                                                      string soFar = "";
                                                      int steps = 0;
                                                      while(steps < stepsToInsanity)
                                                      {
                                                      soFar += alphabet[rng.Next(0, alphabet.Length)];
                                                      if(soFar.Length >= target.Length)
                                                      {
                                                      soFar = soFar.Substring(soFar.Length - target.Length, target.Length);
                                                      }
                                                      if(target.Equals(soFar))
                                                      {
                                                      return steps;
                                                      }
                                                      steps++;
                                                      }
                                                      return stepsToInsanity;
                                                      }


                                                      With the reduced alphabet (containing only 5 letters) this program does complete, and the results over thousands of iterations




                                                      show no clear winner. Thus, I conclude that each monkey has equal probability of winning the first game.







                                                      share|improve this answer



























                                                        up vote
                                                        -1
                                                        down vote













                                                        Similar to Marco Salerno's answer, I wrote a computer program to solve the monkey problem.



                                                        static void Coconuts(int iterations)
                                                        {
                                                        Tuple<double, double> outcomes = new Tuple<double, double>[iterations];
                                                        char alphabet = new char { 'C', 'O', 'N', 'U', 'T' };
                                                        string target1 = "COCONUT";
                                                        string target2 = "TUNOCOC";
                                                        for(int i = 0; i < iterations; i++)
                                                        {
                                                        outcomes[i] = new Tuple<double, double>(RandomLettersToTarget(alphabet, target1), RandomLettersToTarget(alphabet, target2));
                                                        Console.WriteLine($"{outcomes[i].Item1:0.0}t{outcomes[i].Item2:0.0}");
                                                        }

                                                        double average1 = outcomes.Select(pair => pair.Item1).Average();
                                                        double average2 = outcomes.Select(pair => pair.Item2).Average();

                                                        Console.WriteLine($"Average durations are {average1:00000.0}, {average2:00000.0}");
                                                        }

                                                        static int RandomLettersToTarget(char alphabet, string target, int stepsToInsanity = 100000000)
                                                        {
                                                        string soFar = "";
                                                        int steps = 0;
                                                        while(steps < stepsToInsanity)
                                                        {
                                                        soFar += alphabet[rng.Next(0, alphabet.Length)];
                                                        if(soFar.Length >= target.Length)
                                                        {
                                                        soFar = soFar.Substring(soFar.Length - target.Length, target.Length);
                                                        }
                                                        if(target.Equals(soFar))
                                                        {
                                                        return steps;
                                                        }
                                                        steps++;
                                                        }
                                                        return stepsToInsanity;
                                                        }


                                                        With the reduced alphabet (containing only 5 letters) this program does complete, and the results over thousands of iterations




                                                        show no clear winner. Thus, I conclude that each monkey has equal probability of winning the first game.







                                                        share|improve this answer

























                                                          up vote
                                                          -1
                                                          down vote










                                                          up vote
                                                          -1
                                                          down vote









                                                          Similar to Marco Salerno's answer, I wrote a computer program to solve the monkey problem.



                                                          static void Coconuts(int iterations)
                                                          {
                                                          Tuple<double, double> outcomes = new Tuple<double, double>[iterations];
                                                          char alphabet = new char { 'C', 'O', 'N', 'U', 'T' };
                                                          string target1 = "COCONUT";
                                                          string target2 = "TUNOCOC";
                                                          for(int i = 0; i < iterations; i++)
                                                          {
                                                          outcomes[i] = new Tuple<double, double>(RandomLettersToTarget(alphabet, target1), RandomLettersToTarget(alphabet, target2));
                                                          Console.WriteLine($"{outcomes[i].Item1:0.0}t{outcomes[i].Item2:0.0}");
                                                          }

                                                          double average1 = outcomes.Select(pair => pair.Item1).Average();
                                                          double average2 = outcomes.Select(pair => pair.Item2).Average();

                                                          Console.WriteLine($"Average durations are {average1:00000.0}, {average2:00000.0}");
                                                          }

                                                          static int RandomLettersToTarget(char alphabet, string target, int stepsToInsanity = 100000000)
                                                          {
                                                          string soFar = "";
                                                          int steps = 0;
                                                          while(steps < stepsToInsanity)
                                                          {
                                                          soFar += alphabet[rng.Next(0, alphabet.Length)];
                                                          if(soFar.Length >= target.Length)
                                                          {
                                                          soFar = soFar.Substring(soFar.Length - target.Length, target.Length);
                                                          }
                                                          if(target.Equals(soFar))
                                                          {
                                                          return steps;
                                                          }
                                                          steps++;
                                                          }
                                                          return stepsToInsanity;
                                                          }


                                                          With the reduced alphabet (containing only 5 letters) this program does complete, and the results over thousands of iterations




                                                          show no clear winner. Thus, I conclude that each monkey has equal probability of winning the first game.







                                                          share|improve this answer














                                                          Similar to Marco Salerno's answer, I wrote a computer program to solve the monkey problem.



                                                          static void Coconuts(int iterations)
                                                          {
                                                          Tuple<double, double> outcomes = new Tuple<double, double>[iterations];
                                                          char alphabet = new char { 'C', 'O', 'N', 'U', 'T' };
                                                          string target1 = "COCONUT";
                                                          string target2 = "TUNOCOC";
                                                          for(int i = 0; i < iterations; i++)
                                                          {
                                                          outcomes[i] = new Tuple<double, double>(RandomLettersToTarget(alphabet, target1), RandomLettersToTarget(alphabet, target2));
                                                          Console.WriteLine($"{outcomes[i].Item1:0.0}t{outcomes[i].Item2:0.0}");
                                                          }

                                                          double average1 = outcomes.Select(pair => pair.Item1).Average();
                                                          double average2 = outcomes.Select(pair => pair.Item2).Average();

                                                          Console.WriteLine($"Average durations are {average1:00000.0}, {average2:00000.0}");
                                                          }

                                                          static int RandomLettersToTarget(char alphabet, string target, int stepsToInsanity = 100000000)
                                                          {
                                                          string soFar = "";
                                                          int steps = 0;
                                                          while(steps < stepsToInsanity)
                                                          {
                                                          soFar += alphabet[rng.Next(0, alphabet.Length)];
                                                          if(soFar.Length >= target.Length)
                                                          {
                                                          soFar = soFar.Substring(soFar.Length - target.Length, target.Length);
                                                          }
                                                          if(target.Equals(soFar))
                                                          {
                                                          return steps;
                                                          }
                                                          steps++;
                                                          }
                                                          return stepsToInsanity;
                                                          }


                                                          With the reduced alphabet (containing only 5 letters) this program does complete, and the results over thousands of iterations




                                                          show no clear winner. Thus, I conclude that each monkey has equal probability of winning the first game.








                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited yesterday

























                                                          answered yesterday









                                                          Tim C

                                                          75248




                                                          75248






















                                                              anmol porwal is a new contributor. Be nice, and check out our Code of Conduct.










                                                               

                                                              draft saved


                                                              draft discarded


















                                                              anmol porwal is a new contributor. Be nice, and check out our Code of Conduct.













                                                              anmol porwal is a new contributor. Be nice, and check out our Code of Conduct.












                                                              anmol porwal is a new contributor. Be nice, and check out our Code of Conduct.















                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f75627%2f2-monkeys-on-a-computer%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                                              Alcedinidae

                                                              RAC Tourist Trophy