diff options
| author | Abigail <abigail@abigail.be> | 2021-10-18 21:38:38 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-10-18 21:38:38 +0200 |
| commit | b29cb298a8d08a9d47d37b3d1ee7a62cc31a43d3 (patch) | |
| tree | 2f9c3596be71ce8384fa01b015177277c54b2ebd /challenge-135/abigail/bash | |
| parent | afb90dd6756afcd43a86249358fe3a41e3cf1950 (diff) | |
| download | perlweeklychallenge-club-b29cb298a8d08a9d47d37b3d1ee7a62cc31a43d3.tar.gz perlweeklychallenge-club-b29cb298a8d08a9d47d37b3d1ee7a62cc31a43d3.tar.bz2 perlweeklychallenge-club-b29cb298a8d08a9d47d37b3d1ee7a62cc31a43d3.zip | |
Bash solutions for week 135
Diffstat (limited to 'challenge-135/abigail/bash')
| -rw-r--r-- | challenge-135/abigail/bash/ch-1.sh | 27 | ||||
| -rw-r--r-- | challenge-135/abigail/bash/ch-2.sh | 36 |
2 files changed, 63 insertions, 0 deletions
diff --git a/challenge-135/abigail/bash/ch-1.sh b/challenge-135/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..d85a744a0c --- /dev/null +++ b/challenge-135/abigail/bash/ch-1.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +set -f + +while read line +do line=${line/#[-+]/} # Get rid of sign + if [[ $line =~ [^0-9] ]] + then + echo "not an integer" + elif ((${#line} % 2 == 0)) + then + echo "even number of digits" + elif ((${#line} < 3)) + then + echo "too short" + else + echo ${line:$(((${#line} - 3) / 2)):3} + fi +done diff --git a/challenge-135/abigail/bash/ch-2.sh b/challenge-135/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..0d4c43e705 --- /dev/null +++ b/challenge-135/abigail/bash/ch-2.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh < input-file +# + +set -f + +w=(1 3 1 7 3 9 1) + +while read line +do if ((${#line} != 7)) + then echo 0 + elif [[ $line =~ [^0-9BCDFGHJKLMNPQRSTVWXYZ] ]] + then echo 0 + else + ((check = 0)) + for ((i = 0; i < 7; i ++)) + do char=${line:$i:1} + printf -v ord %d "'$char" + if [[ $char =~ [0-9] ]] + then ((value = ord - 48)) + else ((value = ord - 65 + 10)) + fi + ((check += ${w[i]} * value)) + done + if ((check % 10 == 0)) + then echo 1 + else echo 0 + fi + fi +done |
