Zebra puzzle: Difference between revisions

Content deleted Content added
Line 1,107:
postCheck_ houses
| -- NOTE: list of houses is generated "from tail"
[White, Green] `isInfixOf` map color houses -- 5
, any ((==Blend) . smoke) $ nextTo`nextTo1` ((==Cats ) . pet) houses -- 11
, any ((==Dunhill) . smoke) $ nextTo`nextTo1` ((==Horse) . pet) houses -- 12
, any ((==Blue) . color) $ nextTo`nextTo1` ((==Nor ) . man) houses -- 15
, any ((==Blend) . smoke) $ nextTo`nextTo1` ((==Water).drink) houses -- 16
= return ()
| otherwise = mzero
where
| otherwise =nextTo1 go= xnextTo xshouses
 
nextTo :: [House] -> (House -> Bool) -> [(House] -> [House]Bool) -> Bool
-- premature optimization?
nextTo hs p (h:hs)q
nextTo :: (House -> Bool) -> [House] -> [House]
| (_:h:_) <- dropWhile (not . match) hs = match h
nextTo p (h:hs)
| potherwise h = take 1 hs = False
| otherwise = go h hs
where
gomatch prevh (x:xs)= p h || q h
</lang>
| p x = prev : take 1 xs
| otherwise = go x xs
go prev _ = [prev]
 
nextTo _ _ = []</lang>
{{out}}
<pre>House {color = Yellow, man = Nor, pet = Cats, drink = Water, smoke = Dunhill}