aboutsummaryrefslogtreecommitdiff
path: root/challenge-105
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-03-28 12:43:05 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-03-28 12:43:05 +0100
commitde95a289221eae06c7d2c6537102b4ed651448c2 (patch)
tree9d4d80b861979df5e0378c824f77de3062ddc651 /challenge-105
parentc60f1380ada9cf3b4f7df6490beec1f508c2cbc8 (diff)
downloadperlweeklychallenge-club-de95a289221eae06c7d2c6537102b4ed651448c2.tar.gz
perlweeklychallenge-club-de95a289221eae06c7d2c6537102b4ed651448c2.tar.bz2
perlweeklychallenge-club-de95a289221eae06c7d2c6537102b4ed651448c2.zip
- Added solutions by Pete Houston.
Diffstat (limited to 'challenge-105')
-rw-r--r--challenge-105/pete-houston/perl/ch-1.pl23
-rw-r--r--challenge-105/pete-houston/perl/ch-2.pl54
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-105/pete-houston/perl/ch-1.pl b/challenge-105/pete-houston/perl/ch-1.pl
new file mode 100644
index 0000000000..8c2ba46837
--- /dev/null
+++ b/challenge-105/pete-houston/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 10501.pl
+#
+# USAGE: ./10501.pl ROOT OPERAND
+#
+# DESCRIPTION: Display the ROOTth root of OPERAND
+#
+# NOTES: This sems trivial. Have I missed something?
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 27/03/21
+#===============================================================================
+
+use strict;
+use warnings;
+
+my ($n, $k) = @ARGV;
+die "Root ($n) must be more than 1\n" unless $n > 1;
+die "Operand ($k) must be positive\n" unless $k > 0;
+print $k ** (1 / $n) . "\n";
diff --git a/challenge-105/pete-houston/perl/ch-2.pl b/challenge-105/pete-houston/perl/ch-2.pl
new file mode 100644
index 0000000000..9ba2698a26
--- /dev/null
+++ b/challenge-105/pete-houston/perl/ch-2.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 10502.pl
+#
+# USAGE: ./10502.pl NAME
+#
+# DESCRIPTION: Output "The Name Game" lyrics based upon the given name.
+#
+# REQUIREMENTS: Text::Unidecode, Encode
+# BUGS: Assumes the encoding of NAME is utf-8
+# Relies on Text::Unidecode
+# Assumes a consonant is anything which is not a vowel
+# NOTES: Tested with Roman and Greek alphabets only. YMMV.
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 22/03/21
+#===============================================================================
+
+use strict;
+use warnings;
+use Encode 'decode';
+use Text::Unidecode;
+
+binmode STDOUT, ':utf8';
+my $n = decode ('UTF-8', shift);
+
+# Prune the leading consonants, if any.
+# Turn all vowels into ASCII equivalents for detection purposes
+# Assume that anything which isn't a vowel is a consonant.
+my ($consonants) = unidecode ($n) =~ /^([^aeiou]*)/i;
+my $trail = lc $n;
+my $s = substr ($trail, 0, length ($consonants), '');
+
+my ($trimlead, $trimrest) = ('' ne $s) ? split //, lc ($s), 2 : ('', '');
+$trimlead = unidecode ($trimlead);
+
+# Closure to handle leading b, f, m special cases.
+sub lead {
+ my $l = shift;
+ return ($trimlead eq $l ? $trimrest : $l) . $trail;
+}
+
+my %h;
+$h{$_} = lead ($_) for qw/b f m/;
+
+print <<EOT;
+$n, $n, bo-$h{b}
+Bonana-fanna fo-$h{f}
+Fee fi mo-$h{m}
+$n!
+
+EOT