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?
I'd be very surprised if that is the largest. I'm sure it is among the longest. But I'd bet money that the largest starts with a 9, and I'd bet a lot of money that it doesn't start with a 1. Update: I didn't notice it was only 7 digits until I wrote a short script that showed that there is no 9-digit answer, which surprised me -- but it's too early for clear thinking ATM :). I should have noted that I looked at the code and it doesn't appear to look for the largest answer, just the first answer that it finds (and it doesn't look at the possible answers from largest to smallest).
Update2: And here is the quick hack showing the first block that failed to find any 9-digit answer and then an added block to find the answer. Note that this code searches the potential solutions in order from largest to smallest so it can stop as soon as one answer is found. It isn't particularly fast to run (taking 14 seconds), but it was very fast to write. (:
use Algorithm::Loops qw( NextPermuteNum ); my @digs= (1..9); my @map; @map[1..9]= reverse 1..9; do { my $num= join '', @map[ @digs ]; for( 9, 8, 7, 5, 0 ) { die "$num\n" if ! $_; last if 0 != $num % $_; } } while( NextPermuteNum(@digs) ); my $prev= 0; for my $len ( reverse 1..8 ) { do { my $num= substr( join( '', @map[ @digs ] ), 0, $len ); if( $num != $prev ) { for( $num =~ /./g, 0 ) { die "$num\n" if ! $_; last if 0 != $num % $_; } } $prev= $num; } while( NextPermuteNum(@digs) ); }
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Puzzle: What is the largest integer ... (not "a longest")
by Limbic~Region (Chancellor) on Oct 27, 2005 at 14:14 UTC | |
Re^3: Puzzle: What is the largest integer ... (not "a longest")
by fizbin (Chaplain) on Oct 27, 2005 at 14:59 UTC | |
by tye (Sage) on Oct 27, 2005 at 15:25 UTC | |
Re^3: Puzzle: What is the largest integer ... (not "a longest")
by Skeeve (Parson) on Oct 27, 2005 at 14:02 UTC |