mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 11:09:07 +01:00
13 lines
354 B
Haskell
13 lines
354 B
Haskell
module Codewars.Kata.XO where
|
|
|
|
import Data.Char
|
|
|
|
-- | Returns true if the number of
|
|
-- Xs is equal to the number of Os
|
|
-- (case-insensitive)
|
|
xo :: String -> Bool
|
|
xo str = xs == os
|
|
where counter (x, o) 'x' = (x + 1, o)
|
|
counter (x, o) 'o' = (x, o + 1)
|
|
counter counts _ = counts
|
|
(xs, os) = foldl counter (0, 0) $ map toLower str
|