C
C#•3y ago
veud

possible combinations of upper and lower case string

How to get all possible combinations of upper and lower case string stored as a list of strings?
46 Replies
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
I need to iterate through them
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•3y ago
How big is your input data?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
but that is exactly my question
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
i am able to do something like this: cat => Cat, cAt, caT
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
but i need all combinations what is yield returining and why is your name exaxtly that coincidence?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
i only need it for small words, im not going to have to get all combinations of a 1000 character word
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
No I dont.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
I mean I can tell you, but I dont know how that will help I want to create hashes for all combinations
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
Is the need evaded?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
I really dont want to use yield
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
I have never heard or seen it And a list seems perfomant enough
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•3y ago
using System;
using System.Collections.Generic;

IEnumerable<string> GivePermutations(string input)
{
if (input.Length == 0)
{
yield return string.Empty;
yield break;
}

foreach (var permutation in GivePermutations(input[1..])
{
yield return char.ToUpper(input[0]) + permutation;
yield return char.ToLower(input[0]) + permutation;
}
}

foreach (var permutation in GivePermutations("cat"))
{
Console.WriteLine(permutation);
}
using System;
using System.Collections.Generic;

IEnumerable<string> GivePermutations(string input)
{
if (input.Length == 0)
{
yield return string.Empty;
yield break;
}

foreach (var permutation in GivePermutations(input[1..])
{
yield return char.ToUpper(input[0]) + permutation;
yield return char.ToLower(input[0]) + permutation;
}
}

foreach (var permutation in GivePermutations("cat"))
{
Console.WriteLine(permutation);
}
this was fun 🙂
veud
veudOP•3y ago
yes
Tvde1
Tvde1•3y ago
you can see the longer the string the bigger it gets
veud
veudOP•3y ago
thanks, I don't want to force someone to code it again, but I wonder how much better it really is than with lists
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•3y ago
also you can remove the index, it isn't used anywhere anymore
veud
veudOP•3y ago
Thank you
Tvde1
Tvde1•3y ago
though you probably are doing something wrong if you need all permutations
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
.
Tvde1
Tvde1•3y ago
good luck bruteforcing someone's password haha
veud
veudOP•3y ago
educational purposes
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
Whats that supposed to mean
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
okay thats true
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
jesus that doesn't look like C# for me anymore
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
idk if im inexpierenced, i have made some stuff work im not a professional ofc but syntax is just something i try to avoid for more readable code (also for myself)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
veud
veudOP•3y ago
Oh I have no mute here, nice Well it wasn't particularly necessary to do it this way Hmm
Want results from more Discord servers?
Add your server