C
C#•2y ago
armin

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•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
I need to iterate through them
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•2y ago
How big is your input data?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
but that is exactly my question
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
i am able to do something like this: cat => Cat, cAt, caT
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
but i need all combinations what is yield returining and why is your name exaxtly that coincidence?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y 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•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
No I dont.
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y 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•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
Is the need evaded?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
I really dont want to use yield
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
I have never heard or seen it And a list seems perfomant enough
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•2y 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 🙂
armin
armin•2y ago
yes
Tvde1
Tvde1•2y ago
you can see the longer the string the bigger it gets
armin
armin•2y 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•2y ago
Message Not Public
Sign In & Join Server To View
Tvde1
Tvde1•2y ago
also you can remove the index, it isn't used anywhere anymore
armin
armin•2y ago
Thank you
Tvde1
Tvde1•2y ago
though you probably are doing something wrong if you need all permutations
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
.
Tvde1
Tvde1•2y ago
good luck bruteforcing someone's password haha
armin
armin•2y ago
educational purposes
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
Whats that supposed to mean
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
okay thats true
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
jesus that doesn't look like C# for me anymore
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y 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•2y ago
Message Not Public
Sign In & Join Server To View
armin
armin•2y ago
Oh I have no mute here, nice Well it wasn't particularly necessary to do it this way Hmm