wordle-cli

Golang implementation of wordle in CLI.
git clone http://git.hanabi.in/repos/wordle-cli.git
Log | Files | Refs | README | LICENSE

commit cf485df71664b36db624d6d39c37d801b58c4ed0
parent 2b0b4dc45efc2fca17fff63841421d526c781f10
Author: Sahibardj <sahiba.rdj@gmail.com>
Date:   Thu, 17 Feb 2022 00:09:44 +0530

Algorithm to check if the word guessed is or not the ans. Incase it is/is not it shows the output through colour coding it.

Diffstat:
Asrc/algos/colour-algo.go | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/src/algos/colour-algo.go b/src/algos/colour-algo.go @@ -0,0 +1,47 @@ +package algos + +type Lookup map[string]int + +func GetColours(ans, guess string, alphabet map[string]int) string { + alookup := getALookup(ans) + res := glookup(ans, guess, alookup, alphabet) + return res +} + +func getALookup(ans string) Lookup { + alookup := make(Lookup, 0) + alen := len(ans) + for i := 0; i < alen; i++ { + achar := string(ans[i]) + alookup[achar]++ + } + return alookup +} + +// Sahiba's algo +func glookup(ans, guess string, alookup Lookup, alphabet map[string]int) string { + var res string + glookup := make(Lookup, 0) + glen := len(guess) + for i := 0; i < glen; i++ { + gchar := string(guess[i]) + if alookup[gchar] == 0 { + res += "R" + alphabet[gchar] = -1 + } else { + glookup[gchar]++ + if glookup[gchar] <= alookup[gchar] { + if ans[i] == guess[i] { + res += "G" + alphabet[gchar] = 1 + } else { + res += "Y" + alphabet[gchar] = 0 + } + } else { + res += "R" + } + } + } + return res +}