Anonymous user
Department numbers: Difference between revisions
→{{header|zkl}}: re-write
(→{{header|Javascript}}: Added an ES5 version) |
(→{{header|zkl}}: re-write) |
||
Line 714:
=={{header|zkl}}==
<lang zkl>Utils.Helpers.pickNFrom(3,[1..7].walk()) // 35 combos
.filter(fcn(numbers){ numbers.sum(0)==12 })
.println();</lang>
{{output}}
Line 722 ⟶ 721:
L(L(1,4,7),L(1,5,6),L(2,3,7),L(2,4,6),L(3,4,5))
</pre>
Note: The sum of three odd numbers is odd, so a+b+c=12 means at least one even
For a table with repeated solutions:▼
nmber (1 even, two odd or 3 even). Futher, 2a+b=12, a,b in (2,4,6) has one
solution: a=2,b=4
▲For a table with repeated solutions using nested loops:
<lang zkl>println("Police Fire Sanitation");▼
foreach p,f,s in ([2..7,2], [1..7], [1..7])
{ if((p!=s!=f) and p+f+s==12) println(p,"\t",f,"\t",s) }</lang>
▲println("Police Fire Sanitation");
{{out}}
<pre>
Police Fire Sanitation
4 7 1▼
4 1 7▼
6 1 5▼
6 5 1▼
2 3 7
2 4 6
2 6 4
4 6 2▼
4 2 6
4 3 5
▲4 6 2
▲4 7 1
▲6 1 5
6 2 4
6 4 2
▲6 5 1
</pre>
|