Department numbers: Difference between revisions
Content added Content deleted
(→{{header|Modula-2}}: Added MiniScript) |
(Add MATLAB implementation) |
||
Line 2,972: | Line 2,972: | ||
<pre>{{2, 3, 7}, {2, 4, 6}, {2, 6, 4}, {2, 7, 3}, {4, 1, 7}, {4, 2, 6}, {4, 3, 5}, {4, 5, 3}, |
<pre>{{2, 3, 7}, {2, 4, 6}, {2, 6, 4}, {2, 7, 3}, {4, 1, 7}, {4, 2, 6}, {4, 3, 5}, {4, 5, 3}, |
||
{4, 6, 2}, {4, 7, 1}, {6, 1, 5}, {6, 2, 4}, {6, 4, 2}, {6, 5, 1}}</pre> |
{4, 6, 2}, {4, 7, 1}, {6, 1, 5}, {6, 2, 4}, {6, 4, 2}, {6, 5, 1}}</pre> |
||
=={{header|MATLAB}}== |
|||
<syntaxhighlight lang="MATLAB"> |
|||
% Execute the functions |
|||
clear all;close all;clc; |
|||
sol = findsolution(); |
|||
disp(table(sol(:, 1), sol(:, 2), sol(:, 3), 'VariableNames',{'Pol.','Fire','San.'})) |
|||
function sol = findsolution() |
|||
rng = 1:7; |
|||
sol = []; |
|||
for p = rng |
|||
for f = rng |
|||
for s = rng |
|||
if p ~= s && s ~= f && f ~= p && p + s + f == 12 && mod(p, 2) == 0 |
|||
sol = [sol; p s f]; |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Pol. Fire San. |
|||
____ ____ ____ |
|||
2 7 3 |
|||
2 6 4 |
|||
2 4 6 |
|||
2 3 7 |
|||
4 7 1 |
|||
4 6 2 |
|||
4 5 3 |
|||
4 3 5 |
|||
4 2 6 |
|||
4 1 7 |
|||
6 5 1 |
|||
6 4 2 |
|||
6 2 4 |
|||
6 1 5 |
|||
</pre> |
|||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |