/**
 * Class name: Gambler
 * A Java application to simulate a gamlber's ruin.
 *
 * @author Robert Sedgewick
 * @author Kevin Wayne
 * @version 1.1, 09/23/2026, modified by Takunari Miyazaki
 */

public class Gambler {
  public static void main(String[] args) {
    int stake  = Integer.parseInt(args[0]);  // gambler's stating bankroll
    int goal   = Integer.parseInt(args[1]);  // gambler's desired bankroll

    int bets = 0;                            // number of bets made

    // perform one gambler's ruin simulation
    int cash = stake;
    while (cash > 0 && cash < goal) {
      bets++;
      if (Math.random() < 0.5) cash++;       // win $1
      else cash--;                           // lose $1
    }
    if (cash == goal)
      System.out.println("You reached your goal, $" + goal +
			 ", and won after making " + bets + " bets.");
    else
      System.out.println("You lost everything, $" + stake +
			 ", after making " + bets + " bets.");
  }
}
