[Python-ideas] Haskell envy

Terry Reedy tjreedy at udel.edu
Mon Apr 23 22:28:50 CEST 2012


On 4/22/2012 11:18 PM, Chris Rebert wrote:
> On Sun, Apr 22, 2012 at 7:55 PM, Terry Reedy<tjreedy at udel.edu>  wrote:
>> On 4/22/2012 9:07 PM, Nestor wrote:
> <snip>
>>> Have the function ArrayAddition(arr) take the array of numbers stored
>>> in arr and print true if any combination of numbers in the array can
>>> be added up to equal the largest number in the array, otherwise print
>>> false. For example: if arr contains [4, 6, 23, 10, 1, 3] the output
>>> should print true because 4 + 6 + 10 + 3 = 23.  The array will not be
>>> empty, will not contain all the same elements, and may contain
>>> negative numbers.
>>
>> Since the order of the numbers is arbitrary and irrelevant to the problem,
>> it should be formulated in term of a set of numbers.
>
> Er, multiplicity still matters, so it should be a multiset/bag. One
> possible representation thereof would be a list...

Er, yes. Given the examples, I (too quickly) misread 'will not contain 
all the same elements' as 'no duplicates'. In any case, a set was needed 
for the functional version as there is no 'list1 - list2' expression 
that returns the list1 minus the items in list2. (Well, I could have 
defined an auxiliary list sub function, but that is beside the point of 
the example.)

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list