Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 Skeeve (Parson)
on Oct 27, 2005 at 13:59 UTC ( [id://503336]=note: print w/replies, xml ) Need Help??


in reply to 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?

My attempt:
#!/usr/bin/perl use strict; use warnings; my @digits= qw(9 8 7 6 5 4 3 2 1); my $max= 0; permut('', @digits); print "Solution: $max\n"; sub permut { my ($s, @digits)= @_; my $i= scalar @digits; DIV: { { no warnings; last DIV if $s<$max; } foreach my $i (split //m,$s) { last DIV if $s % $i; } print "$s\n"; $max=$s; } if ($i) { while ($i--) { my $f= shift @digits; permut($s.$f, @digits); push(@digits, $f); } } }

My solution and the time needed on a 900MHz Power PC G3 with 640MB and lot's of Java running in the background ;-) is:

9867312
real 2m14.144s
user 0m32.100s
sys 0m0.730s


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
  • 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?
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-23 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found