Crafting some nice declarative non-procedural code tonight
?- columnSums([[1,1],[3,1]], S).
S = [4, 2].
columnSums(ListOfRows, ColumnSums):-
Outer = ListOfRows,
Outer = [FirstInner | _],
length(Outer, LengthOuter),
length(FirstInner, LengthInner),
findall(
X,
(
between(1, LengthInner, IndexInner),
findall(
Y,
(
between(1, LengthOuter, IndexOuter),
nth1(IndexOuter, Outer, AnOuter),
nth1(IndexInner, AnOuter, Y)
),
Ys
),
sum_list(Ys, X)
),
ColumnSums
).