Formula to get combination… sum

Formula to get combination
Lats say, I have 5 values

 
ID Price
1 5
2 10
3 30 
4 5

Resule with Possible combinations will be

 
ID Price
1 5
2 10
3 30
4 5
1+1 10
1+2 15
1+3 35
1+4 10
2+2 20
2+3 40
2+4 15
3+3 60
3+4 35
4+4 10
1+2+3 45
1+2+4 20
.
.
.
1+2+3+4 50

Likewise, i have different groups wich has IDs from 1 to 10.... can u please help someone how to get this result..

I have tried to write the following code, but it does not give me 1+2+3...

 
let count=1
let m_var=$((`wc -l < x`))
while [[ $m_var -gt 0 ]]
do
rm xyz1||true
tail -$m_var x|while read abc
do
id=`echo $abc|awk -F"~" '{print $1}'`
#echo $id>>xyz1
echo $abc>>xyz1
if [[ -s xyz1 ]]
then
cat xyz1|while read xyz
do
if [[ ! -z $mmm ]] && [[ ! -z $nnn ]]
then
mor=`echo $xyz|awk -F"~" '{print $1}'`
mmm=`echo $mmm + $mor`
let nor=`echo $xyz|awk -F"~" '{print $2}'`
let nnn=`expr $nnn + $nor`
else
mmm=`echo $xyz|awk -F"~" '{print $1}'`
nnn=`echo $xyz|awk -F"~" '{print $2}'`
fi
#echo $mmm
done
echo "$mmm~$nnn"
mmm=""
nnn=0
fi
done
m_var=`expr $m_var - 1`

interesting question...

something along the lines of:

#  cat infile
a 5
b 10
c 30 
d 5


#  nawk '{t[2^(NR-1)]=$1;s[2^(NR-1)]=$2}END{for (i=1;i<=2^NR-1;i++){x="";z=0;k=i;n=0;  while (k>0){j=int(k/2); if (k-2*j==1) {x=x" "t[2^n];z+=s[2^n]};n++;k=j};print x,z}}' infile
 a 5
 b 10
 a b 15
 c 30
 a c 35
 b c 40
 a b c 45
 d 5
 a d 10
 b d 15
 a b d 20
 c d 35
 a c d 40
 b c d 45
 a b c d 50

should be what you're after....I'll let you tidy up the exact formatting :slight_smile: