Skip to content

Instantly share code, notes, and snippets.

@DebarghaG
Forked from huytd/wordle.md
Created February 2, 2022 06:59
Show Gist options
  • Save DebarghaG/da328d4f3b5bfeca07151ebabfc2cdd6 to your computer and use it in GitHub Desktop.
Save DebarghaG/da328d4f3b5bfeca07151ebabfc2cdd6 to your computer and use it in GitHub Desktop.

Revisions

  1. @huytd huytd revised this gist Feb 2, 2022. 2 changed files with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wordle.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@
    How to use:

    ```
    ./wordle
    ./wordle.sh
    ```

    Or try the unlimit mode:

    ```
    ./wordle unlimit
    ./wordle.sh unlimit
    ```
    File renamed without changes.
  2. @huytd huytd revised this gist Feb 2, 2022. 2 changed files with 13 additions and 13 deletions.
    13 changes: 0 additions & 13 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    <img width="1408" alt="image" src="https://user-images.githubusercontent.com/613943/152087994-f2ce8529-1ba4-400d-8824-2c6e4be9c5d4.png">

    How to use:

    ```
    ./wordle
    ```

    Or try the unlimit mode:

    ```
    ./wordle unlimit
    ```
    13 changes: 13 additions & 0 deletions wordle.md
    Original 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
    ```
  3. @huytd huytd revised this gist Feb 2, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <img width="874" alt="image" src="https://user-images.githubusercontent.com/613943/152087185-2cdc0bc4-b6a2-4ac7-847f-0f22d18cd5d8.png">
    <img width="1408" alt="image" src="https://user-images.githubusercontent.com/613943/152087994-f2ce8529-1ba4-400d-8824-2c6e4be9c5d4.png">

    How to use:

  4. @huytd huytd created this gist Feb 2, 2022.
    13 changes: 13 additions & 0 deletions readme.md
    Original 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
    ```
    48 changes: 48 additions & 0 deletions wordle
    Original 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