Re: Interesting Programming Problem
- From: Gene Wirchenko <genew@xxxxxxxx>
- Date: Thu, 29 May 2008 08:40:59 -0700
"Jeff Grippe" <jeff@xxxxxxxxx> wrote:
"Gene Wirchenko" <genew@xxxxxxxx> wrote in message
news:qsor34thvsfn41m5sisqaivomcs84dimv0@xxxxxxxxxx
"Jeff Grippe" <jeff@xxxxxxxxx> wrote:
[snip]
I see your point here but I'm dealing with a relatively small number of
numbers. Of course once you say that you immediately get someone who wants
to use your application with a large data set.
You are dealing with factorials here. They get very big very
fast. 10! is well over one million. That makes ten a big number
relatively speaking. How much data do you have?
You do not search, but rather increment indexes. Actually, it
does not get complex. I already outlined the algorithm. It is little
more complicated than nested loops.
Run:
Pick 16. Reject 14, 8, 7, 5. Pick 2. No more data: back off 2. No
more data: back off 16.
Pick 14. Reject 8, 7. Pick 5. Reject 2. No more data: back off 5.
Pick 2. No more data: back off 2. No more data: back off 14.
Your algorithm is still dealing with factorials because in order to reject
the numbers you are rejecting you must consider them. I'm not sure if your
algorithm allows you to not consider higher numbers once you have rejected
them in a pass through the loop. This may be a problem for which the human
brain is better suited.
Higher numbers, once they are incremented past, will not be
considered.
No, not as a general solution. If you accept close
approximations, then possibly.
What I can add to the problem description is:
1. There will always be a solution (although you must code for the "no
solution" case)
Not for the exact sum version.
By the ordering principle, there will always be a best answer. By
your definition (being close), this is a solution.
2. The numbers will all always be positive
Then use my approach.
I'm going to play with your algorithm a bit more a bit more. I've been
wondering if there were some algorithm where you start with the sum of the
data set and then use subtraction to find your answer.
That is isomorphic to my algorithm. Whether you add up to the
desired number and watch for sums too big or subtract from the desired
number and watch for differences less than zero, it is the same
general idea.
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.
.
- References:
- Interesting Programming Problem
- From: Jeff Grippe
- Re: Interesting Programming Problem
- From: Gene Wirchenko
- Re: Interesting Programming Problem
- From: Jeff Grippe
- Re: Interesting Programming Problem
- From: Olaf Doschke
- Re: Interesting Programming Problem
- From: Jeff Grippe
- Re: Interesting Programming Problem
- From: Gene Wirchenko
- Re: Interesting Programming Problem
- From: Jeff Grippe
- Interesting Programming Problem
- Prev by Date: Re: How to OLE automate printing a Word document to a specific printer under VFP?
- Next by Date: Re: MSCAL.OCX v7 overwritten by v11 of control?
- Previous by thread: Re: Interesting Programming Problem
- Next by thread: Re: Interesting Programming Problem
- Index(es):
Relevant Pages
|