diff options
| author | Philip Hood <hood@panix.com> | 2020-12-01 02:21:57 -0500 |
|---|---|---|
| committer | Philip Hood <hood@panix.com> | 2020-12-01 02:21:57 -0500 |
| commit | d28f919766e5e70e4b420d64d3a803e8645e6007 (patch) | |
| tree | d68cfde23c98a14292722c96e1878c74c004a500 | |
| parent | d3f8a4ffd028c6c532ee4e97a434bcb351364120 (diff) | |
| download | perlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.tar.gz perlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.tar.bz2 perlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.zip | |
challenge #89, nums #1 & 2.
| -rwxr-xr-x | challenge-089/pkmnx/raku/ch-1.raku | 13 | ||||
| -rwxr-xr-x | challenge-089/pkmnx/raku/ch-2.raku | 29 |
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-089/pkmnx/raku/ch-1.raku b/challenge-089/pkmnx/raku/ch-1.raku new file mode 100755 index 0000000000..2880fe34a7 --- /dev/null +++ b/challenge-089/pkmnx/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/env raku + +sub MAIN( Int $N where $N > 1 ) { + + my $v = 0; + my $str = (1..$N).combinations(2).map(->($a,$b){ $v += $a gcd $b; "gcd($a,$b)"}).join(" + "); + + "Input: $N".say; + "Output: $v\n".say; + + $str.say; + +} diff --git a/challenge-089/pkmnx/raku/ch-2.raku b/challenge-089/pkmnx/raku/ch-2.raku new file mode 100755 index 0000000000..c20006f1c9 --- /dev/null +++ b/challenge-089/pkmnx/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +sub MAIN() { + + my $t = 15; + my @all = (1,2,3,4,5,6,7,8,9); + my @workers; + + for @all -> $a { + push @workers, start { + for ( @all (^) ($a) ).keys.grep({ ($a + $_) < $t }) -> $b { + for ( @all (^) ($a,$b) ).keys -> $c { + next if ($a + $b + $c) != $t; + + for ( @all (^) ($a,$b,$c) ).keys.permutations -> ($d,$e,$f,$g,$h,$i) { + if ( $t ==($d +$e +$f) ==($g +$h +$i) ==($a +$d +$g) ==($b +$e +$h) ==($c +$f +$i) ==($a +$e +$i) ==($c +$e +$g) ) { + ( ($a,$b,$c), ($d,$e,$f), ($g,$h,$i) ).join("\n").say; + print "\n"; + } + } + + } + } + } + } + + await(@workers); + +} |
