Skip to content

Commit be2467e

Browse files
committed
6.2 Add Basketball (math)
1 parent 58bcd1d commit be2467e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
* 5.0 [Bitwise Operations Cheat Sheet](https://github.com/another-guy/problem-solving-ts/blob/master/src/cracking-the-coding-interview/5-bit-manipulation/5-0-cheat-sheet.md)
2727
* 5.1 Insert one bit sequence into another
2828
* 5.3 [Flip bit to win](https://github.com/another-guy/problem-solving-ts/blob/master/src/cracking-the-coding-interview/5-bit-manipulation/5-3-flip-to-win.cr.md). [[Code Review]](https://codereview.stackexchange.com/questions/194733/find-the-longest-length-of-sequence-of-1-bits-achievable-by-flipping-a-single-bi)
29-
* 6 TODO
29+
* 6 Math and Logic Puzzles
30+
* 6.2 Basketball
3031
* 7 TODO
3132
* 8 Recursion and Dynamic Programming
3233
* 8.1 Triple step (non-recursive)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Basketball Game
2+
3+
Let $p$ is the probability of a single successful throw.
4+
5+
Therefore, to win in a two-out-of-three-throws game, one of the following outcomes must happen:
6+
7+
* hit+hit+hit $P_{allThree} = p*p*p = p^3$ ;
8+
* hit+hit+miss OR hit+miss+hit OR miss+hit+hit $P_{twoOnly} = 3 * [p * p * (1-p)] = 3 p^2 (1-p)$ .
9+
10+
The likelyhood of the win in such game is $p^3 + 3p^2(1-p)$
11+
12+
In order for two-out-of-three-throws to be more appealing, the following inequality must be solved:
13+
14+
| . | . |
15+
|:--:|:--:|
16+
| $p^3 + 3p^2(1-p) > p$ | divide by $p$ |
17+
| $p^2 + 3p(1-p) > 1$ | |
18+
| $p^2 +3p - 3p^2 - 1 > 0$ | |
19+
| $-2p^2 + 3p - 1 > 0$ | multiply by $-1$ |
20+
| $2p^2 - 3p + 1 < 0$ | |
21+
| $(p - 1)(p - \frac{1}{2}) < 0$ | |
22+
23+
From the graph below it's clear that the inequation holds for range of $0.5 < p < 1$:
24+
25+
[![graph][1]][1]
26+
27+
[1]: https://i.imgur.com/sl1XcnN.png

0 commit comments

Comments
 (0)