Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[euler/prob029] add more 6ish versions
  • Loading branch information
gerdr committed Oct 25, 2012
1 parent 3705102 commit b3ea22a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions euler/prob029-gerdr-idiomatic.pl
@@ -0,0 +1,4 @@
use v6;

constant N = 100;
say +(2..N X=> 2..N).classify({ .key ** .value });
38 changes: 38 additions & 0 deletions euler/prob029-gerdr.pl
@@ -0,0 +1,38 @@
use v6;

# same algorithm as polettix' solution

# range of bases
constant A = 2..100;

# range of exponents
constant B = 2..100;

my %seen-bases;
my $seen-values = [+] gather {

# visit bases which are powers of preceeding ones
for A[0] .. sqrt(A[*-1]).Int -> \root {
next if %seen-bases{root};

my %seen-exponents;
my @powers = root, * * root ...^ * > A[*-1];

for @powers Z 1..* -> \base, \exp {
next if %seen-bases{base};

# mark powers of \base according to their exponent
# relative to \root
%seen-exponents{B.map(* * exp)} = True...*;

# avoid double-counting
%seen-bases{base} = True;
}

take +%seen-exponents;
}

}

# without duplicates, the result would be A * B
say (A - %seen-bases) * B + $seen-values;

0 comments on commit b3ea22a

Please sign in to comment.