Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Puzzle: What is the largest integer whose digits are all different (and do not include 0) that is divisible by each of its individual digits?

by QM (Parson)
on Oct 27, 2005 at 20:09 UTC ( [id://503459]=note: print w/replies, xml ) Need Help??


in reply to Re: Puzzle: What is the largest integer whose digits are all different (and do not include 0) that is divisible by each of its individual digits?
in thread Puzzle: What is the largest integer whose digits are all different (and do not include 0) that is divisible by each of its individual digits?

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

  • Comment on Re^2: Puzzle: What is the largest integer whose digits are all different (and do not include 0) that is divisible by each of its individual digits?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://503459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found