let luhn s =
  let n = String.length s in
  let total = ref 0 in
  for i = 0 to n - 1 do
    let d = Char.code s.[n - 1 - i] - Char.code '0' in
    let v = if i mod 2 = 1 then
      let dd = d * 2 in
      if dd > 9 then dd - 9 else dd
    else d
    in
    total := !total + v
  done;
  !total mod 10 = 0

;;

(if luhn "79927398713" then 1 else 0)
+ (if luhn "79927398710" then 1 else 0)
+ (if luhn "4532015112830366" then 1 else 0)
+ (if luhn "1234567890123456" then 1 else 0)
