aboutsummaryrefslogtreecommitdiff
path: root/challenge-107
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-04-09 11:18:08 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-04-09 11:18:08 +0100
commitdcc2242e6286072829e36e2bb625815d4d3cb9a4 (patch)
tree0f45497e09b2ee429aa9da82f6537b5c4804a6b3 /challenge-107
parent0d8b50097baa85c6c081e192a55c62b218d8268e (diff)
downloadperlweeklychallenge-club-dcc2242e6286072829e36e2bb625815d4d3cb9a4.tar.gz
perlweeklychallenge-club-dcc2242e6286072829e36e2bb625815d4d3cb9a4.tar.bz2
perlweeklychallenge-club-dcc2242e6286072829e36e2bb625815d4d3cb9a4.zip
- Added solutions by Pete Houston.
Diffstat (limited to 'challenge-107')
-rw-r--r--challenge-107/pete-houston/perl/ch-1.pl38
-rw-r--r--challenge-107/pete-houston/perl/ch-2.pl33
2 files changed, 71 insertions, 0 deletions
diff --git a/challenge-107/pete-houston/perl/ch-1.pl b/challenge-107/pete-houston/perl/ch-1.pl
new file mode 100644
index 0000000000..d10e4a68b8
--- /dev/null
+++ b/challenge-107/pete-houston/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 10701.pl
+#
+# USAGE: ./10701.pl
+#
+# DESCRIPTION: Outputs the first 3 self-descriptive numbers
+#
+# REQUIREMENTS: Perl 5.10, List::Util
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 06/04/21
+#===============================================================================
+
+use strict;
+use warnings;
+use 5.010;
+use List::Util 'sum';
+
+my $x = 0;
+my @sdn;
+my %cinit = map { $_ => 0 } 0 .. 9;
+
+OUTER: while ($#sdn < 2) {
+ $x++;
+ my @digits = split //, $x;
+ next unless @digits == sum (@digits);
+ my %count = %cinit;
+ $count{$_}++ for @digits;
+ for my $i (0 .. $#digits) {
+ next OUTER unless $count{$i} == $digits[$i];
+ }
+ push @sdn, $x;
+}
+
+print join (', ', @sdn), "\n";
diff --git a/challenge-107/pete-houston/perl/ch-2.pl b/challenge-107/pete-houston/perl/ch-2.pl
new file mode 100644
index 0000000000..a1c7fb240f
--- /dev/null
+++ b/challenge-107/pete-houston/perl/ch-2.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 10702.pl
+#
+# USAGE: ./10702.pl Foo.pm
+#
+# DESCRIPTION: List the names of subs in the source
+#
+# REQUIREMENTS: PPI
+# NOTES: The task talks about methods but then just provides
+# empty subs in the sample module. I have therefore assumed
+# that the real requirement is to list all the subs and
+# not just methods as there seems no way to distinguish
+# between them anyway.
+#
+# The task also shows BEGIN in its output which is
+# neither a sub nor a method so I've simply assumed that
+# is a mistake.
+#
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 06/04/21
+#===============================================================================
+
+use strict;
+use warnings;
+use PPI;
+
+my $doc = PPI::Document->new (shift);
+my $subs = $doc->find ('PPI::Statement::Sub');
+print $_->name . "\n" for @$subs;