import Prelude import Control.Monad import Data.List data Customer = BetsyBeard | CoraCarey | DonnaDrake | EdwinEllis deriving (Eq,Show) type Size = Integer type Price = Integer -- triple pairing data Tripling = Tripling { customer :: Customer, size :: Size, price :: Price } deriving (Show) customers = [BetsyBeard, CoraCarey, DonnaDrake, EdwinEllis] prices = [550, 775, 1500, 2000] sizes = [55, 60, 65, 70] -- each solution is 4 triples type Solution = [Tripling] answers :: [Solution] answers = do -- spiders arent permutated so they will be in that order always, dont need to find them solution@[betsy, cora, donna, edwin] <- [zipWith3 Tripling customers szs prs | szs <- permutations sizes , prs <- permutations prices] -- Clue 1 Just twoThousand <- [find (\x -> price x == 2000) solution] Just fiveFifty <- [find (\x -> price x == 550) solution] guard (size twoThousand < size fiveFifty) -- Clue 2 guard (price donna == 550) -- Clue 3 Just fiftyFive <- [find (\x -> size x == 55) solution] guard (price fiftyFive == 775 || price fiftyFive == 550) -- Clue 4 guard (size cora == 70) -- Clue 5 guard (size edwin + 5 == size betsy) return solution