aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-285/kjetillll/perl/ch-1.pl9
-rw-r--r--challenge-285/kjetillll/perl/ch-2.pl14
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;