Exactly three adjacent 3 in lists: Difference between revisions

m
Line 93:
=={{header|Haskell}}==
<lang haskell>import Data.Bifunctor (bimap)
import Data.List (elemIndexspan)
 
nnPeers :: Int -> [Int] -> Bool
nnPeers n xs = maybe False go (elemIndex n xs)
uncurry (&&) $
bimap
(notp . any plength)
(not . any p)
(span p (dropWhile (not . p) xs))
where
p x = (n ==) x
go i =
uncurry (&&) $
bimap
(((&&) . p . length) <*> all p)
(not . any p)
(splitAt n (drop i xs))
 
--------------------------- TEST -------------------------
9,655

edits