diff options
| -rwxr-xr-x | challenge-109/pkmnx/raku/ch-1.raku | 6 | ||||
| -rwxr-xr-x | challenge-109/pkmnx/raku/ch-2.raku | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-109/pkmnx/raku/ch-1.raku b/challenge-109/pkmnx/raku/ch-1.raku new file mode 100755 index 0000000000..4d31c01eed --- /dev/null +++ b/challenge-109/pkmnx/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/usr/bin/env raku + + +my $upr = 20; +my @chwla = (1 .. $upr).map(-> $n { (2..$n -1).grep({ !($n % $_) }).sum() }); +@chwla.say; diff --git a/challenge-109/pkmnx/raku/ch-2.raku b/challenge-109/pkmnx/raku/ch-2.raku new file mode 100755 index 0000000000..f71cf17e84 --- /dev/null +++ b/challenge-109/pkmnx/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/usr/bin/env raku + +# See usage: +# pk@pkx:~/stuff/.../challenge-109/pkmnx/raku$ time ./ch-2.raku 1 2 3 5 4 6 7 +# 3 + 7 == 7 + 2 + 1 == 1 + 5 + 4 == 4 + 6 +# 5 + 6 == 6 + 2 + 3 == 3 + 1 + 7 == 7 + 4 +# 4 + 5 == 5 + 3 + 1 == 1 + 6 + 2 == 2 + 7 +# 4 + 7 == 7 + 1 + 3 == 3 + 2 + 6 == 6 + 5 +# 6 + 4 == 4 + 1 + 5 == 5 + 2 + 3 == 3 + 7 +# 6 + 4 == 4 + 5 + 1 == 1 + 2 + 7 == 7 + 3 +# 7 + 2 == 2 + 6 + 1 == 1 + 3 + 5 == 5 + 4 +# 7 + 3 == 3 + 2 + 5 == 5 + 1 + 4 == 4 + 6 +# +# real 0m0.337s + +sub MAIN( *@N where @N.elems == 7 && @N.all ~~ Numeric ) { + + @N.permutations.grep({ val(|$_) }).map({ disp(|$_) }).join("\n").say; + +} + +sub val ( $a, $b, $c, $d, $e, $f, $g ) { + $a + $b == $b + $c + $d == $d + $e + $f == $f + $g; +} +sub disp ( $a, $b, $c, $d, $e, $f, $g ) { + "$a + $b == $b + $c + $d == $d + $e + $f == $f + $g"; +} |
