code for counting strings of a given length