Re:The Array Cast – A podcast about the array programming la...
by rklmno on Saturday May 22, 2021 @11:59PM
(#27252333)
Like was mentioned, the simplest behavior is treat this as an error case.
Other possibilities include:
(*) extending the length of the short array to match the length of the long array -- padding with zeros on the right -- before adding.
(*) finding all possible sums between pairs with one number from one array and the other number from the other array.
(*) cyclically extending the shorter array (probably not useful in this example, but since the example didn't come with a use case that's difficult to know for sure).
(*) Treating each array as a decimal number (or a number in some other base)
(*) combining the two array as a single list of numbers and summing everything to a single value
and... so on...
One point being that programming languages support arbitrarily complex operations.
Another point being that "sum" in this context carries some understandable ambiguity -- the sort of thing which we usually try to constrain with use cases or examples or similar elaboration.
Other possibilities include:
(*) extending the length of the short array to match the length of the long array -- padding with zeros on the right -- before adding.
(*) finding all possible sums between pairs with one number from one array and the other number from the other array.
(*) cyclically extending the shorter array (probably not useful in this example, but since the example didn't come with a use case that's difficult to know for sure).
(*) Treating each array as a decimal number (or a number in some other base)
(*) combining the two array as a single list of numbers and summing everything to a single value
and... so on...
One point being that programming languages support arbitrarily complex operations.
Another point being that "sum" in this context carries some understandable ambiguity -- the sort of thing which we usually try to constrain with use cases or examples or similar elaboration.