mathtaskprobabilityprobability-theory

Playful cat and keyboard

Problem:

The keyboard on the screen of the mobile application consists of: 26 capital Latin letters, 10 digits 4 navigation keys: up, down, right and left.

The application is open on a tablet, on which an unpredictable and consistent cat walks. The unpredictability of the cat is that all its movements are random and independent, that is, it can press the same key in a row. Or different - it's unpredictable. And his sequence is that he attacks each in turn, and not simultaneously. What is the probability that after eight steps on the buttons this cat will press the arrow at least once? Give your answer as a percentage, rounded to the nearest whole number.

I tried different formulas on Python for finding the probability and settled on this one, but it does not give the correct result

``````no_arrow_prob = (1/10)**8*100
print(no_arrow_prob)
``````

I will be thankful for any help. =)

Solution

• One way to think about it:

So there's 40 keys. And 4 of them are arrows. So the probability that the cat hits an arrow on the first change is `4/40` or 10%.

If it doesn't hit it on the first try, it's got another chance.

And so on.

``````          10%
┌────► hit an arrow
│
│                           10%
│                          ┌──► hit an arrow on try two
│                          │
first try│                          │
│                          │
│                          │
│ 90%                      │
└────► didn't hit an arrow │
on try one.        │
│90%
└───► didn't hit an arrow
on try two
``````

You could implement this logic in python as:

``````arrow_prob = 0
remaining_prob = 1.0
for attempt in range(10):
arrow_prob += remaining_prob * .1
remaining_prob *= .9
print(int(100*arrow_prob))
``````

Another way:

Alternatively, we could ask what is the probability that I never hit an arrow key over one attempt. This would be `36/40`.

And what's the probability that I never hit an arrow key over 10 attempts: `(36/40) ** 10`.

``````no_arrow_prob = (36/40) ** 10
arrow_prob = 1 - no_arrow_prob
print(int(arrow_prob * 100))
``````