Last active
October 26, 2025 01:01
-
Star
(471)
You must be signed in to star a gist -
Fork
(43)
You must be signed in to fork a gist
-
-
Save huytd/6a1a6a7b34a0d0abcac00b47e3d01513 to your computer and use it in GitHub Desktop.
Revisions
-
huytd revised this gist
Feb 2, 2022 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,5 @@ words=($(grep '^\w\w\w\w\w$' /usr/share/dict/words | tr '[a-z]' '[A-Z]')) actual=${words[$[$RANDOM % ${#words[@]}]]} end=false guess_count=0 max_guess=6 if [[ $1 == "unlimit" ]]; then max_guess=999999 fi @@ -13,7 +10,7 @@ while [[ $end != true ]]; do read guess guess=$(echo $guess | tr '[a-z]' '[A-Z]') if [[ " ${words[*]} " =~ " $guess " ]]; then output="" remaining="" if [[ $actual == $guess ]]; then echo "You guessed right!" for ((i = 0; i < ${#actual}; i++)); do @@ -22,18 +19,21 @@ while [[ $end != true ]]; do printf "$output\n" end=true else for ((i = 0; i < ${#actual}; i++)); do if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then remaining+=${actual:$i:1} fi done for ((i = 0; i < ${#actual}; i++)); do if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then if [[ "$remaining" == *"${guess:$i:1}"* ]]; then output+="\033[30;103m ${guess:$i:1} \033[0m" remaining=${remaining/"${guess:$i:1}"/} else output+="\033[30;107m ${guess:$i:1} \033[0m" fi else output+="\033[30;102m ${guess:$i:1} \033[0m" fi done printf "$output\n" -
huytd revised this gist
Feb 2, 2022 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,28 +13,28 @@ while [[ $end != true ]]; do read guess guess=$(echo $guess | tr '[a-z]' '[A-Z]') if [[ " ${words[*]} " =~ " $guess " ]]; then output="" if [[ $actual == $guess ]]; then echo "You guessed right!" for ((i = 0; i < ${#actual}; i++)); do output+="\033[30;102m ${guess:$i:1} \033[0m" done printf "$output\n" end=true else c_actual=$actual for ((i = ${#actual}-1; i >= 0; i--)); do if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then if [[ "$c_actual" == *"${guess:$i:1}"* ]]; then c_actual=$(echo $c_actual | sed "s/${guess:$i:1}//") output="\033[30;103m ${guess:$i:1} \033[0m$output" else output="\033[30;107m ${guess:$i:1} \033[0m$output" fi else output="\033[30;102m ${guess:$i:1} \033[0m$output" c_actual=$(echo $c_actual | sed "s/${guess:$i:1}//") fi done printf "$output\n" fi -
huytd revised this gist
Feb 2, 2022 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ while [[ $end != true ]]; do echo "Enter your guess ($guess_count / $max_guess):" read guess guess=$(echo $guess | tr '[a-z]' '[A-Z]') if [[ " ${words[*]} " =~ " $guess " ]]; then if [[ $actual == $guess ]]; then echo "You guessed right!" output="" @@ -23,16 +23,18 @@ while [[ $end != true ]]; do end=true else output="" c_actual=$actual for ((i = 0; i < ${#actual}; i++)); do if [[ "${c_actual:$i:1}" != "${guess:$i:1}" ]]; then if [[ "$c_actual" == *"${guess:$i:1}"* ]]; then output+="\033[30;103m ${guess:$i:1} \033[0m" else output+="\033[30;107m ${guess:$i:1} \033[0m" fi else output+="\033[30;102m ${guess:$i:1} \033[0m" fi c_actual=$(echo $c_actual | sed "s/${guess:$i:1}//") done printf "$output\n" fi -
huytd revised this gist
Feb 2, 2022 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,11 @@ How to use: ``` ./wordle.sh ``` Or try the unlimit mode: ``` ./wordle.sh unlimit ``` File renamed without changes. -
huytd revised this gist
Feb 2, 2022 . 2 changed files with 13 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <img width="1017" alt="image" src="https://user-images.githubusercontent.com/613943/152097718-60e89194-9e1c-43f1-882c-4de84db75046.png"> How to use: ``` ./wordle ``` Or try the unlimit mode: ``` ./wordle unlimit ``` -
huytd revised this gist
Feb 2, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ <img width="1408" alt="image" src="https://user-images.githubusercontent.com/613943/152087994-f2ce8529-1ba4-400d-8824-2c6e4be9c5d4.png"> How to use: -
huytd created this gist
Feb 2, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <img width="874" alt="image" src="https://user-images.githubusercontent.com/613943/152087185-2cdc0bc4-b6a2-4ac7-847f-0f22d18cd5d8.png"> How to use: ``` ./wordle ``` Or try the unlimit mode: ``` ./wordle unlimit ``` 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ words=($(grep '^\w\w\w\w\w$' /usr/share/dict/words | tr '[a-z]' '[A-Z]')) actual=${words[$[$RANDOM % ${#words[@]}]]} end=false guess_count=0 max_guess=6 if [[ $1 == "unlimit" ]]; then max_guess=999999 fi while [[ $end != true ]]; do guess_count=$(( $guess_count + 1 )) if [[ $guess_count -le $max_guess ]]; then echo "Enter your guess ($guess_count / $max_guess):" read guess guess=$(echo $guess | tr '[a-z]' '[A-Z]') if [[ " ${words[*]^^} " =~ " $guess " ]]; then if [[ $actual == $guess ]]; then echo "You guessed right!" output="" for ((i = 0; i < ${#actual}; i++)); do output+="\033[30;102m ${guess:$i:1} \033[0m" done printf "$output\n" end=true else output="" for ((i = 0; i < ${#actual}; i++)); do if [[ "${actual:$i:1}" != "${guess:$i:1}" ]]; then if [[ "$actual" == *"${guess:$i:1}"* ]]; then output+="\033[30;103m ${guess:$i:1} \033[0m" else output+="\033[30;107m ${guess:$i:1} \033[0m" fi else output+="\033[30;102m ${guess:$i:1} \033[0m" fi done printf "$output\n" fi else echo "Please enter a valid word with 5 letters!"; guess_count=$(( $guess_count - 1 )) fi else echo "You lose! The word is:" echo $actual end=true fi done