Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Puzzle: What is the largest integer ... (not "a longest")

by Limbic~Region (Chancellor)
on Oct 27, 2005 at 14:14 UTC ( [id://503345]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Puzzle: What is the largest integer ... (not "a longest")
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?

tye,
I borrowed Algorithm::Loops for the following brute-force approach:
#!/usr/bin/perl use strict; use warnings; use Algorithm::Loops qw/NestedLoops NextPermute/; my $max = 1; my $next = GenPowerSet(9); while ( my @list = $next->() ) { PERMUTE: while ( NextPermute(@list) ) { my $num = join '', @list; next PERMUTE if $num < $max; for ( @list ) { next PERMUTE if $num % $_; } $max = $num if $num > $max; } } print $max; sub GenPowerSet { my $end = shift; return NestedLoops( [ [ 1..$end ], ( sub { [ $_+1 .. $end ] } ) x $end, ], { OnlyWhen => 1, }, ); }
It came up with 9_867_312 in about 30 seconds.

Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-16 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found