aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/asherbhs/haskell/ch-1.hs
blob: 54ef77e16c7eebccd07df0ae4170673c0eb8f9b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE MultiWayIf #-}

maxPositiveNegative :: [Int] -> Int
maxPositiveNegative ints =
  let
    (pos, neg) = foldr
        (\n (pos, neg) -> if
            | n > 0     -> (pos + 1, neg    )
            | n < 0     -> (pos,     neg + 1)
            | otherwise -> (pos,     neg    )
        )
        (0, 0)
        ints
  in
    max pos neg

main :: IO ()
main = do
    print $ maxPositiveNegative [-3, 1, 2, -1, 3, -2, 4]
    print $ maxPositiveNegative [-1, -2, -3, 1]
    print $ maxPositiveNegative [1, 2]