Counting words using the Euler characteristic