Skip to content

Commit

Permalink
Correctly eliminating letters that can't show up.
Browse files Browse the repository at this point in the history
  • Loading branch information
archy-bold committed Jan 5, 2022
1 parent 3583dba commit 57a863b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,20 @@ func main() {
parts := strings.Split(strings.TrimSpace((input)), "")
boardRow := ""
numCorrect := 0
rejected := make([]bool, NUM_LETTERS)
for i, chr := range parts {
if chr == "x" {
letters[wordParts[i]] = false
// If this letter has shown up before but not rejected, don't eliminate
shouldEliminate := true
for j := 0; j < i; j++ {
if chr == parts[j] && !rejected[j] {
shouldEliminate = false
}
}
if shouldEliminate {
letters[wordParts[i]] = false
}
rejected[i] = true
} else if chr == "y" {
boardRow += COLOUR_GREEN
answersCorrect[i] = wordParts[i]
Expand Down Expand Up @@ -192,6 +203,12 @@ word:
}

for i, chr := range chrs {
// If this is an eliminated letter, score down
if !letters[chr] {
rankedWords = append(rankedWords, Pair{word, 0})
continue word
}

// If there is an answer in this position, we can disregard words that don't have that letter in that position
if answersCorrect[i] != "" && answersCorrect[i] != chr {
rankedWords = append(rankedWords, Pair{word, 0})
Expand Down
Binary file modified wordle
Binary file not shown.

0 comments on commit 57a863b

Please sign in to comment.