A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Josephus Problem in Ruby page! Here, you'll find the source code for this program as well as a description of how the program works.
def josephus(n, k)
(1..n).reduce(0) { |acc, i| (acc + k) % i } + 1
end
def usage!
abort("Usage: please input the total number of people and number of people to skip.")
end
n, k = ARGV
usage! unless n && k
usage! unless n.match?(/\A\d+\z/) && k.match?(/\A\d+\z/)
n = n.to_i
k = k.to_i
puts josephus(n, k)
Josephus Problem in Ruby was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.