This looks like fun, so I've had a go :)
#!/usr/bin/perl -w use strict; my $biggest_number = 987654321; BIGNUMBER: while ($biggest_number) { # Discard all odd numbers (not divisible by 2) if ($biggest_number % 2) { $biggest_number--; next BIGNUMBER; } my @divisors = split //, $biggest_number; # Discard all numbers containing zero if (grep {$_ eq "0"} @divisors) { $biggest_number--; next BIGNUMBE +R; } # Discard all numbers with repeated digits my %seen = (); for (@divisors) { if ($seen{$_}++) { $biggest_number--; next BIGNUMBER; } } # Get this far, give it a try print "Trying $biggest_number..."; DIVISORS: for (@divisors) { if ($biggest_number % $_) { $biggest_number--; print "Failed!\n"; next BIGNUMBER; } } print "Success!!\n"; for (@divisors) { print "$biggest_number / $_ = ", $biggest_number / $_, "\n"; } exit; }
Update:Well, I'd now like to stake my claim as having come up with the slowest solution that gets the correct answer, and here is my evidence:
Trying 9867312...Success!! 9867312 / 9 = 1096368 9867312 / 8 = 1233414 9867312 / 6 = 1644552 9867312 / 7 = 1409616 9867312 / 3 = 3289104 9867312 / 1 = 9867312 9867312 / 2 = 4933656 real 384m53.120s user 382m59.960s sys 0m14.600s
Almost 6.5 hours, I imagine that would have been quite impressive in the late 50's :D

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? by McDarren
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? by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.