This was my take too. Since we start with an even number, and subtract an even number, we don't have to worry about ending in an odd digit. Since we know that all allowed digits will divide any multiple of 504, we don't even test for that.
Here's the code I wrote (somewhat inspired by previous posts):
#!/your/perl/here
use strict;
use warnings;
use Benchmark::Timer;
my $t = Benchmark::Timer->new();
$t->start();
my $c = 7*8*9;
my $x = $c * int(9876321/$c);
my $steps = 0;
while ($x > 0)
{
next if $x =~ /[05]/; # no 0 or 5
next if $x =~ /([1-9]).*\1/; # no repeated digits
last;
}
continue
{
$x -= $c;
$steps++;
}
$t->stop();
print "$x ($steps steps)\n";
print $t->report();
__OUTPUT__
9867312 (17 steps)
1 trial of _default (64us total)
-QM
--
Quantum Mechanics: The dreams stuff is made of