aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/asherbhs/haskell/ch-2.hs
blob: c4c37ee179d128eeef91d4ccacf0b5a9f079f1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
countEqualDivisible :: [Int] -> Int -> Int
countEqualDivisible ints k =
  let
    help :: [(Int, Int)] -> Int
    help [] = 0
    help ((x, i) : rest)
        = help rest
        + (length $ filter
            (\(y, j) -> x == y && (i `mod` k == 0 || j `mod` k == 0))
            rest
        )
  in
    help $ zip ints [0 ..]

main :: IO ()
main = do
    print $ countEqualDivisible [3, 1, 2, 2, 2, 1, 3] 2
    print $ countEqualDivisible [1, 2, 3]             1