aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-07-21 18:33:33 +0100
committerGitHub <noreply@github.com>2019-07-21 18:33:33 +0100
commit25772b222772d08a2559d28d1a7def69bbe32848 (patch)
tree1a5afc8a83596094ed2fd1d6be1dd30f6098fd26
parent194e1264db47a2decf5433797de8afb34a5a83e2 (diff)
parent9cf6ddc393a17d1799721a289433d01533f46908 (diff)
downloadperlweeklychallenge-club-25772b222772d08a2559d28d1a7def69bbe32848.tar.gz
perlweeklychallenge-club-25772b222772d08a2559d28d1a7def69bbe32848.tar.bz2
perlweeklychallenge-club-25772b222772d08a2559d28d1a7def69bbe32848.zip
Merge pull request #404 from kianmeng/master
Add T1 and T2 for challenge 017
-rw-r--r--challenge-017/kian-meng-ang/perl5/ch-1.pl36
-rw-r--r--challenge-017/kian-meng-ang/perl5/ch-2.pl29
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-017/kian-meng-ang/perl5/ch-1.pl b/challenge-017/kian-meng-ang/perl5/ch-1.pl
new file mode 100644
index 0000000000..499c995fff
--- /dev/null
+++ b/challenge-017/kian-meng-ang/perl5/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+# vi:et:sw=4 ts=4 ft=perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw(say signatures state);
+no warnings qw(experimental recursion);
+
+use Carp;
+use Memoize;
+use Test::More;
+
+memoize('A');
+sub A($m, $n) {
+ croak 'Invalid integer $m and $n' if ($m < 0 or $n < 0);
+ croak 'Exceed calculation range' if ($m >= 4 && $n >= 2);
+
+ return $n + 1 if ($m == 0);
+ return A($m - 1, 1) if ($m > 0 && $n == 0);
+ return A($m - 1, A($m, $n - 1)) if ($m > 0 && $n > 0);
+}
+
+is A(0, 0), 1, 'A(0, 0) equal 1';
+is A(1, 2), 4, 'A(1, 2) equal 4';
+is A(4, 1), 65533, 'A(4, 1) equal 65533';
+done_testing;
+
+1;
+
+__END__
+$ perl ch-1.pl
+ok 1 - A(0, 0) equal 1
+ok 2 - A(1, 2) equal 4
+ok 3 - A(4, 1) equal 65533
+1..3
diff --git a/challenge-017/kian-meng-ang/perl5/ch-2.pl b/challenge-017/kian-meng-ang/perl5/ch-2.pl
new file mode 100644
index 0000000000..a353e5a563
--- /dev/null
+++ b/challenge-017/kian-meng-ang/perl5/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+# vi:et:sw=4 ts=4 ft=perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw(say);
+use URI::Fast qw(uri);
+
+my $uri = uri q|jdbc://user:password@localhost:3306/pwc?profile=true#h1|;
+say 'scheme', ':', $uri->scheme;
+say 'userinfo', ':', $uri->usr, ':', $uri->pwd;
+say 'host', ':', $uri->host;
+say 'port', ':', $uri->port;
+say 'path', ':', $uri->path;
+say 'query', ':', scalar $uri->query;
+say 'fragment', ':', $uri->frag;
+
+1;
+
+__END__
+$ perl ch-2.pl
+scheme:jdbc
+userinfo:user:password
+host:localhost
+port:3306
+path:pwc
+query:profile=true
+fragment:h1