N'th: Difference between revisions

64 bytes removed ,  7 years ago
→‎{{header|OCaml}}: Improving code (considering suggestions from Gabriel Scherer)
(→‎{{header|Ocaml}}: corrected Ocaml to OCaml)
(→‎{{header|OCaml}}: Improving code (considering suggestions from Gabriel Scherer))
Line 1,510:
let show_nth n =
let sn = string_of_int n in
| x whenif (n mod 10 = 31) && (n mod 100 <> 1311) ->then sn ^ "rdst"
match n with
|else x whenif (n mod 10 = 12) && (n mod 100 <> 1112) ->then sn ^ "stnd"
|else x whenif (n mod 10 = 23) && (n mod 100 <> 1213) ->then sn ^ "ndrd"
| _ ->else sn ^ "th"
| x when (n mod 10 = 3) && (n mod 100 <> 13) -> sn ^ "rd"
 
| _ -> sn ^ "th"
 
let () =
let f min max =
for i=min to max do
let arr = Array.init (max - min + 1) (fun i -> min + i) in
Array.iter (fun n -> let s = show_nth ni in print_string (s ^ " ")) arr;
print_string (s ^ " ")
done;
print_newline() in
 
List.iter (fun (min,max) -> f min max) [ (0,25); (250,265); (1000,1025) ]
</lang>
Anonymous user