$| = 1;

sub tobase {
	my $base = shift;
	my $n = shift;
	my @b = ();

	while ($n) {
		my $d = $n % $base;
		@b = ($d, @b);
		$n -= $d;
		$n /= $base;
	}

	return join("," => @b);
}

my @prev = ();
my %seen = ();

sub keep {
	my $can = shift;

	foreach my $base (@prev) {
		if (exists $seen{ tobase($base, $can) }) {
			return 0;
		}
	}

	return 1;
}

my $next = 1;

sub other {
	while (not keep(++$next)) {
	}

	my @repr = map { tobase($_, $next) } @prev;

	foreach (@repr) {
		$seen{ $_ } = 1;
	}

	# print "$next: ", join(" " => @repr), "\n";

	unshift @prev => $next;

	return $next;
}

foreach my $n (1..10_000) {
	print $n, " ", other(), "\n";
}