Last active
August 5, 2020 15:46
-
-
Save junminstorage/92ba54521940a2ff9c03b4cf3c23d946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's say we label each person starting with index 0, for N persons, we have | |
0, 1, 2, 3, ...., N-1. | |
Fn(N, K) return the index of the last person, with starting position at 0 | |
Given N persons, after removing the Kth person, then the next starting position will be K%N | |
Fn(N-1, K) return the position of the survivor with starting position at 0 then for starting position of K%N | |
(Fn(N-1, K) + K)%N will return the position of the survivor. | |
so Fn(N, K) = (Fn(N-1, K) + K)%N | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment