How to use a fair coin to simulate any probability $p$ of winning You have a fair coin and you are tasked with designing a simple game using the fair coin so that your probability of winning is between $0 < p < 1$. One easy method I can think of to simply represent the i-th toss as the i-th bit of some $n$-bit integer. i.e., if you get heads, the i-th bit is turned on and turned off otherwise.
For example, if you toss heads, tail, heads, heads. Your integer is
$$
1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 8 + 4 + 1 = 13
$$
Then to turn this into a probability, we divide the above outcome by the maximum representable number of $n$ bits, which for $n=4$ would be $2^4 - 1 = 15$. Then using this approach, we can assign some range of numbers to be winning and some to be losing. e.g., if I wanted a 25% chance of winning, then I could assign numbers 0-3 as winning and numbers 4-15 as losing and each number occurs with equal probability by symmetry.
This is one approach I thought of and I'm trying to understand another solution, which is shown in the screenshot below.
My confusion is why does $s_i < p_i$ indicate that we win and vice versa? $s_i$ and $p_i$ are just binary values, so I don't understand what this solution is saying. Could it be a typo or does it make sense to others?

 A: To make the probability of winning equal to $p \in [0, 1]$, you would randomly choose a number in $[0, 1]$. If the random number is less than $p$, then that is counted as a win. If the random number is greater than $p$, that is counted as a loss. The problem here is that the only way of generating the random number is through coin flips.
Given an infinite sequence of coin flips, represented as $(s_n)_{n \ge 1}$, the constant random number associated with that would be $$s = \sum_{n=1}^{\infty} \frac{s_n}{2^n}$$
The key here is to stop flipping coins if it is guaranteed to win or lose. Specifically, even if a sequence of straight $1$s after the $i$th flip wouldn't make it win, or if a sequence of straight $0$s after the $i$th flip wouldn't make it lose. For the first case, we can stop if $s_i < p_i$ since even an infinite sequence of $1$s after the $i$th flip wouldn't change that $s < p$. For the second case, we can stop if $s_i > p_i$ since even an infinite sequence of $0$s after the $i$th flip wouldn't change that $s>p$.
Intuitively, this follows from the fact that any subsequent digits couldn't possible affect previous digits.
