From e6cc157ff0288e298c0984aabf903bc77cf356e6 Mon Sep 17 00:00:00 2001 From: ricmaps Date: Mon, 15 Jun 2026 21:49:19 -0300 Subject: [PATCH] Add Josephus Problem in Elixir --- archive/e/elixir/josephus-problem.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 archive/e/elixir/josephus-problem.ex diff --git a/archive/e/elixir/josephus-problem.ex b/archive/e/elixir/josephus-problem.ex new file mode 100644 index 000000000..2925c6680 --- /dev/null +++ b/archive/e/elixir/josephus-problem.ex @@ -0,0 +1,13 @@ +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