A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Josephus Problem in Elixir page! Here, you'll find the source code for this program as well as a description of how the program works.
defmodule Josephus do
@spec josephus(n :: integer(), k :: integer()) :: integer()
def josephus(1, _), do: 1
def josephus(n, k), do: Integer.mod(josephus(n - 1, k) + k - 1, n) + 1
end
with [n, k] <- System.argv(),
{n, ""} <- Integer.parse(n),
{k, ""} <- Integer.parse(k) do
Josephus.josephus(n, k) |> IO.puts()
else
_ -> IO.puts("Usage: please input the total number of people and number of people to skip.")
end
Josephus Problem in Elixir 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.