let rec is_match s i p j =
  if j = String.length p then i = String.length s
  else if p.[j] = '*' then
    is_match s i p (j + 1)
    || (i < String.length s && is_match s (i + 1) p j)
  else
    i < String.length s
    && (p.[j] = '?' || p.[j] = s.[i])
    && is_match s (i + 1) p (j + 1)

let count_match patterns texts =
  let count = ref 0 in
  List.iter (fun p ->
    List.iter (fun t ->
      if is_match t 0 p 0 then count := !count + 1
    ) texts
  ) patterns;
  !count

;;

let patterns = ["a*b"; "?b*c"; "*x*y*"] in
let texts = ["aaab"; "abc"; "abxyz"; "xy"; "xyz"; "axby"] in
count_match patterns texts
