Coder Social home page Coder Social logo

wordle-solver's Introduction

Wordle-Solver

A Wordle Solver console application using C++ by an easy yet efficient algorithm.

Table of Content

Tools

  1. Code Blocks (IDE)
  2. C++
  3. STL library

How to enter Input

For each bad letter (aka black letter) put '!' before it. For each possible letter (aka yellow letter) put '@' before it. For each right letter (aka green letter) put '#' before it.

Example:

  !n@o#t!e!s

where: n,e,s are black, o is yellow, t is green

Don't put spaces between letters as input.

Algorithm Explained

  1. Populate vector named 'v' with words inside the dictionary using "populateVector" function

  2. Take input from user

  3. If the letter in the word is Green, insert it in "rightLetters" vector along with its index. If the letter is Yellow, insert it in "possibleLetters" vector along with its index.

  4. If the letter is black, we will check if it has been previously inserted in right or possible vector, if so we will insert it in "specialLetters" vector, else we will inser it in "badLetters" vector.

  5. For each Bad letter in the word (Black Letter):

    Iterate through the vector of words, if any word contain such bad letter, remove it from vector
    
void eliminateBadLetters(char x){       //removing words containing black characters
   for(it=v.begin();it!=v.end();){
       bool flag =false;
       string temp = *it;
       for(int i=0;i<=4;i++){
           if(x==temp[i]){
               flag =true;
               break;
           }
       }
       flag?it=v.erase(it):++it;
   }
}
  1. For each Possible letter in the word (Yellow Letter):

        Iterate through vector of words
              If any words doesn't contain that yellow character at all, remove it
              If any word has yellow character in the same position as entered in input, remove it.
    
void eliminatePossibleLetters(char x,int y){
    for(it=v.begin();it!=v.end();){         //removing any word which does not have yellow character in right position
        string temp =*it;
        temp[y]==x?it = v.erase(it):++it;
    }

    for(it =v.begin();it!=v.end();){        //removing any word which does not have any yellow character at all
        string temp =*it;
        bool flag =false;
        for(int k=0;k<=4;k++){
            if(x==temp[k]){
                flag =true;
                break;
            }
        }
        flag?++it:it=v.erase(it);
    }
}
  1. For each Right letter (Green Letter):

         Iterate through vector of words, if any word doesn't have that character in same position as entered, remove it.
    
void findRightLetters(char x,int y){
    for(it = v.begin();it!=v.end();){       //removing any word which does not have green character in right position
        string temp = *it;
        temp[y]!=x?it = v.erase(it):++it;
    }
}
  1. For each (Special letter):

         Iterate through vector of words, if any word have that character in same position as entered, remove it.
    
void eliminateSpecialLetters(char x,int y){
    for(it = v.begin();it!=v.end();){
        string temp = *it;
        temp[y]==x?it = v.erase(it):++it;
    }
}

Special letter are the letters which are green and (black) at the same time. Meaning special letters are just black letters with index.

Author

Yousef Kotp

wordle-solver's People

Contributors

yousefkotp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.