Pathologically Eclectic Rubbish Lister PerlMonks

### 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?

by Zed_Lopez (Chaplain)
 on Oct 28, 2005 at 20:02 UTC ( #503755=note: print w/replies, xml ) Need Help??

Mine is very slow, but short. I wrote it before reading the rest of the thread. I figured that we knew the answer had at most 8 characters, as it couldn't have both 2 and 5, so I counted down from the largest 8-different-digit number, guessing the answer would be closer to the top than the bottom. I realized that checking both 9, 8, 6 and their divisors was a waste, but guessed that the logic to exclude those would outweigh the extra modulos.

```LOOP: for (my \$i = 98765432; \$i > 0; \$i--) {
next if \$i =~ /0/ or \$i =~ /(\d)\d*\1/;
\$i % \$_ and next LOOP for split '', \$i;
print "\$i\n";
exit;
}

Updated: Re-worded the last sentence to correct a word-processing-o.

• Comment on 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?

Replies are listed 'Best First'.
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 tphyahoo (Vicar) on Oct 31, 2005 at 10:16 UTC
This is based on what you did, except it prints out a status bar for "time remaining." Well, actually not a status bar. Just something along the lines of
```On 22000000. Minutes required: 0.718182
On 21000000. Minutes required: 0.683761
On 20000000. Minutes required: 0.645359
On 19000000. Minutes required: 0.611250
........
I think I liked yours the best because it was the closest in spirit to my, even slower, initial attempt. Cheers :)
```use strict;
use warnings;

my \$start = 98765432;

my \$start_time = time;
my \$div = 1000000;
my \$max_tries = ( ( \$start - ( \$start % \$div) ) / \$div );
my \$tries;

LOOP: for (my \$i = \$start; \$i > 0; \$i--) {
if ( \$i % \$div == 0 ) {
\$tries++;
my \$tries_remaining = \$max_tries - \$tries;    #print "tries re
+maining: \$tries_remaining\n";
my \$seconds_per_tries = ( time() - \$start_time ) / \$tries;
my \$estimated_minutes_to_completion = \$seconds_per_tries * \$tr
+ies_remaining / 60;

\$estimated_minutes_to_completion = sprintf ( "%2f", \$estimated
+_minutes_to_completion );

print "On \$i. Minutes required: \$estimated_minutes_to_completi
+on\n";
}
next if \$i =~ /0/ or \$i =~ /(\d)\d*\1/;
\$i % \$_ and next LOOP for split '', \$i;
print "\$i\n";
exit;
}

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://503755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2023-05-31 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?