let is_pal n =
  let s = string_of_int n in
  let len = String.length s in
  let p = ref true in
  for i = 0 to len / 2 - 1 do
    if s.[i] <> s.[len - 1 - i] then p := false
  done;
  !p

let euler4 lo hi =
  let m = ref 0 in
  for a = lo to hi do
    for b = a to hi do
      let p = a * b in
      if p > !m && is_pal p then m := p
    done
  done;
  !m
;;

euler4 10 99
