summary refs log tree commit diff
path: root/puzz2.hs
blob: fd5d2a59070c3ff3bea3e7f1328661489ac4b2e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
  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