Jump to content

Exactly three adjacent 3 in lists: Difference between revisions

→‎{{header|Haskell}}: Settled for the simpler variant
(→‎{{header|Haskell}}: Settled for the simpler variant)
Line 45:
 
=={{header|Haskell}}==
<lang haskell>import Data.ListBifunctor (groupbimap)
import Data.List (elemIndex)
 
nnPeers :: Int -> [Int] -> Bool
nnPeers n xs = maybe False go (elemIndex n xs)
where
let p = (n ==)
in p (length= (filter pn xs)==)
go i && any=
uncurry ((&&) . p . length <*> any p)$
(group xs)bimap
(all p)
(not . any p)
(splitAt n (drop i xs))</lang>
 
--------------------------- TEST -------------------------
Line 73 ⟶ 77:
[1,2,3,4,5,6,7,8,9] -> False
[4,6,8,7,2,3,3,3,1] -> True</pre>
 
Or (same test and results):
 
<lang haskell>import Data.Bifunctor (bimap)
import Data.List (elemIndex)
 
nnPeers :: Int -> [Int] -> Bool
nnPeers n xs = maybe False go (elemIndex n xs)
where
p = (n ==)
go i =
uncurry (&&) $
bimap
(all p)
(not . any p)
(splitAt n (drop i xs))</lang>
 
=={{header|Julia}}==
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.