I'm coding a program about "Drunken Squares" where I generate a random list of directions like N S E or W and use code to test if those lists of directions correspond to a perfect square.
Each list of directions is 20 directions (characters) long and in the format of a character array.
One criteria which I am trying to implement is code which would detect how large of clusters of characters there are in the list, here is an example of what I mean:
Grade the list of directions in terms of how well it is clustered
Perfect Square would be (Perfect Input): N N N N N E E E E E S S S S S W W W W W
output: largest cluster = 5
output: smallest cluster = 5
Typical Input: W N N E E E W S N S S W W E S S W W W
output: Largest cluster would be 3
output: Smallest cluster would be 1
My specific question is how do you take input as a character array and return the largest and smallest clusters of characters within the array?
Current code:
for (int i = 0; i < 20; i++) {
if (i+1 <= 20) {
if (input2[i].ToString() == input2[i+1].ToString()) {
//Make some value increase?
}
}
}