% head_game.m
%  Players alternate in flipping 3 coins. 
%  The first to get three heads wins.
%
toss = 0;

while ( true )  %  ← “Do forever”

  toss = toss + 1;
  i = randi ( [ 1, 8 ] ); 
  if ( i == 1 )
    fprintf ( 'Barbara wins' );
    break;
  end

  toss = toss + 1;
  i = randi ( [ 1, 8 ] );
  if ( i == 1 )
    fprintf ( 'Mary wins' );
    break;
  end

end

fprintf ( ' after %d tosses.\n', toss );

