Subset sum problem: Difference between revisions
→{{header|jq}}: def selections:
(→{{header|jq}}: def selections:) |
|||
Line 1,197:
'''Works with gojq, the Go implementation of jq''' (provided `keys_unsorted` is replaced by `keys`)
<lang jq>
if length == 0 then []▼
.[0][] as $x▼
end ;▼
# Input: an array of n elements, each of which is either in or out
# Output: a stream of the 2^n possible selections
def
# map( [null, .] ) | combinations | map(select(.));
then .
| .[1:] | selections | ., ([$x] + .)
▲ end ;
# input: a JSON object giving the weights
Line 1,218 ⟶ 1,213:
. as $dict
|
</lang>
'''An Example'''
Line 1,260 ⟶ 1,255:
<pre>
[
"
"
"
"
"
"
"
"
"elysee"
]
</pre>
=={{header|Julia}}==
|