static double digitalVariation(int[] array) { int n = l(array); if (n == 0) ret 0; // ? - undefined if (n == 1) ret 0; var value = array[0]; int deviations = 0; for (int i = 1; i < n; i++) if (array[i] != value) ++deviations; ret doubleRatio(deviations, n); } static double digitalVariation(Iterable l) { var it = iterator(l); if (!it.hasNext()) ret 0; // ? - undefined int n = 1; var value = it.next(); int deviations = 0; while (it.hasNext()) { ++n; if (!eq(value, it.hasNext())) ++deviations; } ret doubleRatio(deviations, n); }