Skip to content

Instantly share code, notes, and snippets.

@florida
Created February 27, 2014 00:51
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 florida/9242048 to your computer and use it in GitHub Desktop.
Save florida/9242048 to your computer and use it in GitHub Desktop.
My Solution to the Josephus Problem.
def last_man_standing(total)
total_in_circle = *1..total
until total_in_circle.size == 1
for i in (1..((total_in_circle.size.to_f / 2)).ceil)
if total_in_circle[i] == total_in_circle[total_in_circle.size - 2]
total_in_circle.delete_at i
total_in_circle.delete_at(0)
else
total_in_circle.delete_at i
end
end
end
puts total_in_circle[0]
end
(1..1000).each do |x|
last_man_standing x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment