Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hard programming question ?

Status
Not open for further replies.

ggreg

Programmer
Mar 9, 2001
201
US
I have a field-"group"(which is letters A,B...I,J),two other
fields are Name and Number,Name is a keyfield and one name will always have the same letter. The number range from 1 to 50 and a number is given to a name. Now there could be
7 or more of any one group(7 names with group A,B,C..etc)
Now here's what i need to do, example I have a number total=150...what i want to know is what combinations of the
groups can I have that equals 150 but excludes Letters higher than G..........150=A+B+C+D+E+F+G,(Alan,20,-Bill,30-
Charles,20-Dave,20-Ed,27-Greg,33)=150 how do i write the
code for that problem and what would be best to use a form
report or query?
 
Hello.

I'm sorry. I don't understand the question. Can you reformulate more clearly?

Grigore Dolghin
Class Software
Bucharest, Romania
 
Grigore,
first thanks for responding thought this would have gotten more intesest from programmers. cause my problem has got to be some kind of array with a while and may some if statements.let me give you a small breakdown of data realize my groups goes from
A to Z and I only want to use A thru G so I want to exclude letters higher than G
fields names
name group number section now let say I put in 50 as the total for
alan A 11 a the number field --Then the answer i would
ben B 29 a want to see is (alan-A-11,ben-B-29,charles-
charles C 10 a C-10) those numbers would total 50 and i would
tony A 5 a want it to use only one A-B-C and if there were
sam B 20 a more combination that total 49 I want to know
all possible combination(meaning that there maybe other combination of A,B,C,D,E,F,G that might total what ever number I put) that total the number that I put in...notice I added a section field cause I will have another field that I will include in the sort! let me know if you need more information!!! and Thanks a Bunch for looking at this problem!!!!Cause i think its too hard for me to figure out on my own...I have been
trying on my own by looking at while and if, else statements and think its going
to be a combination of both!
Thanks again and I will be waiting to see if you and anybody can help!!
 
sorry that first one got scamble was not sure how much room I would have!

Grigore,
first thanks for responding thought this would have gotten more intesest from programmers. cause my problem has got to be some kind of array with a while and may some if statements.let me give you a small breakdown of data realize my groups goes from
A to Z and I only want to use A thru G so I want to exclude letters higher than G
fields names
name group number section
alan A 11 a
ben B 29 a
charles C 10 a
tony A 5 a
sam B 20 a
now let say I put in 50 as the total for the number field --Then the answer i would
want to see is (alan-A-11,ben-B-29,charles-C-10) those numbers would total 49 and i would want it to use only one A-B-C and if there were more combination that total 49 I want to know
all possible combination that total the number that I put in...notice I added a section
field cause I will have another field that I will include in the sort!
let me know if you need more information!!! and Thanks a Bunch for looking at this
problem!!!!Cause i think its too hard for me to figure out on my own...I have been
trying on my own by looking at while and if, else statements and think its going
to be a combination of both!!!!
Thanks again and I will be waiting to see if you and anybody can help!!
 
I goof again cause I change my data cause within in one section-a different number
will be assign to a person, so none of the people will have the same number
but not should not effect the code.....so the total I know above is 50 so insert 50
where ever you see that i put 49! sorry for the mistakes!
 
ggreg

if i am understanding your problem, the following may give you some hints


create table results etc (whatever the syntax is for this)
use xxx (your data file)
index on group to xxx (index the file on this field, use a tag if you already have one)

m.your_number = 50
m.cumulative = 0

scan
scatter memvar
m.cumulative = m.cumulative + number
if m.cumulative =< m.your_number
insert into results from memvar
endif
endscan


Let me know if I am on the right track

Pete Bloomfield
Down Under
 
repete has a good point, just make a table with all possible answers and just look at total number of records.
or you could use something like this (untested code)
<code>
letters = 'ABCDEFG' && letters you wish to use
counter = 0 && count the number of outputs
n = 50 && the max number
for i = 1 to 7 && letter loop
for x = 1 to n && number loop
?substr(letters,i,1),x && output letter,number
counter = counter+1 && increment counter
next
endfor
?&quot;there are&quot;,counter,&quot;possible letter number combo's
</code>
 
One thing to bear in mind is that if you're only dealing with a few items, e.g. a,b,c,d,e,f,g, it's feasible to calculate all the possible combinations, but if you're dealing with a large number, the combinations quickly become too large to calculate. A quick hand calculation of the first 5 numbers give 1, 3, 7, 15, 31, or 2 to the Nth minus 1. For just a-g this is only 127 possibilities, but if you wanted to do the entire alphabet it'd jump to 64 million +. --Dave
 
hey Thanks all!!!!!!!!-I thought about trying something to show all possible combination
but did think it might be too big!!going to look into all your suggestion!!and I will
come back and post what work!!and too what turn out best or if I still need a little more help!!!Thanks all!!!
 
:) my code was also untested, but hopefully it will only insert into the results table, the results based on the value of m.your_number which in my example i hard coded, but in actual use, i would expect that the user would provide this value through the interface.

Good luck
Pete Bloomfield
Down Under
 
Hey in Access you can query off of a query but all I see i can do in foxpro is
query off of the tables is that correct or can i query off of a query cause maybe a crosstab query might help, built off of a query?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top