Anonymous user
Department numbers: Difference between revisions
m
→{{header|REXX}}: added/changed comments, changed header information.
m (→{{header|REXX}}: added the REXX language.) |
m (→{{header|REXX}}: added/changed comments, changed header information.) |
||
Line 53:
=={{header|REXX}}==
A little extra code was added to allow the specification for the high department number as well as the sum.
<lang rexx>/*REXX program finds/displays all possible variants of (3) department numbering puzzle.*/▼
if high=='' | high=="," then high= 7▼
if sum=='' | sum=="," then sum=12▼
#=0; @pd='police'; @fd="fire"; @sd='sanitation'▼
Also, extra code was added to nicely format a title (header) for the output, as well as displaying the number of solutions found.
▲<lang rexx>/*REXX program finds/displays all possible variants of (3) department numbering puzzle.*/
parse arg high sum . /*obtain optional arguments from the CL*/
▲if high=='' | high=="," then high= 7 /*Not specified? Then use the default.*/
▲if sum=='' | sum=="," then sum=12 /* " " " " " " */
do SD=1 for high▼
@dept= ' department '; L=length(@dept) /*literal; and also its length*/
#=0 /*initialize the number of solutions. */
do PD=2 by 2 to high /*try numbers for the police department*/
do FD=1 for high /* " " " " fire " */
if FD+PD>sum-1 then iterate PD /*Is sum too large? Try another PD#. */
if SD==PD | SD==FD then iterate /*Is SD# ¬unique? They must be unique,*/
if #==1 then say center('',Lpd,"═") center('',Lfd,"═") center('',Lsd,"═")▼
$=PD+FD+SD
if $> sum then iterate FD /*Is the sum too high? Try another FD#*/
end /*SD*/▼
if $\==sum then iterate /*Is the sum ¬correct? " " SD#*/
end /*FD*/▼
#=# + 1 /*bump the number of solutions (so far)*/
if #==1 then do /*Is this the 1st solution? Show hdr.*/
say center(@pd, L) center(@fd, L) center(@sd, L)
say copies(center( @dept, L)' ', 3)
say copies(center('number', L)' ', 3)
say center(PD, L) center(FD, L) center(SD, L) /*display a solution.*/
say /*display a blank line before the #sols*/
if #==0 then #= 'no' /*use a better word for bupkis. */
say # "solutions found." /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the default inputs:}}
<pre>
police fire sanitation
department department department
════════════ ════════════ ════════════
▲ 2 4 6
2
2
4
4
4
4
4 6
6
6
6 4 2
6 5 1
14 solutions found.
|