\\ A301801		a(n) = smallest integer not yet in the sequence with no digits in common
\\				with a(n-1), a(n-2), a(n-3), and a(n-4); a(0)=0, a(1)=1, a(2)=2, a(3)=3.

big = 1 000 000
s = 0
S = Set([])
unseen = 1
seen(v) = if (v < big, bit test(s, v), set search(S, v))
see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++)

other(p) = {
	my (allowed = Set([0..9]));
	for (i=1, #p,
		allowed = setminus(allowed, Set(if (p[i]==0, [0], digits(p[i]))));
	);
	if (#allowed==1,
		\\ repdigit
		for (w=0, oo,
			my (v=fromdigits(vector(w, k, allowed[1])));
			if (!seen(v),
				return (v);
			);
		),
		for (w=0, oo,
			for (j=#allowed^w, 2*#allowed^w-1,
				my (v=fromdigits(apply(d -> allowed[d+1], digits(j, #allowed)[2..-1])));
				if (!seen(v),
					return (v);
				);
			);
		);
	);
}

\\ use p = vector(3) to compute A298482
p = vector(4)
for (n=0, 10 000, v = if (n<=#p-1, n, other(p)); print (n " " v); see(v); p = concat(p[2..#p], v))

quit