aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-05-16 18:18:26 +0100
committerGitHub <noreply@github.com>2020-05-16 18:18:26 +0100
commitd6fb4511e20ea6ff9b047bb2f18d11807050b240 (patch)
tree296743ce8dca613c63d744d2f0696b4133fa4378
parent5cea4808bdaecbaacefc040755d8d799dfd76f9a (diff)
parent9e6c712e010fc50a7842a0798521566bb7251a76 (diff)
downloadperlweeklychallenge-club-d6fb4511e20ea6ff9b047bb2f18d11807050b240.tar.gz
perlweeklychallenge-club-d6fb4511e20ea6ff9b047bb2f18d11807050b240.tar.bz2
perlweeklychallenge-club-d6fb4511e20ea6ff9b047bb2f18d11807050b240.zip
Merge pull request #1717 from manfredi/challenge-060
Solution for Task #1
-rwxr-xr-xchallenge-060/manfredi/bash/ch-1.sh15
-rwxr-xr-xchallenge-060/manfredi/perl/ch-1.pl11
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-060/manfredi/bash/ch-1.sh b/challenge-060/manfredi/bash/ch-1.sh
new file mode 100755
index 0000000000..db68e18e70
--- /dev/null
+++ b/challenge-060/manfredi/bash/ch-1.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+set -e
+
+declare -a cols=($(echo {A..Z} {A..Z}{A..Z} {A..Z}{A..Z}{A..Z}))
+declare -a nums=( $(seq 1 ${#cols[*]}) )
+declare -A hcols=()
+declare -A hnums=()
+
+for ((i = 0; i < ${#cols[*]}; i++)); do
+ hcols+=([${cols[$i]}]=${nums[$i]})
+ hnums+=([${nums[$i]}]=${cols[$i]})
+done
+
+[[ $1 =~ ^[0-9]+$ ]] && echo "${hnums[$1]}"
+[[ $1 =~ ^[A-Z]{1,3}$ ]] && echo "${hcols[$1]}"
diff --git a/challenge-060/manfredi/perl/ch-1.pl b/challenge-060/manfredi/perl/ch-1.pl
new file mode 100755
index 0000000000..1fe51ebc80
--- /dev/null
+++ b/challenge-060/manfredi/perl/ch-1.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use strict;
+my (%cols, @cols, %nums, @nums);
+@cols = ('A'..'ZZZ');
+@cols{1..scalar(@cols)} = @cols;
+@nums = (1..scalar(@cols));
+@nums{@cols} = @nums;
+
+my $in = $ARGV[0];
+print "$cols{$in}\n" if $in =~ /^\d+$/ && $in <= scalar(@nums);
+print "$nums{$in}\n" if $in =~ /^[A-Z]{1,3}$/;