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.
::* Baker does not live on the top floor.
::* Cooper does not live on the bottom floor.
::* Fletcher does not live on either the top or the bottom floor.
::* Miller lives on a higher floor than does Cooper.
::* Smith does not live on a floor adjacent to Fletcher's.
::* Fletcher does not live on a floor adjacent to Cooper's.
<code>permutations</code> is defined at [[Permutations#Quackery]].
<syntaxhighlight lang="Quackery"> [
[ 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
[ - 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
smith fletcher adjacent exclude
fletcher cooper adjacent exclude
|