Department numbers: Difference between revisions
Content added Content deleted
Line 2,288: | Line 2,288: | ||
Note that we are only showing the distinct valid [[combinations]] here, not all valid [[permutations]] of those combinations. (Valid permutations would be: swapping the last two values in a combination, and all permutations of 2 4 6.) |
Note that we are only showing the distinct valid [[combinations]] here, not all valid [[permutations]] of those combinations. (Valid permutations would be: swapping the last two values in a combination, and all permutations of 2 4 6.) |
||
Another variation would be more constraint based, blindly implementing the rules of the task and yielding all valid permutations: |
Another variation would be more constraint based, blindly implementing the rules of the task and yielding all valid permutations. (Shown here with the number of possibilities at each step): |
||
<syntaxhighlight lang=J> NB. 3 departments, 1..7 in each |
<syntaxhighlight lang=J> NB. 3 departments, 1..7 in each |
||
rule1=. >,{3#<1+i.7 |
#rule1=. >,{3#<1+i.7 |
||
343 |
|||
NB. total must be 12, numbers must be unique |
NB. total must be 12, numbers must be unique |
||
rule2=. (#~ ((3=#@~.) * 12=+/)"1) rule1 |
#rule2=. (#~ ((3=#@~.) * 12=+/)"1) rule1 |
||
30 |
|||
NB. no odd numbers in police department (first department) |
NB. no odd numbers in police department (first department) |
||
rule3=. (#~ 0=2|{."1) rule2 |
#rule3=. (#~ 0=2|{."1) rule2 |
||
14 |
|||
rule3 |
rule3 |
||
2 3 7 |
2 3 7 |