% ruin.m
%  For $10 a toss, players H and T toss a coin, playing til bankruptcy.
%
h_cash = 100;
t_cash = 80;
flips = 0;

while ( 10 <= h_cash && 10 <= t_cash )

  flips = flips + 1;
  ht = randi ( [ 0, 1 ] );

  if ( ht == 0 )
    t_cash = t_cash + 10;
    h_cash = h_cash - 10;
  else
    h_cash = h_cash + 10;
    t_cash = t_cash - 10;
  end

end 

if ( h_cash < 10 )
  fprintf ( 'Terry won after %d flips!\n', flips );
else
  fprintf ( 'Haley won after %d flips!\n', flips );
end

