Bulls and Cows out parameters

My Version. A we bit different.

void UBullCowCartridge::GetBullsAndCows(const FString& Guess, int32& BullCount, int32& CowCount)
{
	BullCount = 0;
	CowCount = 0;

	for (int32 i = 0; i < Guess.Len(); i++) {
		if (Guess[i] == HiddenWord[i]) {
			BullCount++; // Direct hit
		}
		else {
			for (int32 j = 0; j < Guess.Len(); j++) 
			{	// See if char is repeated elsewhere.
				if ((Guess[i]) == HiddenWord[j] && (i != j))
				{
					CowCount++;
				}
			}
		}
	}
}
1 Like