I know what I want but I have no idea if there's a technical name for this or how to go about calculating it.
Suppose I have a string:
ABCDEFGHI
This string can be split evenly into a "MAXIMUM" of 3 characters each sub-string.
Basically, I'm trying to find out how to split a string evenly into its maximum sub-lengths. A string of 25 characters can be evenly split into 5 parts consisting of 5 characters each. If I tried to split it into 4 or 6 pieces, I'd have an odd length string (a string with a size different from the others).
- A string of 9 characters can be split into only 3 pieces of 3 characters each.
- A string of 10 characters can be split into only 2 pieces of 5 characters each.
- A string of 25 characters can be split into only 5 pieces of 5 characters each.
- A string of 15 characters can be split into 3 pieces of 5 characters each OR 5 pieces of 3 characters each.
- A string of 11 characters cannot be split because one string will always be larger than the other.
So how do I go about doing this? I've thought of using the square root but that doesn't work for a string of "10" characters. Works for 9 and 25 just fine.
Any ideas? Is there a technical name for such a thing? I thought of "Greatest Common Divisor", but I'm not so sure.
Aucun commentaire:
Enregistrer un commentaire