Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 24 lines (19 sloc) 0.508 kb
d91a594 @jtpalmer Problem 32, Perl 5.
authored
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use 5.010;
5 use List::Util qw(sum);
6 use Algorithm::Permute;
7
8 my %products;
9
18f0d5d @jtpalmer Perltidy.
authored
10 my $p = Algorithm::Permute->new( [ 1 .. 9 ] );
d91a594 @jtpalmer Problem 32, Perl 5.
authored
11
18f0d5d @jtpalmer Perltidy.
authored
12 while ( my @r = $p->next() ) {
d91a594 @jtpalmer Problem 32, Perl 5.
authored
13 foreach my $a ( 0 .. 6 ) {
18f0d5d @jtpalmer Perltidy.
authored
14 my $x = join( '', @r[ 0 .. $a ] );
d91a594 @jtpalmer Problem 32, Perl 5.
authored
15 foreach my $b ( $a + 1 .. 7 ) {
18f0d5d @jtpalmer Perltidy.
authored
16 my $y = join( '', @r[ $a + 1 .. $b ] );
17 my $z = join( '', @r[ $b + 1 .. 8 ] );
d91a594 @jtpalmer Problem 32, Perl 5.
authored
18 $products{$z} = 1 if $z == $x * $y;
19 }
20 }
21 }
22
23 say sum keys %products;
Something went wrong with that request. Please try again.