Algorithm THREEHEADSORTHREETAILS(k): flip a fair coin three times; if the result is HHH or TTT then return k else THREEHEADSORTHREETAILS(k+1) endif