s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) ok(p,v) = { my (d=digits(v), t=p%10, w=t%2==0); for (k=1, #d, if (w && d[k]<=t, return (0), w=(t=d[k])%2==0 ); ); return (1); } other(p) = { see(p); for (v=unseen, oo, if (!seen(v), if (!ok(1,v), see(v) ); if (!seen(v) && ok(p,v), return (v); ); ); ); } \\ A377912 Numbers such that every even digit except the last is immediately followed by a strictly larger digit. is(n) = { my (d = digits(n)); for (i = 1, #d-1, if (d[i]%2==0 && d[i] >= d[i+1], return (0); ); ); return (1); } b = [0] c = vector(10 000) u = 1 { for (n = 1, oo, v = if (n==1, 0, other(v)); if (v > b[#b], b = concat(b, select(is, [b[#b]+1..v])); ); w = setsearch(b, v); if (w <= #c, c[w] = n; while (c[u], print (u " " c[u]); if (u++ > #c, break (2); ); ); ); ) } quit