Hi,

I have no1 to no30 product prices.
I want to calculate combination for 30 product prices

Suppose I have 30 different numbers..
I want to calculate their sum by using combination.

But combination should not repleted
i.e.
E.g
for 4 numbers...
[ 10 20 30 40]

I want to do like without repetition
10
20
30
40
10+20
10+30
10+40
20+30
20+40
30+40
10+20+30
10+20+40
10+30+40
20+30+40

so how to calculate 30 numbers in this way..without repetition
How to do that??
I think when i calculate sum without repetition for numbers it takes minimum time Or any algorithm or method to do it fast in minimum time??

Hi,

I have no1 to no30 product prices.
I want to calculate combination for 30 product prices

Suppose I have 30 different numbers..
I want to calculate their sum by using combination.

But combination should not repleted
i.e.
E.g
for 4 numbers...
[ 10 20 30 40]

I want to do like without repetition
10
20
30
40
10+20
10+30
10+40
20+30
20+40
30+40
10+20+30
10+20+40
10+30+40
20+30+40

so how to calculate 30 numbers in this way..without repetition
How to do that??
I think when i calculate sum without repetition for numbers it takes minimum time Or any algorithm or method to do it fast in minimum time??

Well this is just a thought

$array = array('10', '20', '30');
$addition = join("+", $array);

then you can echo 1 then add have a counter to reach 50

like i said it is just a thought so maybe someone can expand on it

hi,
right now i am just tried to display structure...
E.g
for 4 numbers...
[ 10 20 30 40]
I want to do like
10
20
30
40
10+20
10+30
10+40
20+30
20+40
30+40
10+20+30
10+20+40
10+30+40
20+30+40

$colorList = array("10","20","30","40");
  $count=count($colorList);
$reduce=$count;
for ($i=0;$i<$count;$i++)
{
      echo"<br>main-->". $colorList[$i]."<br>";
		for($j=$i+1;$j<$count;$j++)
		{
		echo "<br>".$colorList[$i]."+".$colorList[$j];
		 echo"=".$c=$colorList[$i]+$colorList[$j];
		}
}

It gives output

main-->10

10+20=30
10+30=40
10+40=50
main-->20

20+30=50
20+40=60
main-->30

30+40=70
main-->40

Plz tell me what to do??
How to get the output??
Even if i increase the length of array i.e. number in array

Hi, Aamit
I am not sure but may be for combination of numbers you have to use or create dynamic loops.

This article has been dead for over six months. Start a new discussion instead.