I whipped up a brute force method which might be of interest as a reference.

# Crude but effective hunter. use strict; my %primes = map { $_ => 1 } ( 2,3,5,7 ); for (10234..98765) { my @a = split //; # Digit 1 is 1 less than digit 3. next unless $a[0] == $a[2]-1; # Digit 1 is higher than the sum of digits 4 and 5. next unless $a[0] > $a[3]+$a[4]; my @sorted = sort @a; my $highest = pop @sorted; my $lowest = shift @sorted; # Digit 3 is the highest number. next unless $a[2] == $highest; # Digit 2 is lowest. next unless $a[1] == $lowest; # Digit 5 is between digit 2 and digit 1 and is half of digit 4. my ($low, $high) = sort ($a[0], $a[1]); next unless $a[4] < $high; next unless $a[4] > $low; next unless $a[4] == $a[3]/2; # It has 2 prime digits. my $p_count = 0; foreach (@a) { $p_count++ if $primes{ $_ }; } next unless $p_count == 2; # There are no duplicates. my %uniq = (); foreach (@a) { $uniq{$_} = 1; } next unless scalar( keys %uniq ) == 5; # All tests passed - print number. print @a, "\n"; }

The results produced match those given above - so it must be right....

-- tidiness is the memory loss of environmental mnemonics


In reply to Re: Simple Math Puzzle... by EvdB
in thread Simple Math Puzzle... by Daruma

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.