Josephus Problem in Elixir

Published on 16 June 2026 (Updated: 16 June 2026)

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.

Current Solution

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.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.