let bowling_score frames =
  let arr = Array.of_list frames in
  let n = Array.length arr in
  let total = ref 0 in
  let i = ref 0 in
  let frame = ref 1 in
  while !frame <= 10 && !i < n do
    if arr.(!i) = 10 then begin
      total := !total + 10 + arr.(!i + 1) + arr.(!i + 2);
      i := !i + 1
    end else if !i + 1 < n && arr.(!i) + arr.(!i + 1) = 10 then begin
      total := !total + 10 + arr.(!i + 2);
      i := !i + 2
    end else begin
      total := !total + arr.(!i) + arr.(!i + 1);
      i := !i + 2
    end;
    frame := !frame + 1
  done;
  !total

;;

bowling_score [10; 7; 3; 9; 0; 10; 0; 8; 8; 2; 0; 6; 10; 10; 10; 8; 1]
