I try to solve the following task:
Let $p\in ]0,1[$ and $X_1,X_2,\dots,Y_1,Y_2,\dots$ be i.i.d. Bernoulli$(p)$ random variables. We define $N:=\min\{n\in\mathbb{N}:X_n\neq Y_n\}$ and set $$Z:=X_N=\sum\limits_{n=1}^\infty \mathbb{1}_{\{N=n\}}X_n$$ where $1$ is the indicator function.
- Check that $N\geq 1$ has the geometric distribution with parameter $2p(1-p)$
Show that $Z$ has Bernoulli$(1/2)$ distribution
Deduce a way to simulate a fair coin toss using a potentially unfair coin.
My attempt:
We are interested in the case where after $n-1$ steps the $X_n\neq Y_n$.
$P(X_1=Y_1,\dots, X_n\neq Y_n)=P(X_1=Y_1)\cdots P(X_n\neq Y_n)$
I can view $Z:=X_i=Y_i$ as a Bernoulli experiment since it is either true or not. So I want to find out, at which step $P(Z_n)=1-p$ So I have $$P(Z_1)\cdots P(Z_n)=P(X_1=Y_1)\cdots P(X_n\neq Y_n)=p^{n-1}(1-p)$$ Which is the geometric distribution with parameter $q:=1-p$.
But I don't know why it should have parameter $2p(1-p)$ and how the rest works.