Math problem giving me a headache, please advise!

Dec 2, 2012 at 3:31pm

Math problem giving me a headache, please advise!

Hello math folks
I need your help to help me solve a math trick, any advice is very appreciated

I have these numbers: 4 3 2 1.5 1 0.75 0.5 0.25
I need to create a coll that contains ALL the permutations of these numbers which the sum is always equal to 4
any idea for a quick patch or suggestion?

many thanks

#65470
Dec 2, 2012 at 3:36pm

For permutations I mean
4
3 1
1 3
2 2
2 1 1
1 2 1
1 1 2
1 1 1 1
0.5 1 1 1
1 0.5 1 1
1 1 0.5 1
1 1 1 0.5
and so on…

#235901
Dec 2, 2012 at 3:41pm

You used the word “permutation,” but the example you gave is not a collection of permutations. A permutation is a reordering, so if your original sequence contains 8 elements, as yours does, every permutation will also contain 8 elements.

So I haven’t a clue about what problem you’re trying to solve. Before anyone can help you, you’ll have to explain the problem accurately and completely.

#235902
Dec 2, 2012 at 3:57pm

you’re right, I’ll try to explain better.

I need to create a coll that contains all the possible lists (from 1 to 16 numbers) using (4 3 2 1.5 1 0.75 0.5 0.25)
in which total sum is 4
for example:

4

2 2

2 1 1
1 2 1
1 1 2

1.5 1 1.5
1 1.5 1.5
1.5 1.5 1.5

0.5 0.5 1 2
2 1 0.5 0.5
0.5 1 0.5 2
2 1 0.5 0.5
0.5 2 0.5 1

and so on

as you can see as the list grows I need also all the permutations

sorry for my english, not easy to talk of math in a foreign language

#235903
Dec 2, 2012 at 3:58pm

1.5 1 1.5
1 1.5 1.5
1.5 1.5 1

SORRY

#235904
Dec 2, 2012 at 4:45pm

I would concentrate my efforts on 2 individual problems:

1- Getting the different combinations of numbers, independently of the order of the elements in the list.
To that extent, you could use a high to low generation methodology. Here’s an example to get to the number “3″:
3
2 1
2 0.75 0.25
2 0.5 0.5
2 0.5 0.25 0.25
2 0.25 0.25 0.25 0.25
1.5 1.5
1.5 1 0.5
1.5 1 0.25 0.25
1.5 0.75 0.75
1.5 0.75 0.5 0.25
1.5 0.75 0.25 0.25 0.25
1.5 0.5 0.5 0.5
1.5 0.5 0.5 0.25 0.25
…….

2- Generate all possible permutations for each list created, maybe with the help of the [permute] object from http://www.essl.at/works/rtc.html

Disclaimer: I’ve never tried any of this… ;-)

#235905
Dec 2, 2012 at 4:52pm

HI,

With a programming language, you can use a tree search algorithm. But as the branching factor is 8 and the depth is 16, i’m almost sure that the number of solution is huge and that results can not be stored in a [coll] object ;-)

#235906
Dec 2, 2012 at 5:56pm

Hi Pedro
yes that’s what I’m doing.. I just hoped there was a faster method..
For permutations I’m using zl.permute

it is coming like this

4

3 1
3 0.75 0.25
3 0.5 0.5
3 0.5 0.25 0.25
3 0.25 0.25 0.25 0.25

2 2
2 1 1
2 1 0.75 0.25
2 1 0.5 0.5
2 1 0.5 0.25 0.25
2 1 0.25 0.25 0.25 0.25
2 1.5 0.5
2 1.5 0.25 0.25
2 0.75 0.25 0.75 0.25
2 0.5 0.5 0.5 0.5
2 0.5 0.25 0.25 0.5 0.25 0.25
2 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25

1.5 1.5 1 0.75 0.25
1.5 1.5 0.5 0.5
1.5 1.5 0.5 0.25 0.25
1.5 1.5 0.25 0.25 0.25 0.25

and so on…

#235907
Dec 2, 2012 at 5:59pm

sorry zl.scramble

#235908
Dec 2, 2012 at 6:42pm

Hi,

A naive approach with a depth of 8 to illustrate my previous post.

– Pasted Max Patch, click to expand. –
#235909
Dec 3, 2012 at 7:50am

Hi,

With [deferlow] you can do it recursively even if i’m not sure it is a really safe. It seems there is 24098 solutions.

– Pasted Max Patch, click to expand. –
#235910
Dec 3, 2012 at 10:19pm

Great patch, nicolas! Simple and efficient.

#235911

You must be logged in to reply to this topic.