Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
import Data.List (permutations)
|
||||
import Control.Monad (guard)
|
||||
|
||||
dinesman :: [(Int,Int,Int,Int,Int)]
|
||||
dinesman = do
|
||||
-- baker, cooper, fletcher, miller, smith are integers representing
|
||||
-- the floor that each person lives on, from 1 to 5
|
||||
|
||||
-- Baker, Cooper, Fletcher, Miller, and Smith live on different floors
|
||||
-- of an apartment house that contains only five floors.
|
||||
[baker, cooper, fletcher, miller, smith] <- permutations [1..5]
|
||||
|
||||
-- Baker does not live on the top floor.
|
||||
guard $ baker /= 5
|
||||
|
||||
-- Cooper does not live on the bottom floor.
|
||||
guard $ cooper /= 1
|
||||
|
||||
-- Fletcher does not live on either the top or the bottom floor.
|
||||
guard $ fletcher /= 5 && fletcher /= 1
|
||||
|
||||
-- Miller lives on a higher floor than does Cooper.
|
||||
guard $ miller > cooper
|
||||
|
||||
-- Smith does not live on a floor adjacent to Fletcher's.
|
||||
guard $ abs (smith - fletcher) /= 1
|
||||
|
||||
-- Fletcher does not live on a floor adjacent to Cooper's.
|
||||
guard $ abs (fletcher - cooper) /= 1
|
||||
|
||||
-- Where does everyone live?
|
||||
return (baker, cooper, fletcher, miller, smith)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
print $ head dinesman -- print first solution: (3,2,4,5,1)
|
||||
print dinesman -- print all solutions (only one): [(3,2,4,5,1)]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import Data.List (permutations)
|
||||
|
||||
main :: IO ()
|
||||
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, c, f, m, s] <- permutations [1 .. 5],
|
||||
b /= 5,
|
||||
c /= 1,
|
||||
f /= 1,
|
||||
f /= 5,
|
||||
m > c,
|
||||
abs (s - f) > 1,
|
||||
abs (c - f) > 1
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue