Skip to content

Commit

Permalink
Adds code by @uzluisf for cached, refs Raku/doc#2514
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Dec 26, 2018
1 parent a9f4f97 commit 291c83b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions aliquot-cached.p6
@@ -0,0 +1,24 @@
#!/usr/bin/env perl6

use v6;

use experimental :cached;

sub aliquot-parts( $number ) is cached {
(^$number).grep: $number %% *;
}

sub infix:<amic>( $m, $n ) {
$m == aliquot-parts($n).sum &&
$n == aliquot-parts($m).sum;
}

# Taken from https://en.wikipedia.org/wiki/Amicable_numbers
my @numbers = [2620, 2924, 5020, 5564, 6232, 6368, 66928, 66992];

say "Aliquot parts of $_ are ", aliquot-parts $_ for @numbers;

for @numbers X @numbers -> @pair {
say "@pair[0] and @pair[1] are ", @pair[0] amic @pair[1]??" "!!"not ", "amicable";
}

0 comments on commit 291c83b

Please sign in to comment.