Another Way To Write the IsIsogram Function

Hello! Before watching the two videos regarding checking characters, I worked out a solution that does work. The difference is that every character is checked against every character including itself. So obviously, it is less efficient for the purposes of this game. I was just wondering if anyone knew of an instance where this method might be useful.

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    for (int32 i = 0; i < Word.Len(); i++)
    {
        for (int32 j = 0; j < Word.Len(); j++)
        {
            if (Word[i] == Word[j] && i != j)
            {
                return false;
            }
            
        }    
    }
    return true;
}

I ignored the times where the function checks the same index by adding it as a condition in my if statement. So does anyone know when this style might be useful?

1 Like

I agree with you, @gddpeh . I think it sincerely depends on the application. Personally, I can’t think of one that would require all the checks (disregarding the fact that I know little of your molecular dynamics example – that’s my fiancee’s field more than mine).

@Littledoom , first: kudos to you for coming up with that before watching the videos. Second: to point at your original question, I do think that the best thing you can focus on is writing the best, cleanest code you know how to do. Obviously the algorithm described in the video is more “efficient,” but I am willing to assume you did the best you knew how to do at the time. Always work to improve yourself and these tips and tricks will come to you over time.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms