Skip to content

Instantly share code, notes, and snippets.

@karapetyan
Created October 29, 2015 21:26
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 karapetyan/7f548e05476ff904ccb3 to your computer and use it in GitHub Desktop.
Save karapetyan/7f548e05476ff904ccb3 to your computer and use it in GitHub Desktop.
def josephus_survivor(n,k)
circle = (1..n).to_a
index = -1
size = circle.size
until circle.size == 1
if index + k <= size
index += k
circle.delete_at(index)
else
index = k - (size - index)
circle.delete_at(index)
size = circle.size
end
end
end
josephus_survivor(7,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment