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 | |
# Given a positive integer n, write a function that finds the number of zeros | |
# at the end of n! in base 10. | |
if [ $# -eq 0 ] || [ -n "$(printf '%s\n' "$1" | sed 's/[0-9]//g')" ]; then | |
echo "$(basename "$0"): enter a positive integer" | |
exit 1 | |
fi |
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 | |
# Given an IPv4 address and a netmask in CIDR notation, return a boolean | |
# specifying whether the IP address is inside the given range. | |
# requirements: | |
# # bash version >= 4 | |
# # 'grepcidr' command (http://www.pc-tools.net/unix/grepcidr/) |
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 | |
# Imagine your users are all typing slightly incorrectly, in that they shifted their | |
# hands one key to the right. Write a function that translates what they mean to say. | |
if [ $# -ne 1 ]; then | |
echo "$(basename $0): enter a mis-typed string, e.g. ';p; epe'" | |
exit 1 | |
fi |
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 | |
# Given a direction and a number of columns, write a function that outputs | |
# an arrow of asterisks | |
if [ $# -ne 2 ] || | |
! ( ( [ $( echo $1 | tr [':upper:'] [':lower:'] ) == 'left' ] || [ $( echo $1 | tr [':upper:'] [':lower:'] ) == 'right' ] ) && [ -z "$(printf '%s\n' "$2" | sed 's/[0-9]//g')" ] ); then | |
echo "$(basename $0): enter 'left' or 'right' and a positive integer, e.g. 'left 4' or 'right 3'" | |
exit 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 | |
# 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 |
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 ruby | |
=begin | |
This week’s question: | |
Given a list of people with their names and the time slots when they are available in a given week, and a meeting length, return the first meeting time available (if possible). Format the input however you’d like to receive it! | |
=end | |
=begin | |
Andrew Rich [email protected] | |
https://projectinsomnia.com/ | |
=end |
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 | |
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 |
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
#!/bin/bash | |
function htmlValidator () | |
{ | |
if xmllint --noout --nowarning - 2> /dev/null <<< "$1"; then | |
echo "valid"; | |
else | |
echo "not valid"; | |
fi | |
} |
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 | |
# shellcheck source=/Users/andrewrich/etc/functions.sh | |
. "$HOME/etc/functions.sh" | |
readonly R="ROCK" P="PAPER" S="SCISSORS" | |
about () { | |
cat <<EOF | |
$( basename "$0" ) by Andrew Rich <[email protected]> | |
Based on @cassidoo's interview question from https://buttondown.email/cassidoo/archive/be-careful-with-your-words-once-they-are-said/ |
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 | |
about () { | |
cat <<EOF | |
$( basename "$0" ) by Andrew Rich <[email protected]> | |
Based on @cassidoo's interview question from https://tinyletter.com/cassidoo/letters/be-curious-read-widely-try-new-things-what-people-call-intelligence-just-boils-down-to-curiosity-aaron-swartz | |
Definition and table of logic gates: https://whatis.techtarget.com/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR | |
EOF |