My stab at the IsIsogram by length

I assume there is a way easier way we are going to do this but… this works! Took me a little bit to workout the last 2 characters being checked also I’m sure it’s not good to do nested while loops like this?

If you’re wondering I didn’t set the checked to 1 immediately because of the way I was comparing them before and was afraid I could get an error if somehow IsIsogram(); was called without a guess.

void UBullCowCartridge::IsIsogram(FString Guess)
{
    int check = 0;
    int checked = 0;
    if ((Guess.Len()) != 0)
    {
        checked = 1;
        while (check != (Guess.Len()) - 1)
        {
            while (checked != Guess.Len())
            {
                if (Guess[check] == Guess[checked])
                {
                    PrintLine(TEXT("That's not an isogram lul"));
                    return;
                }
                else
                {
                    ++checked;
                }
            }

            ++check;
            checked = check + 1;
        }
    }
}```

Pseudo code lmao
image

1 Like

turned it into a bool return type in case it’s important for later

bool UBullCowCartridge::IsIsogram(FString Guess)
{
    int check = 0;
    int checked = 0;
    if ((Guess.Len()) != 0)
    {
        checked = 1;
        while (check != (Guess.Len()) - 1)
        {
            while (checked != Guess.Len())
            {
                if (Guess[check] == Guess[checked])
                {
                    PrintLine(TEXT("That's not an isogram lul"));
                    return true;
                }
                else
                {
                    ++checked;
                }
            }
            ++check;
            checked = check + 1;
        }
    }
    return false;
}

Privacy & Terms