Scanf.scanf "%d" (fun x -> let rec pat = 0 :: 0 :: 1 :: 1 :: 0 :: 1 :: 1 :: pat in let rec loop pos moved = function | [] -> failwith "??" | y :: ys -> let pos = if y = 0 then pos + 2 else pos - 1 in let moved = if y = 0 then moved + 2 else moved + 1 in if pos = x then moved else loop pos moved ys in loop 0 0 pat |> Printf.printf "%d\n" )