Dinesman's multiple-dwelling problem: Difference between revisions

m
→‎{{header|REXX}}: added whitespace, aligned statements, added comments.
m (added whitespace.)
m (→‎{{header|REXX}}: added whitespace, aligned statements, added comments.)
Line 3,253:
<lang rexx>/*REXX program solves the Dinesman's multiple─dwelling problem with "natural" wording.*/
names= 'Baker Cooper Fletcher Miller Smith' /*names of multiple─dwelling tenants. */
tenants= words(names) /*the number of tenants in the building*/
floors=5; top=floors; bottom=1; #=floors; /*floor 1 is the ground (bottom) floor.*/
sols= 0 /*the number of solutions found so far.*/
sols= 0
do !.1=1 for # /*iterate through all floors for rules.*/
do !.2=1 for # /* " " " " " " */
do !.3=1 for # /* " " " " " " */
do !.4=1 for # /* " " " " " " */
do !.5=1 for # /* " " " " " " */
do p=1 for tenants; _= word(names,p); upper _; call value _, !.p
end /*p*/
 
do j=1 for #-1 /* [↓] people don't live on same floor*/
do do k=j+=1 to for # -1 /*see if[↓] any people don't live on same floor.*/
do if !.j==!.k=j+1 thento # iterate !.5 /*cohab?see if any people live Thenon notsame validfloor.*/
if !.j==!.k then iterate !.5 end /*kcohab? Then not valid.*/
end end /*jk*/
call Waldo end /* ◄══ where the rubber meets the road.j*/
 
end /*!.5*/
end call Waldo /*! ◄══ where the rubber meets the road.4*/
end end /*!.35*/
end end /*!.24*/
end end /*!.13*/
end end /*!.52*/
end /*!.1*/
 
say 'found' sols "solution"s(sols). /*display the number of solutions found*/
Line 3,283 ⟶ 3,285:
Waldo: if Baker == top then return
if Cooper == bottom then return
if Fletcher == bottom | Fletcher == top then return /*| ≡ "or".*/
if Miller \> Cooper then return
if Smith == Fletcher -1 | Smith == Fletcher +1 then return