let to_counts s =
  let counts = Array.make 256 0 in
  for i = 0 to String.length s - 1 do
    let c = Char.code s.[i] in
    counts.(c) <- counts.(c) + 1
  done;
  counts

let same_counts a b =
  let result = ref true in
  for i = 0 to 255 do
    if a.(i) <> b.(i) then result := false
  done;
  !result

let is_anagram s t = same_counts (to_counts s) (to_counts t)

;;

(if is_anagram "listen" "silent" then 1 else 0) +
(if is_anagram "hello" "world" then 1 else 0) +
(if is_anagram "anagram" "nagaram" then 1 else 0) +
(if is_anagram "abc" "abcd" then 1 else 0)
