This variant uses an accumulating parameter to return a list of all the suicides in order:
(* return list of suicides in order; last "suicide" is survivor *) let josephus'all n m = let rec j circle acc = if Dllist.length circle = 1 then (Dllist.get circle)::acc else let dead = Dllist.skip circle (m-1) in j (Dllist.drop dead) (Dllist.get dead::acc) in List.rev (j (Dllist.of_list (1--n)) [])
val josephus'all : int -> int -> int list = <fun> # josephus'all 40 3;; - : int list = [3; 6; 9; 12; 15; 18; 21; 24; 27; 30; 33; 36; 39; 2; 7; 11; 16; 20; 25; 29; 34; 38; 4; 10; 17; 23; 31; 37; 5; 14; 26; 35; 8; 22; 40; 19; 1; 32; 13; 28] # josephus'all 41 3;; - : int list = [3; 6; 9; 12; 15; 18; 21; 24; 27; 30; 33; 36; 39; 1; 5; 10; 14; 19; 23; 28; 32; 37; 41; 7; 13; 20; 26; 34; 40; 8; 17; 29; 38; 11; 25; 2; 22; 4; 35; 16; 31] #