My thoughts on different methods

As some have said we could create an array for the 26 letters of the alphabet, and increment that array value if it’s in the word, if hits more then it should then it returns false. However there is no error checking for other symbols !@#$%^)(*&^:"1234876950-4 etc. They are all valid guesses at the moment.

So I suppose you could use the same array and implement that into CheckValidGuess() to ensure the submitted word only contains characters in the alphabet.

We could compare each letter to each other letter which is again n^2 and slow.

I feel as if there must be some way to check for duplicates in a very easy way without going through n^2 methods and without sorting pairs.

like each char is assigned a value. I’m just thinking aloud here.

say each char was given an individual number, so for ant the chars are given 1,2,3 etc… adding them together gives them predictable result 1,3,6,10 etc. however if we said tat t = 1, a = 2, t = 3. not adding them together would 3+2+3 = 8. Giving us the incorrect number.

However the code isn’t taking “t” it just taking string[0] and string[2] which it can’t tell are the same, so unless there is a way to equate a specific char to an int it wouldn’t work. like “a” = 1 and 1 = ‘a’ so that int 1111 = sting aaaa dont think it works that way though.

So I think sorting than comparing pairs, or Array checking and using the same array to check the guess is only accepted letters can work well.

Privacy & Terms