1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/7kyu/exes_and_ohs/solution.hs

14 lines
354 B
Haskell
Raw Permalink Normal View History

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