Git Product home page Git Product logo

Comments (2)

branwall avatar branwall commented on July 17, 2024

I believe the logic for this requires two passes through the guess to get the highlighting correct.

First pass: is this letter in the correct spot? If so, green. Is it completely absent from the word? If so, black.
Then, remove all the correct guesses from the answer word so they can't be reused in the comparison.

Second pass: Is this letter in the word at all? (It will necessarily be in the wrong spot.) If so, yellow. Else, black.

Edit: Here's how I solved it using the above logic:

let mutableAnswer = String(answer);
  const output = ["", "", "", "", ""];
  const letters = guess.split("");
  letters.forEach((letter, index) => {
    if (answer[index] === letter) {
      mutableAnswer = mutableAnswer.replace(letter, 0); //this ensures the letter won't be "in" the answer 
//for purposes of marking it yellow when the user guessed it in the correct position already, 
//without reordering the remaining letters in the answer.
      output[index] = green;
    } else if (answer.indexOf(letter) === -1) {
      output[index] = black;
    }
  });
  letters.forEach((letter, index) => {
    if (!output[index] && mutableAnswer.indexOf(letter) > -1) {
      output[index] = yellow;
      mutableAnswer = mutableAnswer.replace(letter, 0);
    } else if (!output[index]) {
      output[index] = black;
    }
  });
  return output;

from wordle.

MikhaD avatar MikhaD commented on July 17, 2024

The actual Wordle doesn't mark a letter as yellow unless there is at least one more of the guessed letter in the actual word in an unknown location. I just played and got the word "MANIA" as the answer. But when I guessed "INDIA," I got 🟨🟨⬛️🟩🟩 instead of ⬛️🟨⬛️🟩🟩. You can verify how the actual Wordle works by guessing primp for today's word. You'll see that the first P is black, not yellow, even though a second P exists in the word.

~ Courtesy of flyguy33443322 on reddit.

from wordle.

Related Issues (20)

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.