An alternative solution to sum that does not require an accumulator