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`