News Focus
News Focus
Followers 44
Posts 2488
Boards Moderated 0
Alias Born 03/22/2001

Re: Bob Zumbrunnen post# 17456

Friday, 10/11/2002 9:11:13 AM

Friday, October 11, 2002 9:11:13 AM

Post# of 222454
I did my anagram solver differently. I wanted a C program where I could re-use the code elsewhere. I find the library functions strlen, strlwr, and memset efficient enough. It's surprising how often something I did for fun contains a bit of tricky code that I can apply to work later on. If I get ambitious, I'd substitute the array arithmetic var[index] to code using pointers.

Cheers, PW.

P.S.

 
Zero fill a 26 element array of integers.

Load the array by bumping the count for each letter in the jumbled string.

FOR (each word in the dictionary)
IF (length matches)
Zero fill a second 26 element array of integers.
Load the dictionary word into the array similarly to the jumbled word.
Print words when arrays match.
.
.
.
/* A bit (the testing part) from the actual code */

if (gl!=strlen(w)) return(0); /* Test the length */
memset(wa,0,AL); /* Zero fill arrays */
for (a=0;a<gl;a++) ++wa[w[a]-FL]; /* Count characters */
for (a=0;a<AL;a++) if (ga[a]!=wa[a]) return(0); /* Compare arrays */
return(-1); /* Pass if not fail */




Discover What Traders Are Watching

Explore small cap ideas before they hit the headlines.

Join Today