Slot Machines
InterviewTime limit1sMemory limit128 MB
Simulate a gambler who cycles through three slot machines with fixed payout periods and stops when she runs out of quarters, and report the total number of plays.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Math
- Solved
- No attempts yet
Problem
Martha takes a jar of quarters to the casino, intending to get rich. She plays three machines in turn — machine , then , then , then back to , and so on. Unknown to her, the machines are entirely predictable. Each play costs one quarter.
- Machine pays quarters on every time it is played.
- Machine pays quarters on every time it is played.
- Machine pays quarters on every time it is played.
Whenever a machine pays out, its play counter resets to . Martha keeps playing as long as she has at least one quarter, and goes broke when the jar is empty.
Input
The input consists of four integers separated by spaces or newlines.
- The first integer is the number of quarters in Martha's jar ().
- The next three integers are how many times machine , machine , and machine have each been played since they last paid out.
Output
Print a single line with the total number of times Martha plays before going broke:
Martha plays N times before going broke.
where is the total number of plays.