$| = 1; my $champ = ""; my $unseen = 2; sub a { my $n = shift; my $bin = sprintf("%b", $n); while (1) { my $pos = index($champ, $bin); if ($pos >= 0) { return $pos; } else { $champ .= substr(sprintf("%b", $unseen), 1); $unseen++; } } } foreach my $n (0..2**14) { my $a = a($n); print "$n $a\n"; }