number_simulations := 1000:
tosses := Array(1..number_simulations):
for i from 1 to number_simulations by 1 do
previous := 0:
current := -2:
Stop := 0:
while (Stop = 0) do
tosses[i] := tosses[i] + 1;
u := rand()/10^12;
if (u<.6) then current := 1 else current := -1 end if;
if (current = previous) then Stop := 1 else Stop := 0 end if;
previous := current;
end do:
end do:
evalf(add(tosses[i], i=1..number_simulations)/number_simulations);