Anonymous user
Dinesman's multiple-dwelling problem: Difference between revisions
Dinesman's multiple-dwelling problem (view source)
Revision as of 15:51, 21 September 2020
, 3 years ago→{{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)
floors=5; top=floors; bottom=1; #=floors
sols= 0 /*the number of solutions found so far.*/
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);
end /*p*/
do
do
if !.j==!.k then iterate !.5
end /*!.5*/▼
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
if Miller \> Cooper then return
if Smith == Fletcher -1 | Smith == Fletcher +1 then return
|