Created
October 29, 2013 16:28
-
-
Save Martin91/7217981 to your computer and use it in GitHub Desktop.
A ruby implementation for Josephus problem
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
Array.class_eval do | |
def joseph(k, m) | |
people = ((k - 1) + (m - 1)) % length | |
puts delete(self[people]) | |
while(length > 1) do | |
people = (people + (m - 1)) % length | |
puts delete(self[people]) | |
end | |
puts self.first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment