Skip to content

Instantly share code, notes, and snippets.

@livibetter
Created March 9, 2011 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save livibetter/861587 to your computer and use it in GitHub Desktop.
Save livibetter/861587 to your computer and use it in GitHub Desktop.
6 op1 6 op2 6 = ?
#!/bin/bash
OPs="{++,--,**,*,/,%,+,-,\<\<,\>\>,\&,^,\|}"
eval "echo -ne ${OPs}' '${OPs}'\n'" |
while read op1 op2; do
for eq in "6 $op1 6 $op2 6" "(6 $op1 6) $op2 6" "6 $op1 (6 $op2 6)"; do
read a b c d e <<<"$eq"
if [[ "$eq" == *\) ]] && [[ "$op1" == [/%] ]] && ((6 $op2 6 == 0)); then
printf -v ans "%19s∞" ""
else
ans=$((eq))
fi
[[ "$c" == \(* ]] && c="$c "
[[ "$c" == ? ]] && c=" $c "
printf "%2s %2s %3s %2s %-2s = %20s\n" "$a" "$b" "$c" "$d" "$e" "$ans"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment