#!/bin/sh LIST="$(cat -)" if test "$(echo "$LIST" | wc -l)" -lt ${2:-13}; then # Get the answer on your next guess echo "$LIST" else # Letters you want to guess LETTERS="$(echo "$LIST" | sed 's/\(.\)/\1\n/g' | sort | uniq -c | sort -n)" echo "$LETTERS" grep5="$(echo "$LETTERS" | tac | awk '(p){printf("| grep " $2); p--;} ($2 == ""){p=5;}')" grep4="$(echo "$LETTERS" | tac | awk '(p){printf("| grep " $2); p--;} ($2 == ""){p=4;}')" grep3="$(echo "$LETTERS" | tac | awk '(p){printf("| grep " $2); p--;} ($2 == ""){p=3;}')" g5="$(sh -c "grep ^.....$ \"$1\" $grep5")" if sh -c "grep ^.....$ \"$1\" $grep5"; then echo elif sh -c "grep ^.....$ \"$1\" $grep4"; then echo elif sh -c "grep ^.....$ \"$1\" $grep3"; then echo fi fi