Created
December 6, 2021 23:12
-
-
Save smartwatermelon/892fd09e8e2a907827edc7ab647ff2ac to your computer and use it in GitHub Desktop.
@cassidoo's interview question from December 5, 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 | |
# You have to order wrapping paper for presents. Given the length, width, and height of | |
# the boxes you need to wrap, return the number of square feet (or whatever units you | |
# want) of wrapping paper you need to order. Extra credit: allow for other shapes of | |
# presents and their dimensions! | |
if [ $# -ne 3 ]; then | |
echo "$(basename $0): enter three nonzero positive integers (length, width, depth)" | |
exit 1 | |
fi | |
for arg in "$@"; do | |
if ! [[ $arg =~ ^[1-9]+$ ]]; then | |
echo "$(basename $0): not a nonzero positive integer: $arg" | |
exit 1 | |
fi | |
done | |
SURFACE=$(( ( 2 * $1 * $2 ) + ( 2 * $1 * $3 ) + ( 2 * $2 * $3 ) )) | |
echo "You'll need at least $SURFACE square units of wrapping paper" |
Author
smartwatermelon
commented
Oct 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment