Teen Programmers Unite  
 

 

Return to forum top

A Simple (?) C++ Problem to do with Number Combinations

Posted by smcpherson [send private reply] at October 11, 2001, 06:28:53 PM

Okie, let's see. I've got a little project I'm trying to work on, and I'm pretty sure it can be done using C++. I only know a litlte bit about C++, though, so I don't know enough to really work the problem out. I understand the basics (or can find information on the net about them), but I don't know too many concepts. I don't think this problem requires any difficult concepts, but I don't know. Let me try to explain a simplified version of the problem (using simplified numbers).

It comes in a number of parts:

******
Part One: Definitons. I know how to define things in C++, but I am including this part here so you know what I am talking about later.

a=1, b=2, c=3, d=4, e=5, f=6

---------

Part Two: Arithmetic.

a*{d,e,f} + b{d,e,f} + c*{d,e,f} = z

(now, by { }, I mean to try all combinations of these variables: a*d + b*d + c*d is one combination, and a*d + b*d + c*e is another. There are 27 combinations, I believe)

if z=20, then continue to next part
if not, then go back up and continue trying combinations until you reach a combination where z=20 (and there is more than one combination where z=20)

-----------
Part Three: Tests. For each combination found where z=20, I want a number of tests to be done.

What was multiplied by a (either d, e, or f) cannot equal what was multiplied by c.

What was multiplied by b (either d, e, or f) cannot equal what was multiplied by c.

if one test is failed, continue with combinations.
if all tests are passed, print the d/e/f values of a, b, and c (in other words, which variables a, b, and c were multiplied by)
******

I don't need an exact working program, but if anyone could help me out with little bits and pieces, or certain topics I should study to figure out how to complete this. There won't be any input. It will just run from the code. This isn't the *actual* problem - the actual problem has many more variables and tests, but if I know how to do just a simple one, I can expand it to fit the real problem.

I also had another solution I could try. Maybe there's really no need to define a, b, c, etc. in part one. In part two, it would be easier to just use

-----
1*{4,5,6} + 2*{4,5,6} + 3*{4,5,6} etc.
-----

For each combinations, though, I need to set the value of { } as a variable, so I could test those variables in part three.

-----
1*{4,5,6} (now assign either the 4, 5, or 6 as x) + 2*{4,5,6} (now assign either the 4, 5, or 6 as y) + 3*{4,5,6} (now assign either the 4, 5, or 6 as z)
-----

To test:

x cannot equal z
y cannot equal z
and so forth.

I don't know if that's possible, though.

I also had another concern. When z does not equal 20, and the process of finding combinations continues, will it restart? Will it pick up from where it left off? Restarting wouldn't be very productive; the program would just keep trying the same combination over and over again.

I'm sorry if this all seems confusing. I don't know any other way to word it. Like I said, *any* help would be appreciated regardless of how detailed it is. Thanks in advance!

Selwyn McPherson.
If you have any questions, you can email me at slcool@neo.rr.com

Posted by csspcman [send private reply] at October 20, 2001, 12:34:27 AM

don't worry only the appearance is a bite scary but it realy has a simple solutions regarding to that you are using c++
you'r solution is not bad but I suggest you use variable instead of using direct values you can make it either in blocks or switch statments or any other conditional capabilities in C++ and ofcourse yes it can keep trying to find the
correct combination and it will help you to makeing up the original problem
how ever it is usefull also in this little simulation that you described
I'll talk to you about it more soon later

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.