Fast test for consecutive integer set using Gauss summation rule
I needed to test whether a set of integers, T, formed a consecutive series including all integers from min(T) to max(T). This can be achieved by sorting T into ascending order and, for each index i, checking whether T[i] is one larger than its predecessor, T[i-1]: public static boolean cons_sort(List<Integer> T) { Collections.sort(T); for (int … Continue reading Fast test for consecutive integer set using Gauss summation rule
Copy and paste this URL into your WordPress site to embed
Copy and paste this code into your site to embed