Dinesman's multiple-dwelling problem: Difference between revisions

m
(Added 11l)
Line 1,856:
print dinesman -- print all solutions (only one): [(3,2,4,5,1)]</lang>
 
Or as a list comprehension (syntactic sugar for a list monad):
<lang haskell>import Data.List (permutations)
 
Line 1,862:
main =
print
[ ( "Baker lives on " ++<> show b,
, "Cooper lives on " ++<> show c,
, "Fletcher lives on " ++<> show f,
, "Miller lives on " ++<> show m,
, "Smith lives on " ++<> show s)
, b /= 5 )
| [b, c, f, m, s] <- permutations [1 .. 5] ,
, b /= 5
, c b /= 1 5,
, f c /= 1 ,
, f /= 5 1,
, m > c f /= 5,
, abs (s - f)m > 1 c,
, abs (cs - f) > 1 ]</lang>,
abs (c - f) > 1
]</lang>
{{out}}
<pre>[("Baker lives on 3","Cooper lives on 2","Fletcher lives on 4","Miller lives on 5","Smith lives on 1")]</pre>
9,655

edits