Skip to content

Commit eb45d62

Browse files
authored
Merge pull request #7462 from carlos157oliveira/challenge-201
solution to challenge 201
2 parents b045076 + 3a5456c commit eb45d62

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use Test;
2+
3+
sub missing-numbers (Int:D @numbers --> Set:D[Int:D]) {
4+
return ((0..@numbers) (-) @numbers);
5+
}
6+
7+
is-deeply missing-numbers(my Int @ = 0,1,3), Set.new(2);
8+
is-deeply missing-numbers(my Int @ = 0,1), Set.new(2);
9+
is-deeply missing-numbers(my Int @ = 0,5,5,4,5), Set.new(1,2,3);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sub pile-pennies (UInt:D $n) {
2+
# repeat elements to treat the problem as a combination with repetition
3+
my @elements-with-repetition = (1..$n).map({ $_ xx $n }).flat;
4+
5+
for @elements-with-repetition
6+
.combinations(1..$n)
7+
.grep(*.sum == $n)
8+
.unique(:with(&infix:<eqv>))
9+
.reverse -> @row
10+
{
11+
say @row.join: ' ';
12+
}
13+
}
14+
15+
pile-pennies 5;
16+
print "\n";
17+
pile-pennies 6;

0 commit comments

Comments
 (0)