Department numbers: Difference between revisions

→‎{{header|jq}}: combinations
(→‎{{header|jq}}: combinations)
Line 2,012:
The second illustrates how essentially the same algorithm can be written in a more economical way, without sacrificing comprehensibility.
 
The third illustrates how the firstbuilt-in function `combinations/1' can easily be made more efficientused byto addingachieve somegreater pruningefficiency.
The solutions in all cases are presented as a stream of JSON objects such as:
Line 2,038:
and .police % 2 == 0 )</lang>
 
'''Pruningcombinations'''
<lang jq>range(1;8) as $fire
| ( [range(1;8) | select(. != $fire)) as $police]
| combinations(3)
| (range(1;8) | select(. != $fire and . != $police)) as $sanitation
| select( add == 12 and .[0] % 2 == 0)
| {$fire, $police, $sanitation}
| select({fire: ([.[0]], |police: add).[1], ==sanitation: 12).[2]}</lang>
 
=={{header|Julia}}==
2,469

edits