\\ A065361		Rebase n from 3 to 2. Replace 3^k with 2^k in ternary expansion of n.
A065361(n) = fromdigits(digits(n, 3), 2)

{
	nb = vector(2^9);	\\ 0 based

	for (k = 0, 3^valuation(#nb, 2),
		v = A065361(k);
		if (1+v <= #nb,
			nb[1+v]++;
		);
	);

	vv = vector(#nb, k, vector(nb[k]));
	ii = vector(#nb);

	for (k = 0, 3^valuation(#nb, 2),
		v = A065361(k);
		if (1+v <= #nb,
			vv[1+v][ii[1+v]++] = k;
		);
	);

	m = -1;
	for (n=1, #vv,
		apply (v -> print (m++ " " v), vv[n]);
	);
}

quit