diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2020-06-29 20:22:32 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2020-06-29 20:22:32 +0000 |
| commit | 8a34e9707c062ed6efe230e4c2a398e4fa3573da (patch) | |
| tree | 73d5399b24d9ea087d4212ba29cd61e29d303a7d /challenge-067/perlboy1967 | |
| parent | 0255154e054c650aa6baa34a887083d583c07dfa (diff) | |
| download | perlweeklychallenge-club-8a34e9707c062ed6efe230e4c2a398e4fa3573da.tar.gz perlweeklychallenge-club-8a34e9707c062ed6efe230e4c2a398e4fa3573da.tar.bz2 perlweeklychallenge-club-8a34e9707c062ed6efe230e4c2a398e4fa3573da.zip | |
Task 1 & 2
Diffstat (limited to 'challenge-067/perlboy1967')
| -rwxr-xr-x | challenge-067/perlboy1967/perl/ch-1.pl | 34 | ||||
| -rwxr-xr-x | challenge-067/perlboy1967/perl/ch-2.pl | 36 |
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-067/perlboy1967/perl/ch-1.pl b/challenge-067/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..ed2a7e57ad --- /dev/null +++ b/challenge-067/perlboy1967/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 067 +# +# Task 1 - Number combinations +# +# Author: Niels 'PerlBoy' van Dijke +# +# Comments: Fun with 'glob()' #1 (Not scalable though ;-) ) + +use strict; +use warnings; + +use List::MoreUtils qw(uniq); + +my ($m, $n); + +if (scalar @ARGV >=2) { + ($m, $n) = @ARGV; +} else { + ($m, $n) = (5, 2); +} + +die "M must be bigger or equal to N (M=$m, N=$n)" + unless ($m >= $n); + +my @list = grep { + my @d = split(/,/); + join('',@d) eq join('',uniq sort @d) +} glob('{'.join('},{', (join(',', 1 .. $m)) x $n).'}'); + +printf "Input: m = %d, n = %d\n", $m, $n; +printf "Output: [ [%s] ]\n", join("], [", @list); + diff --git a/challenge-067/perlboy1967/perl/ch-2.pl b/challenge-067/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..6167198d0b --- /dev/null +++ b/challenge-067/perlboy1967/perl/ch-2.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 067 +# +# Task 2 - Letter Phone +# +# Author: Niels 'PerlBoy' van Dijke +# +# Comments: Fun with 'glob()' #2 (Not scalable though ;-) ) + +use strict; +use warnings; + +my %keypad = ( + 1 => ['_', ',', '@'], + 2 => [qw(a b c)], + 3 => [qw(d e f)], + 4 => [qw(g h i)], + 5 => [qw(j k l)], + 6 => [qw(m n o)], + 7 => [qw(p q r s)], + 8 => [qw(t u v)], + 9 => [qw(w x y z)], +); + +my $s; + +$s = $ARGV[0] // 35; + +die "digits '1' .. '9' only please" + unless $s =~ m#^[1-9]+$#; + +my @list = glob('{'.join('}{', map {join(',', @{$keypad{$_}}) } split(//, $s)).'}'); + +printf qq{Input: s = '%d'\n}, $s; +printf qq{Output: ["%s"]\n"}, join('", "', @list); |
