ocaml: phase 5.1 josephus.ml baseline (n=50 k=3, survivor at position 11)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
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.
This commit is contained in:
@@ -75,6 +75,7 @@
|
||||
"max_product3.ml": 300,
|
||||
"max_run.ml": 5,
|
||||
"mod_inverse.ml": 27,
|
||||
"josephus.ml": 11,
|
||||
"json_pretty.ml": 24,
|
||||
"kadane.ml": 6,
|
||||
"lambda_calc.ml": 7,
|
||||
|
||||
7
lib/ocaml/baseline/josephus.ml
Normal file
7
lib/ocaml/baseline/josephus.ml
Normal file
@@ -0,0 +1,7 @@
|
||||
let rec josephus n k =
|
||||
if n = 1 then 0
|
||||
else (josephus (n - 1) k + k) mod n
|
||||
|
||||
;;
|
||||
|
||||
josephus 50 3 + 1
|
||||
Reference in New Issue
Block a user