diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-01-29 10:38:59 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-29 10:38:59 +0000 |
| commit | eb45d622a5daaaa3a22fdff34a913dcd8f6eca85 (patch) | |
| tree | 057249913078c6f45e4706fb9e12212e1f410208 /challenge-201 | |
| parent | b0450769b36e4aba74d4097e441e2380428fa7b6 (diff) | |
| parent | 3a5456c5afa454d44e2c1069c0fb58f001289c73 (diff) | |
| download | perlweeklychallenge-club-eb45d622a5daaaa3a22fdff34a913dcd8f6eca85.tar.gz perlweeklychallenge-club-eb45d622a5daaaa3a22fdff34a913dcd8f6eca85.tar.bz2 perlweeklychallenge-club-eb45d622a5daaaa3a22fdff34a913dcd8f6eca85.zip | |
Merge pull request #7462 from carlos157oliveira/challenge-201
solution to challenge 201
Diffstat (limited to 'challenge-201')
| -rw-r--r-- | challenge-201/carlos-oliveira/raku/ch-1.raku | 9 | ||||
| -rw-r--r-- | challenge-201/carlos-oliveira/raku/ch-2.raku | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-201/carlos-oliveira/raku/ch-1.raku b/challenge-201/carlos-oliveira/raku/ch-1.raku new file mode 100644 index 0000000000..6986edd5f8 --- /dev/null +++ b/challenge-201/carlos-oliveira/raku/ch-1.raku @@ -0,0 +1,9 @@ +use Test; + +sub missing-numbers (Int:D @numbers --> Set:D[Int:D]) { + return ((0..@numbers) (-) @numbers); +} + +is-deeply missing-numbers(my Int @ = 0,1,3), Set.new(2); +is-deeply missing-numbers(my Int @ = 0,1), Set.new(2); +is-deeply missing-numbers(my Int @ = 0,5,5,4,5), Set.new(1,2,3); diff --git a/challenge-201/carlos-oliveira/raku/ch-2.raku b/challenge-201/carlos-oliveira/raku/ch-2.raku new file mode 100644 index 0000000000..34946c4eeb --- /dev/null +++ b/challenge-201/carlos-oliveira/raku/ch-2.raku @@ -0,0 +1,17 @@ +sub pile-pennies (UInt:D $n) { + # repeat elements to treat the problem as a combination with repetition + my @elements-with-repetition = (1..$n).map({ $_ xx $n }).flat; + + for @elements-with-repetition + .combinations(1..$n) + .grep(*.sum == $n) + .unique(:with(&infix:<eqv>)) + .reverse -> @row + { + say @row.join: ' '; + } +} + +pile-pennies 5; +print "\n"; +pile-pennies 6; |
