~statianzo/sevenlangs

2fcd45110250db60053c8972bcac1e434353d778 — Jason Staten 7 months ago 1e82a2d master
day one logic style
1 files changed, 43 insertions(+), 0 deletions(-)

M haskell/DayOne.hs
M haskell/DayOne.hs => haskell/DayOne.hs +43 -0
@@ 1,4 1,5 @@
module DayOne where
import Control.Monad (guard)

-- How many different ways can you find to write allEven?



@@ 100,3 101,45 @@ maplayouts = [(al, mi, ga, tn, fl) |
-- [(Red,Green,Green,Blue,Blue),(Red,Blue,Blue,Green,Green),(Green,Red,Red,Blue,Blue),(Green,Blue,Blue,Red,Red),(Blue,Red,Red,Green,Green),(Blue,Green,Green,Red,Red)]
--

-- Haskell Wiki: Logic programming
-- https://wiki.haskell.org/Logic_programming_example


data USMap = USMap {
  alabama :: Color,
  florida :: Color,
  georgia :: Color,
  mississippi :: Color,
  tennessee :: Color
} deriving Show

maplayouts2 :: [USMap]
maplayouts2 = do
  al <- [Red, Blue, Green]
  fl <- [Red, Blue, Green]
  ga <- [Red, Blue, Green]
  ms <- [Red, Blue, Green]
  tn <- [Red, Blue, Green]

  guard $ ms /= tn
  guard $ ms /= al
  guard $ al /= tn
  guard $ al /= ms
  guard $ al /= ga
  guard $ al /= fl
  guard $ ga /= fl
  guard $ ga /= tn

  return $ USMap {
    alabama = al,
    florida = fl,
    georgia = ga,
    mississippi = ms,
    tennessee = tn
  }

-- >>> maplayouts2
-- [USMap {alabama = Red, florida = Blue, georgia = Green, mississippi = Green, tennessee = Blue},USMap {alabama = Red, florida = Green, georgia = Blue, mississippi = Blue, tennessee = Green},USMap {alabama = Blue, florida = Red, georgia = Green, mississippi = Green, tennessee = Red},USMap {alabama = Blue, florida = Green, georgia = Red, mississippi = Red, tennessee = Green},USMap {alabama = Green, florida = Red, georgia = Blue, mississippi = Blue, tennessee = Red},USMap {alabama = Green, florida = Blue, georgia = Red, mississippi = Red, tennessee = Blue}]
--