27 lines
971 B
Text
27 lines
971 B
Text
( Baker Cooper Fletcher Miller Smith:?people
|
|
& ( constraints
|
|
=
|
|
. !arg
|
|
: ~(? Baker)
|
|
: ~(Cooper ?)
|
|
: ~(Fletcher ?|? Fletcher)
|
|
: ? Cooper ? Miller ?
|
|
: ~(? Smith Fletcher ?|? Fletcher Smith ?)
|
|
: ~(? Cooper Fletcher ?|? Fletcher Cooper ?)
|
|
)
|
|
& ( solution
|
|
= floors persons A Z person
|
|
. !arg:(?floors.?persons)
|
|
& ( !persons:
|
|
& constraints$!floors
|
|
& out$("Inhabitants, from bottom to top:" !floors)
|
|
& ~ { The ~ always fails on evaluation. Here, failure forces Bracmat to backtrack and find all solutions, not just the first one. }
|
|
| !persons
|
|
: ?A
|
|
%?`person
|
|
(?Z&solution$(!floors !person.!A !Z))
|
|
)
|
|
)
|
|
& solution$(.!people)
|
|
| { After outputting all solutions, the lhs of the | operator fails. The rhs of the | operator, here an empty string, is the final result. }
|
|
);
|