Helgef wrote:@ iPhilip. It seems very good

. Could you generalise it, such that it takes an arbitrary interval

[a,b] that all

ni is required to lie within it. As it is now, the interval is

[1,9].

Thank you, Helgef.

I edited the above code so that it takes an arbitrary interval

[a,b], including negative numbers. Note that, in the case of an interval that crosses zero (e.g.

[-1,1], zero is an allowed integer in the solution.

Nicolas wrote:Thanks a lot @iPhilip, that's pretty close to what I asked for!

Your program seems to stop at i=4, is there a way to increase it or would it be too hard/too much work?

Either way, it's good enough for what I'm using it for!

The script actually covers the interval

[1,9]. The

4 you see is just a way to demonstrate four different examples, i.e.

Sums(9,1),

Sums(9,2),

Sums(9,3),

Sums(9,4).

boiler wrote:This lets you enter the numbers you want each time you run it. First the sum, then how many numbers ... Nice job, iPhilip.

Thank you, boiler.

Exaskryz wrote:... I'm noticing the problems break down into smaller ones ...

I noticed the same thing. It's what led me to use recursion.

Helgef wrote:... looking at iPhilips method, you can see that the termination criterias are either, solution found or sum to high, there is no sorting or checking if solutions are permutated ...

What ensures that there are no permutated solutions is the starting value of the loop for the following integers. For example, in the case of

s=10, i=2, the solution

3,7 will not be permutated because the loop for the first value of

7 will start at

8, i.e. the script will start at

[7,8] and continue with

[7,9]. The line

n[j] := n[j-1] + A_Index insures that. I hope this helps.

Cheers!