14
1
Given an unordered collection of positive integers by any reasonable input method, return all of the sub-collections that have an odd number of odd elements (i.e. have an odd total).
This is code-golf so you should aim to minimize the byte count of your program.
Since some languages only have ordered collections (lists, arrays, vectors, etc.) or don't have an unordered collection that allows duplicates, you may use ordered collections (regardless of your language choice), however you should not output any duplicate collections with different orders (e.g. [2,3]
and [3,2]
). You may output in whatever order you see fit.
Test cases
[2,3,7,2] -> [[3],[7],[2,3],[2,7],[2,2,3],[2,2,7]]
[2,4,6,8] -> []
[4,9] -> [[9],[4,9]]
2Are duplicate subcollections allowed? As in, for
[2, 2, 3]
, may we return[[2, 2, 3], [2, 3], [2, 3]]
? – HyperNeutrino – 2017-05-26T19:16:10.9801Hint: the sum of such a set can only be odd. Any other variant of these sets can only have an even sum. – tuskiomi – 2017-05-26T19:17:01.240
@HyperNeutrino No you should only return each one once – Post Rock Garf Hunter – 2017-05-26T19:17:35.067
Okay. Do the subcollections need to be in ascending order or is it fine to list them in the order provided in the original array? – HyperNeutrino – 2017-05-26T19:18:32.223
@HyperNeutrino They may be in any order, (ideally they would be an unordered collection, but many languages don't have such a construct so ordered collections are fine as long as the order is not important) – Post Rock Garf Hunter – 2017-05-26T19:21:08.990
If we consider an ordered list,
[2, 3]
isn't necessarily a duplicate of[3, 2]
since 2 may occur twice in the original list (like in your example). Should it still output this only once? I would find that strange. – sigvaldm – 2017-05-26T19:45:02.730@sigvaldm The challenge is about unordered collections, the two 2s present are not distinguishable. If you choose to use an ordered collection for this challenge that is fine, but you should treat the input as if it is unordered, in which case those two are duplicates. – Post Rock Garf Hunter – 2017-05-26T19:47:44.437
Your test case contains only primes. That's a coincidence, yes? – Dennis – 2017-05-26T20:24:45.970
I wouldn't call it a problem, but one might draw conclusions after looking at the test case. A test case with empty output would also be useful. – Dennis – 2017-05-26T20:28:07.947
Can languages with unordered collections use ordered collections? – CalculatorFeline – 2017-05-26T20:41:16.913
@CalculatorFeline Yes. – Post Rock Garf Hunter – 2017-05-26T20:41:57.007
Can we assume that the input is given in order? (Several golfing languages use sorted ordered collections as a substitute for unordered collections, and operations which normally work correctly on both ordered and unordered collections will assume the collection is ordered if the inputs are out of order.) – None – 2017-05-27T02:13:29.800
@ais523 No you may not. – Post Rock Garf Hunter – 2017-05-27T02:19:33.587