From 401fb1c591d2cb47c6c6000732379fc69554b5e5 Mon Sep 17 00:00:00 2001 From: Ethan Cheng Date: Fri, 12 Sep 2025 22:09:35 -0700 Subject: [PATCH] fix bitmap creation (coloring) to match wordle's --- main.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index f3c50c3..76e33f3 100644 --- a/main.go +++ b/main.go @@ -80,21 +80,30 @@ func findWord(bitmap string) (string, error) { } func createBitmap(word string) string { - var output string + output := []byte{'0', '0', '0', '0', '0'} + count := make(map[rune]int) + + for _, v := range correctWord { + count[v]++ + } for i, v := range word { - idx := strings.IndexRune(correctWord, v) - - if idx == -1 { - output = output + "0" - } else if idx == i { - output = output + "g" - } else { - output = output + "y" + if word[i] == correctWord[i] { + output[i] = 'g' + count[v]-- } } - return output + for i, v := range word { + if output[i] == '0' { + if count[v] > 0 { + output[i] = 'y' + count[v]-- + } + } + } + + return string(output) } func matchBitmap(bitmap1, bitmap2 string) bool {