Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I'm studying in university and I have to make one program with recursion. But I just cannot figure out where to start.

Basically I have 5 random numbers from 2x{1-10} and one more from {25;50;75;100}.
Final number is {100-999}. I have to write a program that calculates my final number using mathematical operations (+;-;*;/) with those 6 random numbers. Program should solve it for less than 5 secs and use numbers only once.

Sorry for my English. Here is an example:

4 4 7 8 9 100 -> Random numbers
380 -> Final number (to get)

Solutions:

4 * 100 = 400
9 + 8 = 17
7 + 17 = 24
24 – 4 = 20
400 – 20 = 380

or

4 * 9 = 36
4 + 36 = 40
7 * 40 = 280
280 + 100 = 380
(did not use 8)

There also should be situation where It would not be possible to calculate.

I'm really struggling right now, It feels like I am not trying to learn recursion but just waste my time on a difficult mathematical stuff. I don't necessarily want a code in response, I would greatly appreciate an explanation how to solve this mathematical problem the easiest way possible... I can only think of going through all possible outcomes and it's really ineffective and bad imo. Usually I have a plan what to do, and I know hows it's done. The problems I usually have is to write a code. But now, I have no idea how to solve it...

Thanks in advance!

What I have tried:

I just cannot think of proper way to run the recursion. Only trying to run through all of possible outcomes. Which is not easy as well...
Posted
Updated 27-Feb-16 8:04am
Comments
BillWoodruff 28-Feb-16 10:59am    
Try posting this question on the 'Algorithms forum here.

To get help on this forum, you really need to show some code, and indicate you've gotten started. If you are somehow "blocked," getting started, then break this problem into two or three simpler versions of the problem, and program those: along the way you will, I predict, learn a lot.

This is actually an interesting question, and the tricky part is knowing "when to stop." If the "desired result" is prime, is a solution possible ? Can you exclude any factors to reduce the possible computational space ?

From a quick look at your example: it appears to me you allow the expanding of the "search space" to include intermediate results of computation; if that impression is correct, then I think this makes the search space virtually "infinite."

You could also research computational complexity theory:

https://en.wikipedia.org/wiki/NP-completeness

If you could prove this problem involved an infinite search space, I bet your school would no only graduate you with honors, they'd want you to join the faculty.

Also, search on "genetic computing."

http://arstechnica.com/science/2016/02/np-complete-problem-solved-with-biological-motors/

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
(Used with permission of OriginalGriff)

If you show some code with a particular problem, we may help, otherwise, ir is the wrong place.
 
Share this answer
 
Comments
Member 12355942 27-Feb-16 14:16pm    
I'm not asking here so that someone can solve it for me. I just have been struggling with this for quite a while. And I tried to express that I only need an advice how to solve this. How to think about it in mathematical way. Just a couple of sentences might help. Quite disappointed in your response :)
Patrice T 27-Feb-16 14:29pm    
The problem is that there is no "midway" advice that will just lead you in the right direction. "Recursion" is the only help that is not directly the solution.

And don't think I don't know the problem, this problem is simply the oldest TV show here in France.
BillWoodruff 28-Feb-16 10:59am    
This is not a solution; it's a series of comments to the OP.

fyi: OG knows that I think it's a bad idea for anyone to post a warning, caution, moral instruction, etc. here as a solution.
Patrice T 28-Feb-16 11:08am    
The problem is that there is no help other than giving a full blow up solution, thus doing the OP assignment.
The OP already know that he need recursion.
BillWoodruff 29-Feb-16 2:35am    
If you know there is "no help" ... which I doubt you do ... then why would you post a "solution" ? Problems such as the OP describes are found in computation, and, within limits, some are solvable by genetic programming, even by use of bacteria based computation.

The formal analysis of whether this type of problem is computationally possible leads to the very interesting area of computer science theory, computational complexity theory, involving NP-Complete and NP-Incomplete problem taxonomy.

https://en.wikipedia.org/wiki/NP-completeness

If, in this case, the OP could formally prove the problem-space was infinite, I imagine his school would graduate him magna cum laude.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900