diff options
| -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 }; + +} + |
