Skip to content

Commit b045076

Browse files
authored
Merge pull request #7461 from wlmb/challenges
Solve PWC 201
2 parents aca83f1 + e3c33b4 commit b045076

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

challenge-201/wlmb/blog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://wlmb.github.io/2023/01/23/PWC201/
2+

challenge-201/wlmb/perl/ch-1.pl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env perl
2+
# Perl weekly challenge 201
3+
# Task 1: Missing Numbers
4+
#
5+
# See https://wlmb.github.io/2023/01/23/PWC201/#task-1-missing-numbers
6+
use v5.36;
7+
my %seen;
8+
die <<~ "FIN" unless @ARGV;
9+
Usage: $0 N1 [N2...]
10+
to find the missing numbers from the sequence N1 N2...
11+
FIN
12+
@seen{@ARGV}=(1)x@ARGV;
13+
die "Expected unique values" unless 0+@ARGV==0+keys %seen;
14+
say join " ", @ARGV, "->", grep {!$seen{$_}} 0..@ARGV;

challenge-201/wlmb/perl/ch-2.pl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env perl
2+
# Perl weekly challenge 201
3+
# Task 2: Penny Piles
4+
#
5+
# See https://wlmb.github.io/2023/01/23/PWC201/#task-2-penny-piles
6+
use v5.36;
7+
use List::Util qw(min sum);
8+
use Memoize;
9+
memoize "rows";
10+
die <<~"FIN" unless @ARGV;
11+
Usage: $0 N1 [N2...]
12+
to obtain the number of ascending rows of piles of Ni coins.
13+
FIN
14+
say "$_->", rows($_, $_) for @ARGV;
15+
sub rows($coins,$max){
16+
return 1 if $coins==0;
17+
return sum map{rows($coins-$_,min($_, $coins-$_))} 1..min($coins, $max)
18+
}

0 commit comments

Comments
 (0)