Solved hamming in Bash
This commit is contained in:
22
bash/hamming/hamming.sh
Normal file
22
bash/hamming/hamming.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "Usage: $0 <string1> <string2>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
array1=$1
|
||||
array2=$2
|
||||
cnt=0
|
||||
for i in $(seq 0 $((${#array1} - 1))); do
|
||||
if [[ "${array1:$i:1}" != "${array2:$i:1}" ]]; then
|
||||
cnt=$((cnt + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#array1} == ${#array2} ]]; then
|
||||
echo $cnt
|
||||
else
|
||||
echo "strands must be of equal length"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user