Department numbers: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace.
(Add 8086 assembly)
m (→‎{{header|REXX}}: added/changed whitespace.)
Line 2,775:
do p=2 to 7 by 2 /*try numbers for the police department*/
do f=1 for 7 /* " " " " fire " */
do s=1 for 7; $= p + f +s s /* " " " " sanitation " */
if f\==p & s\==p & s\==f & $==12 then say center(p,6) center(f,5) center(s,10)
end /*s*/
Line 2,805:
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 . say 'police fire sanitation' /*obtaindisplay optionala argumentscrude fromtitle for the CLoutput.*/
if high=='' |do high=="," then high p=2 to 7 by 2 /*Not specified? Then use /*try numbers for the default.police department*/
if sum=='' | do sum= f=","1 thenfor 7 sum=12 /* " " /* " " " " fire " */
@pd do s=1 ' policefor '7; @fd $= p + f + s /* " fire " ; @sd=" " ' sanitation ' /*define" names of departments.*/
if f\==p & s\==p & s\==f & $==12 then say say center(@pdp, L6) center(@fdf, L5) center(@sds, L10)
@dept= ' department '; L=length(@dept) /*literal; and also its length*/
end /*SDs*/
#=0 /*initialize the number of solutions. */
end /*FDf*/
do PD=2 by 2 to high /*try numbers for the police department*/
end do FD=1 /*p*/ for high /* " /*stick "a fork in it, " " fire " we're all done. */</lang>
if FD==PD then iterate /*Same FD# & PD#? They must be unique.*/
if FD+PD>sum-1 then iterate PD /*Is sum too large? Try another PD#. */ /* ◄■■■■■■ optimizing code*/
do SD=1 for high /*try numbers for the sanitation dept. */
if SD==PD | SD==FD then iterate /*Is SD# ¬unique? They must be unique,*/
$=PD+FD+SD /*compute sum of department numbers. */
if $> sum then iterate FD /*Is the sum too high? Try another FD#*/ /* ◄■■■■■■ optimizing code*/
if $\==sum then iterate /*Is the sum ¬correct? " " SD#*/
#=# + 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('', L, "═") center('', L, "═") center('', L, "═")
end
say center(PD, L) center(FD, L) center(SD, L) /*display a solution.*/
end /*SD*/
end /*FD*/
end /*PD*/
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=&nbsp; when using the default inputs:}}
<pre>
Line 2,855 ⟶ 2,834:
6 5 1
 
14 solutions found.
</pre>