# 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"; }