Scanf.scanf "%s" (fun s -> let n = String.length s in let rec loop i x y = if i = n then sqrt (float (x * x + y * y)) else match s.[i] with | 'N' -> loop (i + 1) x (y + 1) | 'S' -> loop (i + 1) x (y - 1) | 'E' -> loop (i + 1) (x + 1) y | 'W' -> loop (i + 1) (x - 1) y | _ -> failwith "??" in loop 0 0 0 |> Printf.printf "%f\n" )