Department numbers: Difference between revisions
Content deleted Content added
Added PL/M |
→{{header|UNIX Shell}}: Add implementation |
||
Line 4,438:
6 5 1
</pre>
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
{{works with|Korn Shell}}
{{works with|Z Shell}}
<syntaxhighlight lang="bash">function main {
set -- Police Sanitation Fire
typeset -i pw=${#1} sw=${#2} fw=${#3}
printf '%s' "$1"
shift
printf '\t%s' "$@"
printf '\n'
for (( p=2; p<8; p+=2 )); do
for (( s=1; s<8; ++s )); do
if (( s == p )); then
continue
fi
(( f = 12 - p - s ))
if (( f == s || f == p || f < 1 || f > 7 )); then
continue
fi
printf "%${pw}d\t%${sw}d\t%${fw}d\n" "$p" "$s" "$f"
done
done
}
main "$@"</syntaxhighlight>
{{Out}}
<pre>Police Sanitation Fire
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>
=={{header|Visual Basic .NET}}==
|