I have a list $(d_1, d_2, .. d_k)$ and I want to create all sums that I get for adding only two elements for my list $(d_1+d_2, d_1+d_3,...d_{k-1}+d_k)$. The RotateLeft function gives me only some of my sums and I need all of them.
Tell me more
×
Mathematica Stack Exchange is a question and answer site for
users of Mathematica. It's 100% free, no registration required.
|
|
||||
Let's make use of pattern matching ( even though there are faster methods especially for list manipulations) :
Typically, efficiency of pattern matching solutions is worse than that of functional approach, nevertheless we point out a remarkable feature of the result of
|
||||
|
|
|
Since somebody mentioned timings...
|
|||
|
|
edit Some timings
|
||||
|
|
|
Something like :
Alternatively (plus suggestion from @Oleksandr R.) :
And just because
|
|||||
|
|
Come downvote @Verde
|
|||||||||||||||
|
|
Just to show that there's more than one way to do things in Mathematica:
Of course, Oleksandr's and Verde's suggestions are the more compact way of going about it. |
|||
|
|


clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem,by clicking the checkmark sign- thanks! – Vitaliy Kaurov Sep 4 '12 at 15:09