(*
* $Id: hash.ocaml,v 1.4 2001/01/08 03:02:47 doug Exp $
* http://www.bagley.org/~doug/shootout/
* with help from Markus Mottl
*)
let hexdigits = [| '0'; '1'; '2'; '3'; '4'; '5'; '6'; '7';
'8'; '9'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; |]
let buf = String.create 32
let rec hexstring_of_int n idx len =
if n <= 0 then String.sub buf idx len
else begin
let new_idx = idx - 1
and new_len = len + 1 in
String.set buf new_idx hexdigits.(n land 15);
hexstring_of_int (n lsr 4) new_idx new_len
end
let _ =
let n =
try int_of_string Sys.argv.(1)
with Invalid_argument _ -> 1 in
let hx = Hashtbl.create n in
for i = 1 to n do
Hashtbl.add hx (hexstring_of_int i 32 0) true
done;
let c = ref 0 in
for i = n downto 1 do
if Hashtbl.mem hx (string_of_int i) then incr c
done;
Printf.printf "%d\n" !c