mixster
2008-02-15 17:02:12
Haven't you ever wondered how bored you must be to throw hundreds of thousands of coins to get 20 in a row come up heads (that's a 1 in a million chance, more or less)? Well wonder no more, for I have the solution! Not only does it relieve the stress of getting a sore arm, but it also removes the 'remembering if the last 19 coins were heads' issue, counts how many coins were thrown and how long it took you. Never again will you come second best to that random guy who managed to throw 20 heads in a row in a few hours.
I do hope to (eventually) release a 'highscore' to see who truly does have the most luck and can throw the 20 in the least dice.
Also, feel free to change anything, as throwing 20 heads in a row can take some time if you're extremely unlucky (my personal best is in 149623 throws which took 72187 milliseconds and that was after a good 20 or so runs).
Also, to speed it up, you can remove the loop writeln, though it doesn't look as good when you throw 20 (in my opinion).
program OneInAMillion;
var
i,n,timeRunning: Integer;
heads: array[0..19] of Boolean;
function check: Boolean;
var
i: Integer;
begin
for i:= 0 to 19 do
begin
if not heads[i] then
exit;
end;
Result:= True;
end;
begin
timeRunning:= GetSystemTime;
for i:= 0 to 19 do
heads[i]:= RBool;
i:= 19;
repeat
Inc(i);
n:= i-((i div 20)*20);
heads[n]:= RBool;
if(check) then
Break;
if(heads[n]) then
Writeln('Heads')
else
Writeln('Tails');
// Sleep(1);
until(False)
timeRunning:= GetSystemTime-timeRunning;
Writeln('Well done - a '+IntToStr(Round(1/Pow(0.5,20)))+' chance just happened and you threw 10 virtual heads in a row');
Writeln('Not only that, but it only took you '+IntToStr(timeRunning)+' milliseconds');
Writeln('Also, only '+IntToStr(i)+' virtual throws were needed for the 1 in a million chance');
end.
If your pc slows down drastically when using, uncomment the sleep and it should be ok (took it out as it made it take a lot longer when testing). I do hope to (eventually) release a 'highscore' to see who truly does have the most luck and can throw the 20 in the least dice.
Also, feel free to change anything, as throwing 20 heads in a row can take some time if you're extremely unlucky (my personal best is in 149623 throws which took 72187 milliseconds and that was after a good 20 or so runs).
Also, to speed it up, you can remove the loop writeln, though it doesn't look as good when you throw 20 (in my opinion).