in reply to Re: Re: Re: Words that equal numbers
in thread Words that equal numbers
But check out the hawtin solution below, which generates a combination one letter at a time, eliminating large batches of cases with early constraint testing. And all the constraint checks are simple concatenations and arithmetic.
It's not a completely general solution as it stands, but it could be the basis for one, by using generated code.
Update: It could also be generalized fairly easily by a looping program that pushed the current state onto a stack, or by a recursive program.
Update 2: I just noticed that your idea to test only combinations that sum to 45 means you could count by 9's. Only multiples of 9 have a digital sum that is a multiple of 9. That cuts your number from 9 billion to about 1 billion... still too many to be worth doing it that way, IMHO.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Words that equal numbers
by CountZero (Bishop) on Jan 19, 2003 at 09:06 UTC |