#!/usr/bin/env bash
var1=$1
var2=$2
n=0
if [[ "$#" -eq 0 ]] || [[ "$#" -eq 1 ]]
then
echo "Usage: hamming.sh <string1> <string2>"
exit 1
elif [[ $var1 == "" ]] && [[ $var2 == "" ]]
then
echo 0
# 'single letter identical strands'
elif [[ $var1 == $var2 ]] && [[ ${#var1} -eq 1 ]] && [[ ${#var2} -eq 1 ]]
then
echo 0
# 'single letter different strands'
elif [[ $var1 != $var2 ]] && [[ ${#var1} -eq 1 ]] && [[ ${#var2} -eq 1 ]]
then
echo 1
# 'long identical strands'
elif [[ $var1 == $var2 ]]
then
echo 0
# 'disallow first strand longer'
elif [[ ${#var1} -gt ${#var2} ]]
then
echo "strands must be of equal length"
exit 22
# 'disallow second strand longer'
elif [[ ${#var1} -lt ${#var2} ]]
then
echo "strands must be of equal length"
exit 22
elif [[ ${#var1} -eq ${#var2} ]] && [[ ${#var1} -gt 1 ]] && [[ ${#var2} -gt 1 ]] && [[ $var1 != $var2 ]]
then
for ((i=0;i<${#var1};i++))
do
letter1=${var1:$i:1}
letter2=${var2:$i:1}
if [[ $letter1 != "$letter2" ]]
then
((n++))
fi
done
echo $n
fi
#help with Hamming bash script test 12
12 messages · Page 1 of 1 (latest)
Increase your chance of getting help and look like a pro by sharing codeblocks not images. For example, you can type the following. Note, the ``` must be on their own line.
```
for number in range(10):
total += number;
```
Discord will render that as so:
for number in range(10):
total += number;
Click here to learn more about codeblocks: https://exercism.org/docs/community/being-a-good-community-member/writing-support-requests
What is the error message?
TEST FAILURE
(from function assert_output' in file bats-extra.bash, line 394, in test file hamming.bats, line 93) assert_output "1"' failed
-- output differs --
expected : 1
actual : 0
Does that also show what command was run? What the input is?
If not, you can find it in the test file, line 93
hamming.sh 'AAA' 'A?A'
Also, please read the bot message and use codeblocks
What's your code output for those inputs? Do you understand why? What should it output? Do you understand why?
See also, debugging steps: #programming message
Figured it out?
in my understanding my code does not handles wiledcard correctly