last = [0] \\ m -> index of last occurence of m gaps = [0] \\ m -> mask of gaps between consecutive m's w = 0 \\ number of distinct values so far other(n) = { for (v=1, w, if (!bittest(gaps[v], n-last[v]), gaps[v] += 2^(n-last[v]); last[v] = n; return (v); ); ); if (w++>#last, last = concat(last, vector(#last)); gaps = concat(gaps, vector(#gaps)); ); last[w] = n; return (w); } { for (n=1, 10 000, print (n " " other(n)); ); } quit