Skip to content

Instantly share code, notes, and snippets.

@Martin91
Created October 29, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Martin91/7217981 to your computer and use it in GitHub Desktop.
Save Martin91/7217981 to your computer and use it in GitHub Desktop.
A ruby implementation for Josephus problem
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