Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**mpatt****Member**- Registered: 2012-04-30
- Posts: 5

I have a real world problem, and I'm hoping there will be an elegant mathematical solution to this.

I have an unordered list of ~100 values, some of which may appear more than once in the list e.g 10,15,15,12,13,10,15,29,30,.....

and I want to find the smallest number of those values, in the order given, which will add up to a particular sum, e.g. 666

Can it be done?

Thanks in advance for any help.

M:

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi;

May I see the list or is this any list?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Mathegocart****Member**- Registered: 2012-04-29
- Posts: 1,884

i do need too see the list to total things

The integral of hope is reality.

Offline

**mpatt****Member**- Registered: 2012-04-30
- Posts: 5

The list will change depending on when I run it, so I was hoping for an 'any case' method.

*Last edited by mpatt (2012-04-30 21:52:08)*

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

You must keep the ordering given too?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**mpatt****Member**- Registered: 2012-04-30
- Posts: 5

bobbym wrote:

You must keep the ordering given too?

yes.

For the record here's a sample list, the numbers will either be whole numbers or halves there will be no other fractions, oh and there may be occasions where it's not possible to find a set of values that will add up to the given sum:

30

20

22.5

15.0

25.0

17.5

17.5

20.0

15.0

22.5

20

20.0

37.5

32.5

12.5

22.5

20.0

20

30

25

12

15.0

22.5

17.5

15.0

17.5

20

22.5

22.5

20

21.5

25

27.5

15.0

22.5

12.5

15.0

30.0

15

30.0

27.0

20

15

12.5

17.5

33.0

22.5

17.5

15.0

20

20

17.5

15.0

22.5

17.5

17.5

17.5

10

27.0

15.0

15.0

22.5

15.0

15.0

12.5

17.5

15.0

15

15.0

25.0

24.0

25.0

15.0

22.5

20

24.0

27.0

22.5

15.0

15.0

15.0

35

17.5

27.0

20.0

15.0

15.0

30

25.0

12.5

21.0

30

20

18.0

27.5

15.0

24.0

10

17.5

11.5

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi mpatt;

Since the order must remain as given, I think that there is no mathematical way to solve the problem. There is a computer way that can do it.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Hi mpatt

First,you are contradicting yourself. You said in your first post you have unordered list. Please,be clear when you ask a question.

Second,I think there isn't a mathematical formula for this. The next best thing you can do is solve it by a computer.

*Last edited by anonimnystefy (2012-05-01 08:40:07)*

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Hi mpatt;

Do you program?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**mpatt****Member**- Registered: 2012-04-30
- Posts: 5

bobbym wrote:

Do you program?

A little, if there's an algorithm which will do it I'll have a go, thanks.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

The simplest approach is to try all singles and then all doubles and then all triples etc. What do you program in?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Hi bobbym

That would take a lot because they needn't be consecutive.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

and I want to find the smallest number of those values, in the order given,

I assume they are consecutive. He does not say they are not.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Not stating it doesn't give you the right to assume that.

The OP should've been clearer on the problem.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

The algorithm can be adjusted to handle that using recursion. I could write it in M as soon as he stipulates the rules. Trouble is he will need to a better than beginner to program it.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**mpatt****Member**- Registered: 2012-04-30
- Posts: 5

Hi Chaps,

When I said 'unordered' originally I meant unordered in the sense of unordered - not arranged in order hierarchically. Perhaps I should have said "unsorted"?

I'm not sure what you mean by consecutive? If by that you mean that the numbers to add up to 666 must be consecutive in the list then that is not the case, it could be that the solution is the 1st, 2nd, 5th, 8th.... nth value.

I can program in perl and have considered how I could write this using recursive loops in perl but it seems to me that for a set of 100 values I could end up with a huge number of iterations which would take ages, which is why I was hoping there might be a mathematical solution.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Recursion is the way to go. You said they are not all integers too?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Let's take the list you have in post #6. Let's do some mathematics on it. Whamo! Done!

You can make the hideous 666 from those numbers in 490208257 ways. Using generating functions will tell you how many there are. To get one answer you will need to do a PSLQ.

Both methods are computer dependent.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Hi bobbym

Do you think the GF method would work?

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

That is what I used!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Cool! So there is a mathematical way to do it without the use of procesural programming!

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

Yes. But it will require a computer to set it up and to solve it. But it will be fast.

I came full circle, the story is complete.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

So we will need more than just computer maths? We will have to use loops?!?

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,606

It could be done with loops and procedural code but it will be clumsy and slow. C++ provides a better solution. But the functional paradigm is the real answer.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,037

Functional paradigm?

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline