N-uniquely additive sets Remember that a set is unordered without duplicates.

Definition An N-uniquely additive set S whose length is K is a set such that all N-length subsets in S sum to different numbers. In other words, the sums of all the N-length subsets of S are all distinct.

Objective Given an array/set as input and a number N to a function or to a full program in any reasonable format, find and return or output a truthy or falsey value (erroring for falsey is okay) denoting whether or not the input is N-uniquely additive.

You may assume that each element only appears at most once and that each number is within your language's native datatype. If need be, you may also assume that the input is sorted. Last, you may assume that 0 &lt; N &lt;= K.

Examples

Let's consider the set S = {1, 2, 3, 5} and N = 2. Here are all the sums of all unique pairs over S (for the unique ones are the only ones of interest for sums):

1 + 2 = 3
1 + 3 = 4
1 + 5 = 6
2 + 3 = 5
2 + 5 = 7
3 + 5 = 8


We can see that there are no duplicates in output, so S is 2-uniquely additive.



Let's now consider the set T = {12, 17, 44, 80, 82, 90} and N = 4. Here are all the possible sums of length four:

12 + 17 + 44 + 80 = 153
12 + 17 + 44 + 82 = 155
12 + 17 + 44 + 90 = 163
12 + 17 + 80 + 82 = 191
12 + 17 + 80 + 90 = 199
12 + 17 + 82 + 90 = 201
12 + 44 + 80 + 82 = 218
12 + 44 + 80 + 90 = 226
12 + 44 + 82 + 90 = 228
12 + 80 + 82 + 90 = 264
17 + 44 + 80 + 82 = 223
17 + 44 + 80 + 90 = 231
17 + 44 + 82 + 90 = 233
17 + 80 + 82 + 90 = 269
44 + 80 + 82 + 90 = 296


They are all unique, and so T is 4-uniquely additive.

Test Cases

[members], N =&gt; output
[1, 4, 8], 1 =&gt; true
[1, 10, 42], 1 =&gt; true                ; all sets trivially satisfy N = 1
[1, 2, 3, 4], 3 =&gt; true
[1, 2, 3, 4, 5], 5 =&gt; true
[1, 2, 3, 5, 8], 3 =&gt; true
[1, 2, 3, 4, 5], 2 =&gt; false           ;  1 +  4       =  5 =        2 + 3
[-2, -1, 0, 1, 2], 3 =&gt; false         ; -2 + -1 + 2   = -1 =   -2 + 0 + 1
[1, 2, 3, 5, 8, 13], 3 =&gt; false       ;  1 +  2 + 13  = 16 =    3 + 5 + 8
[1, 2, 4, 8, 16, 32], 3 =&gt; true
[1, 2, 4, 8, 16, 32], 4 =&gt; true
[1, 2, 4, 8, 16, 32], 5 =&gt; true
[1, 2, 4, 8, 16, 32], 6 =&gt; true
[3, 4, 7, 9, 12, 16, 18], 6 =&gt; true
[3, 4, 7, 9, 12, 16, 18], 3 =&gt; false  ; 3 + 4 + 12 = 19 = 3 + 7 + 9
Jelly, 7 bytes

œcS€ṢIP


Try it online!

Returns a positive number for truthy and zero for falsey.

œc       find combinations
  S€     sum each combination
    Ṣ    sort the sums
     I   find the difference between each pair of sums 
           iff any sums are the same, this returns a list containing 0
      P  product of the elements of the resulting list