Skip to content

Instantly share code, notes, and snippets.

@stevenbarragan
Created November 29, 2015 22:47
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 stevenbarragan/93dda38f060a6976f20a to your computer and use it in GitHub Desktop.
Save stevenbarragan/93dda38f060a6976f20a to your computer and use it in GitHub Desktop.
def josephus(input, k)
a = []
i = 0
while items.size > 0
i += k - 1
i = i % items.size
a << items.slice!(i)
end
a
end
p josephus([1,2,3,4,5,6,7,8,9,10],2)
# => [2, 4, 6, 8, 10, 3, 7, 1, 9, 5]
#
p josephus(["C","o","d","e","W","a","r","s"],4)
# => ['e', 's', 'W', 'o', 'C', 'd', 'r', 'a'])
#
p josephus([1,2,3,4,5,6,7], 3)
# => [3, 6, 2, 7, 5, 1, 4]
p josephus([true, false, true, false, true, false, true, false, true], 9)
# => [true, true, true, false, false, true, false, true, false]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment