You are provided with a function f() which returns either 0 or 1 with probability 1/2. Using this to construct a function f1() which returns 0 with probability 1/3 and 1 with probability 2/3.
int f1(){
while( true ){
if( f()==1 ) return 1;
if( f()==1 ) return 0;
}
}
int f1()
{
while( true)
{
int x = f();
int y = f();
if(x==1) return 1;
if(y==1) return 0;
}
}
int f1()
{
int x = 2;
while(x ==2)
{
x=f() + f();
}
return x;
}