Dinesman's multiple-dwelling problem: Difference between revisions
Dinesman's multiple-dwelling problem (view source)
Revision as of 06:30, 5 October 2021
, 2 years ago→{{header|Haskell}}
Alextretyak (talk | contribs) (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 "
| [b, c, f, m, s] <- permutations [1 .. 5]
▲ , b /= 5
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>
|