Created
June 7, 2021 16:55
-
-
Save smartwatermelon/8bf601290192ebd1338c6cb1f1f9bc0b to your computer and use it in GitHub Desktop.
@cassidoo's Interview question of the week for June 6, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
# lonelyNumber.sh | |
# @cassidoo 2021-06-06 | |
# Given three numbers, return their product. But, if one of the numbers is the same as | |
# another, it does not count: If two numbers are similar, return the lonely number. If all | |
# numbers are same, return 1. | |
if [ $# -ne 3 ] || ! ([[ $1 =~ ^[0-9]+$ ]] && [[ $2 =~ ^[0-9]+$ ]] && [[ $3 =~ ^[0-9]+$ ]]); then | |
echo "$(basename $0): enter three postive integers" | |
exit 1 | |
fi | |
PRODUCT=$(($1*$2*$3)) | |
if [ $(($1**3)) -eq $PRODUCT ]; then | |
echo 1 | |
elif [ $1 -eq $2 ]; then | |
echo $3 | |
elif [ $1 -eq $3 ]; then | |
echo $2 | |
elif [ $2 -eq $3 ]; then | |
echo $1 | |
else | |
echo $PRODUCT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment