I’m making a script to create a username. It should be four letters long; traditionally we’ve used 3 letters of the last name + 1 of the first name.
If it was already used we manually thought of an alternative.
So if my name is Fred Flinstones we should try FLIF. If this doesnt work; we loop through the name: FLIA, FLIB, FLIC … FLIZ, FLAA, FLAB, FLAC, … FLZZ, FAAA, FAAB, …
The easiest way is to loop through last letters; then make another set of loops through second last letter and loop through last letters; then a set of loops through third last, second last, last; and fourth+third+second+last.
This makes a lot of do while loops nested in eachother + unreadable for other humans + a lot of typing.
I could use a counter per letter but that also doesn’t seem elegant
I could try with one counter and then using mod 26 to see how many letters need replacement (but that seems very complex).
Is there some elegant/efficient ways to do this?
Bonus points for first trying to keep the string as ‘logically correct’ as possible (f.e. keeping the last letter an F for Fred or skipping letters FLIF; FLNF, FLSF, FLTF, …) .
Not sure if this is what you mean, but if you structure your username-script in the following way (I used PHP as language), you can extend it by adding options with higher fuzz factors while keeping the code readable: