let nb_distinct array = let result = ref 1 in (*1 since we count only the pair of different consecutive elements*) for i=0 to Array.length array -2 do if array.(i) <> array.(succ i) then incr result; done; !result