Skip to content

Instantly share code, notes, and snippets.

@smartwatermelon
Created May 10, 2021 22:45
Show Gist options
  • Save smartwatermelon/ef24ad01332426d4c073730071de2ae3 to your computer and use it in GitHub Desktop.
Save smartwatermelon/ef24ad01332426d4c073730071de2ae3 to your computer and use it in GitHub Desktop.
@cassidoo's Interview question of the week for May 10, 2021
#!/usr/bin/env bash
set -eu -o pipefail
if [ $# -eq 0 ] || [ -n "$(printf '%s\n' "$1" | sed 's/[0-9]//g')" ]; then
echo "$(basename $0): enter a positive integer"
exit 1
else
echo "$(basename $0): you entered $1"
fi
BASE=$1
EXPONENT=3
RESULT=$((BASE**EXPONENT))
L_BASE=${#BASE}
L_RESULT=${#RESULT}
if [ "$L_BASE" == "$L_RESULT" ]; then
echo "Yes"
else
echo "Nah"
fi
@smartwatermelon
Copy link
Author

MONTASIO:~ andrewrich$ ~/Documents/scripts/sameDigits.sh 1
sameDigits.sh: you entered 1
Yes
MONTASIO:~ andrewrich$ ~/Documents/scripts/sameDigits.sh 2
sameDigits.sh: you entered 2
Yes
MONTASIO:~ andrewrich$ ~/Documents/scripts/sameDigits.sh 3
sameDigits.sh: you entered 3
Nah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment