Render a 1/2 true & 1/2 false bool function by another function returning bool probabilistically Problem
Given a bool function g() which returns true with 1/4 and false with 3/4,
use that function to render another bool function f() which returns true with 1/2 and false with 1/2.
I saw this question on an interview review website, and there are no answers to it.
I tried to solve it but failed after several hours.
I appreciate any suggestions.
Possible Answer
I wrote some python code by simplifying the answer from @Zubin Mukerjee
def f():
    while True:
        x = g()
        y = g()
        if x != y:
            return x

 A: I've written some Java code as a sample solution to your problem. 
The function threefourthspotato below is true with probability $1/4$, and false with probability $3/4$.  
I have used it to construct a function halfpotato that is true with probability $1/2$, and false with probability $1/2$. 

public static boolean threefourthspotato() {
    return (Math.random() > 0.75);
}


In Java, Math.random() is a double chosen between $0$ and $1$. This means that the function threefourthspotato will return true with probability $1/4$, and false with probability $3/4$. 
How I have constructed threefourthspotato here is irrelevant, the only fact that is relevant to halfpotato working as intended is that threefourthspotato returns true with probability $1/4$. 

public static boolean halfpotato() {
    int x=0;
    boolean y = false;   // this will eventually be true with probability 1/2
    while (x < 1) {      // x is a dummy variable for the loop
        y = threefourthspotato();
        boolean z = threefourthspotato();
        if (y ^ z) {     // if y XOR z is true
            x = 1;       // then end the loop
        }
    }
    return y;
}


This method is analogous to a common method used for simulating a fair coin using multiple flips of a biased coin.
