diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-03 13:53:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-03 13:53:18 +0100 |
| commit | 5930a7f71733fb6ab474924ae124b68e804b662f (patch) | |
| tree | 06a9738ef297cf77be25a49d84b4e76c5b18e01a | |
| parent | ef27d1fb8841edfcf387bc46911cb0258d300344 (diff) | |
| parent | 2c6ed8e949ab95f7197b4dfff897ace355a3413b (diff) | |
| download | perlweeklychallenge-club-5930a7f71733fb6ab474924ae124b68e804b662f.tar.gz perlweeklychallenge-club-5930a7f71733fb6ab474924ae124b68e804b662f.tar.bz2 perlweeklychallenge-club-5930a7f71733fb6ab474924ae124b68e804b662f.zip | |
Merge pull request #10764 from kjetillll/challenge-285-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-285/
| -rw-r--r-- | challenge-285/kjetillll/perl/ch-1.pl | 9 | ||||
| -rw-r--r-- | challenge-285/kjetillll/perl/ch-2.pl | 14 |
2 files changed, 23 insertions, 0 deletions
diff --git a/challenge-285/kjetillll/perl/ch-1.pl b/challenge-285/kjetillll/perl/ch-1.pl new file mode 100644 index 0000000000..5562883c79 --- /dev/null +++ b/challenge-285/kjetillll/perl/ch-1.pl @@ -0,0 +1,9 @@ +use strict; use warnings; use Test::More tests => 2; + +sub dest { + my %further = map { $$_[0] => 1 } @_; + grep !$further{$_}, map $$_[1], @_; +} + +is_deeply [ dest( ["B","C"], ["D","B"], ["C","A"] ) ] => [ 'A' ]; +is_deeply [ dest( ["A","Z"] ) ] => [ 'Z' ]; diff --git a/challenge-285/kjetillll/perl/ch-2.pl b/challenge-285/kjetillll/perl/ch-2.pl new file mode 100644 index 0000000000..9748e77f92 --- /dev/null +++ b/challenge-285/kjetillll/perl/ch-2.pl @@ -0,0 +1,14 @@ +use strict; use warnings; no warnings 'recursion'; use List::Util 'min'; use Test::More tests => 3; + +sub ways { + my( $amount, @coins ) = @_; + $amount==0 ? \@coins : map ways($amount-$_, @coins, $_), grep $_ <= &min, 1,5,10,25,50 +} +sub waystring {join('',map{{qw(1 P 5 N 10 D 25 Q 50 H)}->{$_}}@_)=~s,(.)\1*,length($&)."$1 ",reg=~s,\b1(\D),$1,gr} + +print '9 --> '.waystring(@$_)."\n" for ways(9); +print '15 --> '.waystring(@$_)."\n" for ways(15); + +is scalar ways(9) => 2; +is scalar ways(15) => 6; +is scalar ways(100) => 292; |
