Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -o nounset
- set -o noclobber
- set -o errexit
- set -o pipefail
- main() {
- if (( "${#}" != 2)); then
- printf '%s' 'Usage: hamming.sh <string1> <string2>'
- exit 1
- fi
- : 'check two strings that have the same length' && {
- printf '%s\n%s' "${1}" "${2}" |
- awk '{ print length }' |
- uniq |
- (( $(wc -l) != 1)) &&
- {
- printf '%s' 'left and right strands must be of equal length'
- exit 1
- }
- }
- : 'calculate hamming distance' && {
- paste <(printf '%s' "${1}" | fold -w 1) \
- <(printf '%s' "${2}" | fold -w 1) |
- grep -v '\(.\)[[:cntrl:]]\1' |
- wc -l ||
- true # FIXME
- }
- }
- main "$@"
- # vim:set tabstop=3 shiftwidth=3 :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement