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 palindrome_sum lo hi =
  let total = ref 0 in
  for n = lo to hi do
    if is_pal n then total := !total + n
  done;
  !total

;;

palindrome_sum 100 999
