diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2021-05-10 09:48:22 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2021-05-10 09:48:22 +0200 |
| commit | fcff2c88725e89115ed7d7899235c163e770903a (patch) | |
| tree | 9b69839334e4a6de14cb89b71b25089650d437bf /challenge-112 | |
| parent | 04a34716be5e42d72b8dc2e6498b5a7058e4990b (diff) | |
| download | perlweeklychallenge-club-fcff2c88725e89115ed7d7899235c163e770903a.tar.gz perlweeklychallenge-club-fcff2c88725e89115ed7d7899235c163e770903a.tar.bz2 perlweeklychallenge-club-fcff2c88725e89115ed7d7899235c163e770903a.zip | |
Task 2 done
Diffstat (limited to 'challenge-112')
| -rw-r--r-- | challenge-112/luca-ferrari/raku/ch-2.p6 | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-112/luca-ferrari/raku/ch-2.p6 b/challenge-112/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..e56fad916e --- /dev/null +++ b/challenge-112/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,20 @@ +#!raku + +sub MAIN( Int $top where { $top > 1 } ) { + my @haystack = (1 xx $top, 2 xx $top / 2).flat; + my @solutions; + + # get all possible combinations + for @haystack.permutations { + # check every sub-array that gives me the sum + for 0 ..^ $_.elems -> $index { + @solutions.push: $_[ 0 .. $index ] if $_[ 0 .. $index ].sum == $top; + } + } + + + # print only unique values + say @solutions.unique: as => { .Str }; + +} + |
