- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2015-03-03 12:53 编辑
@zsszss0000 @54nwq
Here you are with good performance
$ time awk -vv=275.32 'function x(v,s,c,t,p,y){if(s-c>1)while(++p<=NR-s+c)x(v,s,c+1,t+a[p],p,y a[p]"("p")+");else{if(t+max<v||v<t+min)return;while(++p<=NR){if(v==t+a[p]){cnt++;print v"="y a[p]"("p")"}}}}{a[NR]=$1;N=NR;if(NR==1)max=min=$1;if(max<$1)max=$1;if(min>$1)min=$1;printf $1"("NR"), "}END{print "\nmax="max", min="min;for(n=1;n<=NR;n++)x(v,n);print "got total:"cnt}' FILE
43.11(1), 56.27(2), 88(3), 7.22(4), 4.77(5), 38.59(6), 95.09(7), 64.04(8), 66.61(9), 54.99(10), 54.77(11), 34.83(12), 3.23(13), 4.75(14), 80.26(15), 12.9(16), 77.26(17), 28.17(18), 78.01(19), 68.87(20), 83.95(21), 12.29(22), 79.08(23),
max=95.09, min=3.23
275.32=43.11(1)+64.04(8)+12.9(16)+77.26(17)+78.01(19)
...
275.32=4.77(5)+38.59(6)+95.09(7)+34.83(12)+3.23(13)+4.75(14)+12.9(16)+68.87(20)+12.29(22)
got total:23
real 0m15.366s
user 0m12.925s
sys 0m0.252s
$ time awk -vv=275.32 'function x(v,s,c,t,p,y){if(t>v)return;if(s-c>1)while(++p<=NR-s+c)x(v,s,c+1,t+a[p],p,y a[p]"("p")+");else{if(t+max<v||v<t+min)return;while(++p<=NR){if(v==t+a[p]){cnt++;print v"="y a[p]"("p")"}}}}{a[NR]=$1;N=NR;if(NR==1)max=min=$1;if(max<$1)max=$1;if(min>$1)min=$1;printf $1"("NR"), "}END{print "\nmax="max", min="min;for(n=1;n<=NR;n++)x(v,n);print "got total:"cnt}' FILE
43.11(1), 56.27(2), 88(3), 7.22(4), 4.77(5), 38.59(6), 95.09(7), 64.04(8), 66.61(9), 54.99(10), 54.77(11), 34.83(12), 3.23(13), 4.75(14), 80.26(15), 12.9(16), 77.26(17), 28.17(18), 78.01(19), 68.87(20), 83.95(21), 12.29(22), 79.08(23),
max=95.09, min=3.23
275.32=43.11(1)+64.04(8)+12.9(16)+77.26(17)+78.01(19)
...
275.32=4.77(5)+38.59(6)+95.09(7)+34.83(12)+3.23(13)+4.75(14)+12.9(16)+68.87(20)+12.29(22)
got total:23
real 0m3.029s
user 0m1.720s
sys 0m0.068s
real 0m3.123s
user 0m1.820s
sys 0m0.124s
real 0m2.852s
user 0m1.748s
sys 0m0.096s
Note: run three times
|
|