Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Classic Josephus problem solved with the standard recurrence:
let rec josephus n k =
if n = 1 then 0
else (josephus (n - 1) k + k) mod n
josephus 50 3 + 1 = 11
50 people stand in a circle, every 3rd is eliminated; the last
survivor is at position 11 (1-indexed). Tests recursion + mod.
136 baseline programs total.
8 lines
102 B
OCaml
8 lines
102 B
OCaml
let rec josephus n k =
|
|
if n = 1 then 0
|
|
else (josephus (n - 1) k + k) mod n
|
|
|
|
;;
|
|
|
|
josephus 50 3 + 1
|