Is there a more compact way of summing certain elements of lists together when given a tuple of which elements to sum. For example if I am given the list of size 8:
{1,2,3,4,5,6,7,8}
and a sequence which indicates which elements to sum together, such as (1,3,3,1), this should yield
{1, 9, 18, 8}
I was considering further (1,3,3,1) partitioning of the original list {1,2,3,4,5,6,7,8} and then simply adding the entries at that level? Is there a clear way of doing this further (1,3,3,1) partitioning?
Thanks for any assistance.
Total /@ TakeList[{1, 2, 3, 4, 5, 6, 7, 8}, {1, 3, 3, 1}]
$\endgroup$Total[TakeList[lst,{1,3,3,1}],{2}]
$\endgroup$