Path: utzoo!attcan!uunet!wuarchive!sdd.hp.com!hplabs!hpda!hpcuha!hpcuhd!scotta From: scotta@hpcuhd.HP.COM (Scott Anderson) Newsgroups: alt.sources Subject: Re: Permutation generator Message-ID: <108380001@hpcuhd.HP.COM> Date: 15 Oct 90 18:55:49 GMT References: <1990Oct12.172633.8855@iconsys.uucp> Organization: Hewlett Packard, Cupertino Lines: 51 Here's one I did about 2 years ago for solving jumbles (in a pretty gross way - see leading comment in program). It doesn't use malloc and uses pointers instead of indices. The only minor disadvantage is that dupes aren't eliminated. I find it somewhat amusing how similar the programs are though. Scott Anderson An RTEsian and proud of it... Hewlett-Packard Data Systems Operation scotta@cup.hp.com 11000 Wolfe Rd. MS 42UN 408-447-5219 Cupertino, CA 95014 ________________________________________________________________________ /* This program produces permutations of all of the strings passed to it. * To solve jumbles try: * perm xxxxx | sort -u | tee temp | spell | sort | comm -13 - temp * where xxxxx is the scrambled word. */ #define SWAP(a, b) ch = *(a); *(a) = *(b); *(b) = ch; void perm(whole, partial) char *whole, *partial; { register char *ptr, *next_partial, ch; if (!*partial) { puts(whole); return; } ptr = partial; next_partial = partial + 1; while (*ptr) { SWAP(partial, ptr); perm(whole, next_partial); SWAP(partial, ptr); ptr++; } } main (argc, argv) int argc; char **argv; { int i; for (i=1; i