General Question

LostInParadise's avatar

Programmers, can you spot the error in this Wordle program?

Asked by LostInParadise (31915points) January 30th, 2023

As a programming exercise, I coded a function that would give the letter colors for a guess of a particular word. The program is not that long but it is not trivial.

I went online to see if I could find a similar program. I found this. You can see the code if you scroll down a little. Can you spot the error and give a counter-example that will not work?

Observing members: 0 Composing members: 0

5 Answers

Jeruba's avatar

No, probably not, although my eye keeps lingering on the -1.

You’re not actually showing us a bit of Wordle code, though, right? It’s someone’s attempt to emulate it. You ‘re not saying the actual Wordle code contains the error.

What I’m curious about is the data set: how it was populated, how a given day’s word is selected, whether there’s some sort of algorithm for word difficulty, whether the target words and the guess words come from the same data set or not.

LostInParadise's avatar

This is definitely not Wordle program code.

The -1 is actually at the heart of the problem with the code. Not equal to -1 means that the letter from the guess is in the target word. The problem is that all of the guess letters matching a given target letter are shaded orange so if, for example, the target word is “drink” and the guess is “added”, the program makes each of the 3 d’s in “added” orange, instead of just one, which is what the actual Wordle program would do.

Jeruba's avatar

So I kind of got it? Even if I didn’t know exactly why it was an error.

Your question, by the way, does say it’s a Wordle program.

LostInParadise's avatar

I apologize for any confusion. I would say you have an intuitive sense for where the problem was

Jeruba's avatar

I spent years as a full-time programmer back in the 70s (when there were no jobs for English majors), on IBM S/3 and its successors, and later I played around with BASIC when my husband was building games with it. Long out of touch, though, so intuition is about as far as I’m going to get, although I can read through some code and get a sense of what’s going on.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther