Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • #!/usr/bin/env perl

    my @candidate = grep { $_ % 10 } 101 .. 999;
    for my $N ( 7, 9, 11 ) {
        print join( ', ',
            grep { $_ % $N == 0 && reverse( $_ ) % $N == 0 } @candidate ),
    That's my interpretation of the spec - but that's a hell of a lot more than six numbers as you say. Is that what you get?
    • Nope, not even close :) That tiny spec bears close rereading. For example, "using each of the digits 1 to 9" for 3-digit numbers means your first grep is off.

      my @candidates = grep { !/0/ } 111 ... 999;

      I also used &List::MoreUtils::uniq to pre-trim that list (since duplicate numbers are not allowed).

      Basically, you'll need a three stage process (I think). First, generate your candidate list. Second, find all three digit numbers which satisfy the reverse divisor requirement. Then construct your

    • First, you need a "grep { $_ !~ /0/ }" in there. Second, I think that your three numbers, concatenated, must use each of the digits only once all together. That is, a valid answer would be qw(123 456 789) if only those numbers divided properly. qw(123 331 882) is no good.
      • That appears to be correct. You have to read the spec carefully. They ask you to use each of those numbers, not any. I got that wrong the first time.