Help: for loop doesn't work?

A

a

I'm studying the frequency of 5-letter words composed of {a,b,c,d,e} in a
string, I wanna build an array recording the frequencies of (aaaaa, aaaab,
...., caaaa, ..., eeeee). I find that for loop can work well if I hard-code
the number, what can I do if I wanna study n-letter word (e.g. n=3, 100,
3732)?
 
T

Thad Smith

a said:
I'm studying the frequency of 5-letter words composed of {a,b,c,d,e} in a
string, I wanna build an array recording the frequencies of (aaaaa, aaaab,
..., caaaa, ..., eeeee). I find that for loop can work well if I hard-code
the number, what can I do if I wanna study n-letter word (e.g. n=3, 100,
3732)?

I suggest, for a given n, making a single pass through the string, building
a data structure containing all the defined words and a count of how many
times each is used. A tree or hash table would work well.
 
C

CBFalconer

Thad said:
I suggest, for a given n, making a single pass through the string,
building a data structure containing all the defined words and a
count of how many times each is used. A tree or hash table would
work well.

Take a look at the demonstration application for hashlib, wdfreq.
Modification should do what the OP wants. hashlib is available,
GPL licensed, at:

<http://cbfalconer.home.att.net/download/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top