diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2021-04-21 18:20:10 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2021-04-21 18:20:10 +0200 |
| commit | 9b844027cb11bf15f01c897e5d45b44b2387fb8e (patch) | |
| tree | c0fe250e12439e1d5dca27e214f298c0d9cacdd4 | |
| parent | 342181744b067fd36499de15529b2f87443db79f (diff) | |
| download | perlweeklychallenge-club-9b844027cb11bf15f01c897e5d45b44b2387fb8e.tar.gz perlweeklychallenge-club-9b844027cb11bf15f01c897e5d45b44b2387fb8e.tar.bz2 perlweeklychallenge-club-9b844027cb11bf15f01c897e5d45b44b2387fb8e.zip | |
Command line checks
| -rw-r--r-- | challenge-109/luca-ferrari/raku/ch-2.p6 | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/challenge-109/luca-ferrari/raku/ch-2.p6 b/challenge-109/luca-ferrari/raku/ch-2.p6 index 1213d407ca..15cc86739b 100644 --- a/challenge-109/luca-ferrari/raku/ch-2.p6 +++ b/challenge-109/luca-ferrari/raku/ch-2.p6 @@ -1,25 +1,25 @@ #!raku -sub MAIN() { - my @nums = <1 2 3 4 5 6 7>; +sub MAIN( *@nums where { @nums.grep( * ~~ Int ).elems == @nums.elems && @nums.elems == 7 } ) { my @letters = <a b c d e f g>; - - my @solutions; + # permutate all numbers to find out the correct sum for @nums.permutations -> @current { + # build an hash to help visualize the answer my %squares; %squares{ @letters[ $_ ] } = @current[ $_ ] for 0 ..^ @letters.elems; - + # compute the sums my @sums; - @sums.push: [+] %squares<a b>; @sums.push: [+] %squares<b c d>; @sums.push: [+] %squares<d e f>; @sums.push: [+] %squares<f g>; + + # if the first sum is equal to all the others, push this solution @solutions.push: %squares if @sums[ 0 ] == all @sums; } |
