I tried making an isogram checker and it worked!

I got carried away at the IsIsogram() pseudocode challenge and tried just going for it instead. To my surprise and excitement it seems to actually work! It’s not a lot of code but it still took about a half hour to wrap my head around the logic and fix inefficiencies.

For example, at the start of the first “while” loop I initially set Counter2 to 0 every time, but then I realized it would make some checks more than once as it ran through the loops. I eventually figured out I could set Counter2 to equal Counter1 at that point in the code and eliminate the double-checking of earlier results. I’ll have to see if there were any other places I could have improved when I watch the video. Here’s the function:

bool UBullCowCartridge::IsIsogram(FString IsoGuess)

{

    const int32 NumberOfChars = IsoGuess.Len();

    int32 Counter1 = 0;

    int32 Counter2;

    while(Counter1 < NumberOfChars)

    {

        Counter2 = Counter1;

        while(Counter2 < NumberOfChars)

        {

            if(IsoGuess[Counter1] == IsoGuess[Counter2] && Counter1 != Counter2)

            {

                return false;

            }

            ++Counter2;

        } 

       ++Counter1;

    }

    return true;

}

Edit: I spotted another inefficiency. If I make Counter2 = Counter1 + 1 at the start of the first While loop, it would eliminate the need for the second condition check in the second While loop.

1 Like

Well done on getting this done.

Privacy & Terms