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 | |
| isPerfect() { | |
| NUM=$1 | |
| SQRT=$( bc -l <<< "sqrt ($NUM)" ) | |
| INT_SQRT=$( cut -d '.' -f 1 <<< "$SQRT" ) | |
| SQ_INT_SQRT=$( bc -l <<< "$INT_SQRT ^ 2" ) | |
| test $NUM -eq $SQ_INT_SQRT; echo $? | |
| } |
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 | |
| trimArray () { | |
| arrayName=$1[@] | |
| n=$2 | |
| m=$3 | |
| array=("${!arrayName}") | |
| echo -e "begin:\t[${array[@]}], $n, $m" |
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 | |
| removeZeroes () { | |
| IFS=" " read -ra array <<< "$@" | |
| declare -a ltrim=("") | |
| declare -a rtrim=("") | |
| tmp="" | |
| length="${#array[@]}" |
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 | |
| # Define function to convert a number to English words | |
| function num_to_words { | |
| local ones=( '' one two three four five six seven eight nine ) | |
| local tens=( '' '' twenty thirty forty fifty sixty seventy eighty ninety ) | |
| local specials=( ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen ) | |
| local num=$1 |
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 | |
| # initialize vars | |
| allDoors=() # array | |
| # check input | |
| ARGC="$#" | |
| if [[ "$ARGC" -ne 2 ]]; then | |
| echo "Please enter two parameters: number of doors, and number of passes." |
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
| MONTASIO:~ andrewrich$ N=3 | |
| MONTASIO:~ andrewrich$ STR="never gonna give you up" | |
| MONTASIO:~ andrewrich$ for word in $STR; do echo "${word:0:$N}"; done | |
| nev | |
| gon | |
| giv | |
| you | |
| up |
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 | |
| # initialize vars | |
| ordinal='' | |
| # check input | |
| ARGC="$#" | |
| if [[ "$ARGC" -ne 1 ]]; then | |
| echo "Please enter an integer number, e.g. 123" |
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 | |
| # initialize vars | |
| runningTotal="0" | |
| # normalized grade names to point values | |
| A="4" AMINUS="3.7" | |
| BPLUS="3.3" B="3" BMINUS="2.7" | |
| CPLUS="2.3" C="2" CMINUS="1.7" |
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 | |
| # substitute asterisks for all but first and last characters of string | |
| obscureString () { | |
| str="$1" | |
| ret="${str:0:1}$( printf "%0.s*" $( seq 1 $(( ${#str}-2 )) ) )${str: -1}" | |
| echo $ret | |
| } |
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 | |
| # return true if input is a perfect square | |
| isPerfectSquare () { | |
| square_root=$( bc <<< "sqrt ($1)" ) | |
| return $( [ $(( $square_root * $square_root )) == $1 ] ) | |
| } | |