Dinesman's multiple-dwelling problem: Difference between revisions

→‎{{header|Quackery}}: added commentary, improved solution
(→‎{{header|Quackery}}: added commentary, improved solution)
Line 3,900:
 
=={{header|Quackery}}==
 
This illustrates the idea that you can extend the language in the direction of the problem space.
 
<pre> baker top exclude
cooper bottom exclude
fletcher top
fletcher bottom or exclude
miller cooper higher require
smith fletcher adjacent exclude
fletcher cooper adjacent exclude</pre>
 
Is a restatement of the conditions of the problem with (1) noise words removed, (2) in postfix notation, and (3) recast as imperative rather than declarative.
 
::* &nbsp; Baker does not live on the top floor.
::* &nbsp; Cooper does not live on the bottom floor.
::* &nbsp; Fletcher does not live on either the top or the bottom floor.
::* &nbsp; Miller lives on a higher floor than does Cooper.
::* &nbsp; Smith does not live on a floor adjacent to Fletcher's.
::* &nbsp; Fletcher does not live on a floor adjacent to Cooper's.
 
 
<code>permutations</code> is defined at [[Permutations#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ tempstack ] share 0 peek ] is bakerperms.min ( --> n[ )
 
[ stack ] is perms.max ( --> [ )
 
forward is (perms)
 
[ over size
perms.min share > if
[ over temp take
swap nested join
temp put ]
over size
perms.max share < if
[ dup size times
[ 2dup i^ pluck
rot swap nested join
swap (perms) ] ]
2drop ] resolves (perms) ( [ [ --> )
 
[ perms.max put
1 - perms.min put
[] temp put
[] swap (perms)
temp take
perms.min release
perms.max release ] is perms ( [ a b --> [ )
 
[ dup size dup perms ] is permutations ( [ --> [ )
 
[ temp share 0 peek ] is baker ( --> n )
[ temp share 1 peek ] is cooper ( --> n )
[ temp share 2 peek ] is fletcher ( --> n )
Line 3,911 ⟶ 3,960:
[ 5 = ] is top ( n --> b )
[ 1 = ] is bottom ( n --> b )
[ > ] is above higher ( n n --> b )
[ - abs 1 = ] is adjacent ( n n --> b )
 
[ if ]done[ ] is exclude ( b --> )
[ not if ]done[ ] is require ( b --> )
[ temp share nested join ] is include ( [ --> [ )
 
Line 3,925 ⟶ 3,975:
fletcher top
fletcher bottom or exclude
cooper miller cooper above higher excluderequire
smith fletcher adjacent exclude
fletcher cooper adjacent exclude
1,496

edits