aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-067/cheok-yin-fung/perl/ch-2.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-067/cheok-yin-fung/perl/ch-2.pl b/challenge-067/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..04b049ef59
--- /dev/null
+++ b/challenge-067/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+# Usage: ch-2.pl [digit string]
+
+my $INPUT = '35';
+
+$INPUT = $ARGV[0] if $ARGV[0];
+
+my %BOARD = ('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 @input_str = split //, $INPUT;
+
+my @ans = ( "" );
+
+for my $d (@input_str) {
+ my @prev_ans = @ans;
+ @ans = ();
+ for my $s_str (@prev_ans) {
+ for my $ch (@{$BOARD{$d}}) {
+ push @ans, $s_str."\l$ch";
+ }
+ }
+}
+
+print join ", ", @ans;
+print "\n";