Solved hamming in Bash

This commit is contained in:
2023-04-20 21:25:55 +02:00
parent 8a54eb45e8
commit 76c2f81d48
7 changed files with 947 additions and 0 deletions

22
bash/hamming/hamming.sh Normal file
View 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