(* Purely functional, tail-recursive style *) let count_func lsides rsides = let rec loop ls rs le re total = let new_tot = ( if ls == 0 || rs == 0 then total + 1 else total ) in if re < rsides - 1 then loop ls rs le ( re + 1 ) new_tot else if le < lsides - 1 then loop ls rs ( le + 1 ) rs new_tot else if rs < rsides - 1 then loop ls ( rs + 1 ) ls ( rs + 1 ) new_tot else if ls < lsides - 1 then loop ( ls + 1 ) 0 ( ls + 1 ) 0 new_tot else new_tot in loop 0 0 0 0 0;; count_func 3 3;;