Function that counts the number and length of words and generates a histogram