Jelly, (削除) 37 (削除ここまで) 36 bytes (thanks @Steffan!)
2*’
§=9a×ばつ2*9¤ʋ
Ñe3ƊƇμ’3œcç"Ñ’$F1Ƈ
Also a mess.
Link 1: computes \2ドル^x-1\$
2 Two
* To the power of the input
’ Decrement
Link 2: given a list of subsets of length \$p-1\$ of the input list, and \$q-1\$ (as defined in the question), return a list with all valid answers or 0.
§=9a×ばつ2*9¤ʋ
§ Compute the sum of each sublist (vectorizes at depth 1)
= Check if equal to... (vectorizes)
9 ...q-1
a Logical AND with...
ʋ ...the four previous links as a dyad
Ç The previous link as a monad (2^x-1 for each x in each subset)
€ For each subset:
P Compute the product
×ばつ Multiply by...
¤ ...a nilad followed by some links, as a nilad:
2 Two
* To the power of...
9 ...q-1
Link 3 (main link): given the input list, outputs all valid answers.
Ñe3ƊƇμ’3œcç"Ñ’$F1Ƈ
Ƈ Filter the list using:
Ɗ The last three links as a monad
Ñ The next link as a monad (wraps around to link 1)
e Check if it's present in...
3 ...the input list
μ Start a new monadic chain
(At this point, the list contains all 'p' in the input list such that 2^p-1 is also in the input list.)
’ Decrement
œc All combinations of ... of any length in the list (vectorizes over the right argument)
3 The input list
" Zipping over the left and right arguments:
ç Call the previous link as a dyad, with the next link as the right argument
$ The last two links as a monad:
Ñ The next link (wraps around to link 1) on each valid 'p', thus generating all the candidates for 'q'
’ Decrement (thus generating all the candidates for q-1)
F Flatten
Ƈ Filter the list using:
1 The truth value of each element itself (thus removing all falsy values from the list)
Alex
- 545
- 1
- 5
- 14