diff options
| author | carlos157oliveira <carlos157oliveira@gmail.com> | 2023-01-23 23:56:20 -0300 |
|---|---|---|
| committer | carlos157oliveira <carlos157oliveira@gmail.com> | 2023-01-23 23:56:20 -0300 |
| commit | 3a5456c5afa454d44e2c1069c0fb58f001289c73 (patch) | |
| tree | 9487b1fa2372ac21b93ee9d789c531f79361f39e | |
| parent | 27b88f614b9bb53872ef0da19a56087505836db0 (diff) | |
| download | perlweeklychallenge-club-3a5456c5afa454d44e2c1069c0fb58f001289c73.tar.gz perlweeklychallenge-club-3a5456c5afa454d44e2c1069c0fb58f001289c73.tar.bz2 perlweeklychallenge-club-3a5456c5afa454d44e2c1069c0fb58f001289c73.zip | |
solution 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; |
