Find the Winner of the Circular Game
Real-world version: Last Apprentice at the KilnThe statement here is our own: the same inputs, outputs and technique.
A pottery studio seats its trainees in a ring around the kiln. There are apprentices of them, numbered 1 upwards going clockwise, so the highest number sits shoulder to shoulder with number 1.
The tutor thins the ring one trainee at a time. Begin at apprentice 1 and count step seats clockwise, counting the apprentice you begin on as one. Whoever you finish on hands over their tools and leaves the ring. Begin the next count from the apprentice sitting immediately clockwise of the one who just left, count step seats again, and carry on the same way. Once the ring has grown short the counting simply keeps going round it, so the same apprentice can be counted more than once inside a single count. When only one apprentice is still seated, that apprentice keeps the wheel for the rest of the day.
Return the seat number of the apprentice who keeps the wheel.
Examples
Example 1
- Input
- apprentices = 7, step = 3
- Output
- 4
The counts take out apprentices 3, 6, 2, 7, 5 and 1 in that order, and apprentice 4 is the one still seated.
Example 2
- Input
- apprentices = 9, step = 4
- Output
- 1
The counts clear out apprentices 4, 8, 3, 9, 6, 5, 7 and last of all 2, which leaves apprentice 1 seated.
Example 3
- Input
- apprentices = 6, step = 1
- Output
- 6
Each count stops on the apprentice it begins with, so seats 1 through 5 clear out in order and apprentice 6 keeps the wheel.
Constraints
- 1 <= step <= apprentices <= 500
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def last_apprentice_at_the_kiln(apprentices: int, step: int) -> int:public int lastApprenticeAtTheKiln(int apprentices, int step)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 16 test cases: 16 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Find the K-th Character in String Game IReal-world version: Letter at a Position in the Growing TagEasy
- Number of Students Unable to Eat LunchReal-world version: Stranded at the Battery SwapEasy
- Predict the WinnerReal-world version: Bundle Claim DuelMedium
- Sum of GCD of Formed PairsReal-world version: Total Mesh Cycle of the Gear BinMedium