hi there :)
i'm currently practicing with the recursive backtracking method by trying to solve all the suggested problems...

one of them says: find all the solutions for the next ecuation: 3x + y + 4xz = 100

so the solution would be of type S={(x,y,z) | x,y,z belonging to N}
by now i've tried different stuff like finding a pattern which would guide me then to make the validation part but i couldnt find anything that would work.. i've deduced that each element of the 3 levels of the stack where i build the solution belongs to a set of elements formed only by knowing the other 2 ... can somebody gimme a hint or something?!

Recommended Answers

All 3 Replies

Isn't stuff like that done by setting one variable to zero in order to find the relationship between the the other two, then resubstitute that relationship?

You could also do a simultaneous equations matrix.
Hope this helps, It's been a while...
Hope that helps

Not sure if this defeats the purpose of your program (it's not recursive), but for a problem with numbers as small as this, where everything is natural numbers and less than 100, you could change the equation to:

y = 100 - 3x - 4xz

and do a brute force method. Each value of x and z gives you a value of y. Start with x and z at 0 and check for all value pairs of x and z. Have an outer for loop of x values and an inner for loop of z values. Have each for loop increase by one each time. When y goes negative for a particular x value, bail out of the inner z loop.

first of all thanx for replying :)
i've asked my teacher and said that on each level of the stack representing x,y and z there's a value from 0 to 100 (except for the case where x=0, when on the third level representing z can be actually any natural number) so from here everything worked just fine :)

@VernonDozier: i've tried as you said and it worked perfectly too, thanx :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.