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
44
45
|
import Prelude
import Control.Monad
import Data.List
data Spider = Darkback | RaftSpider | WhipSpider | WolfSpider deriving (Eq,Show)
data Winner = Anthony | Georgia | Olga | Rafael deriving (Eq,Show)
type Price = Integer
-- triple pairing
data Tripling = Tripling { spider :: Spider, winner :: Winner, price :: Price } deriving (Show)
spiders = [Darkback, RaftSpider, WhipSpider, WolfSpider]
winners = [Anthony, Georgia, Olga, Rafael]
prices = [45, 60, 75, 90]
-- 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@[darkback, raft, whip, _] <- [zipWith3 Tripling spiders wns prs
| wns <- permutations winners
, prs <- permutations prices]
-- clue 1
Just georgia <- [find (\x -> winner x == Georgia) solution]
guard (price raft == ((price georgia) - 15))
-- clue 2
Just anthony <- [find (\x -> winner x == Anthony) solution]
guard (price darkback < price anthony)
-- clue 3
guard (spider anthony == RaftSpider)
-- clue 4
Just olga <- [find (\x -> winner x == Olga) solution]
guard (spider olga == WhipSpider || price olga == 90)
-- clue 5
guard ((price whip + 15) == price darkback)
return solution
|