Skip to content

Instantly share code, notes, and snippets.

@smartwatermelon
Created July 9, 2021 18:14
Show Gist options
  • Select an option

  • Save smartwatermelon/fee89fbfd63a6b6b01eeb8efd5f55d6b to your computer and use it in GitHub Desktop.

Select an option

Save smartwatermelon/fee89fbfd63a6b6b01eeb8efd5f55d6b to your computer and use it in GitHub Desktop.
@cassidoo's interview question from July 4, 2021
#!/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
STR=$1
QWERTY='qwertyuiop[]\'
WERTYU='wertyuiop[]\'
ASDFGH='asdfghjkl;'
SDFGHJ='sdfghjkl;'
ZXCVBN='zxcvbnm,./'
XCVBNM='xcvbnm,./'
echo $STR | tr $WERTYU $QWERTY | tr $SDFGHJ $ASDFGH | tr $XCVBNM $ZXCVBN
@smartwatermelon
Copy link
Copy Markdown
Author

MONTASIO:~ andrewrich$ ~/Documents/scripts/translateShift.sh ';p; epe'
lol wow
MONTASIO:~ andrewrich$ ~/Documents/scripts/translateShift.sh 'vtsmnrttu'
cranberry

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