diff options
| author | Leo Manfredi <manfredi@cpan.org> | 2020-05-16 18:52:19 +0200 |
|---|---|---|
| committer | Leo Manfredi <manfredi@cpan.org> | 2020-05-16 18:52:19 +0200 |
| commit | 9e6c712e010fc50a7842a0798521566bb7251a76 (patch) | |
| tree | 5a62e6982e8bb46036f68922060dd13450db0f44 | |
| parent | e2d97eb5f4eb7f99c8ab07f6b2071bd2e4017800 (diff) | |
| download | perlweeklychallenge-club-9e6c712e010fc50a7842a0798521566bb7251a76.tar.gz perlweeklychallenge-club-9e6c712e010fc50a7842a0798521566bb7251a76.tar.bz2 perlweeklychallenge-club-9e6c712e010fc50a7842a0798521566bb7251a76.zip | |
Solution for Task #1
| -rw-r--r-- | challenge-060/manfredi/README | 1 | ||||
| -rwxr-xr-x | challenge-060/manfredi/bash/ch-1.sh | 15 | ||||
| -rwxr-xr-x | challenge-060/manfredi/perl/ch-1.pl | 11 |
3 files changed, 27 insertions, 0 deletions
diff --git a/challenge-060/manfredi/README b/challenge-060/manfredi/README new file mode 100644 index 0000000000..dfb0471044 --- /dev/null +++ b/challenge-060/manfredi/README @@ -0,0 +1 @@ +Solution by Leo Manfredi 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}$/; |
