summary refs log tree commit diff
diff options
context:
space:
mode:
authortzlil <tzlils@protonmail.com>2023-09-16 05:03:03 +0300
committertzlil <tzlils@protonmail.com>2023-09-16 05:03:03 +0300
commit1829780f565aa82fa88573de9c76b878d1f28a0d (patch)
treeb0f92dc26419031bddca3608d12bd983cd60153d
solved 2 logic puzzles
-rw-r--r--puzz1.hs45
-rw-r--r--puzz2.hs44
2 files changed, 89 insertions, 0 deletions
diff --git a/puzz1.hs b/puzz1.hs
new file mode 100644
index 0000000..df54886
--- /dev/null
+++ b/puzz1.hs
@@ -0,0 +1,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
+
diff --git a/puzz2.hs b/puzz2.hs
new file mode 100644
index 0000000..7d933a8
--- /dev/null
+++ b/puzz2.hs
@@ -0,0 +1,44 @@
+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
+