Anonymous user
Dinesman's multiple-dwelling problem: Difference between revisions
Dinesman's multiple-dwelling problem (view source)
Revision as of 16:34, 21 September 2020
, 3 years ago→{{header|REXX}}: simplified the code.
m (→{{header|REXX}}: edlided a duplicate variable name, simplified a statement.) |
m (→{{header|REXX}}: simplified the code.) |
||
Line 3,251:
The "rules" that contain '''==''' could be simplified to '''=''' for readability.
<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;
sols=
do j=1
do k=j+1 to floors /*see if any people live on same floor.*/
if a==@.k then
call Waldo
end
end
end
▲ end /*!.3*/
say 'found ' sols " solution"s(sols). /*display the number of solutions found*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
set: do p=1 for #tenants; call value word(names, p), @.p; end; return
s: if arg(1)=1 then return ''; return "s" /*a simple pluralizer function.*/
th: arg x; x=abs(x); return word('th st nd rd', 1 +x// 10* (x//100%10\==1)*(x//10<4))
Line 3,291 ⟶ 3,290:
sols= sols + 1 /* [↑] "|" is REXX's "or" comparator.*/
say; do p=1 for #tenants; tenant= word(names, p)
say right(tenant, 35) 'lives on the'
end /*p*/ /* [↑] "||" is REXX's concatenation. */
return /* [↑] show tenants in order in NAMES.*/</lang>
|