Minor cleanup (removing explicit fold)

This commit is contained in:
Martin Potier 2020-12-02 21:10:58 +02:00
parent f577913aa1
commit 8325c6e224
1 changed files with 1 additions and 5 deletions

View File

@ -42,17 +42,13 @@ eitherToMaybe :: Either a b -> Maybe b
eitherToMaybe (Right e) = Just e eitherToMaybe (Right e) = Just e
eitherToMaybe (Left _) = Nothing eitherToMaybe (Left _) = Nothing
match' :: Char -> Char -> Int
match' c1 c2 | c1 == c2 = 1
match' _ _ = 0
-- How many passwords are valid according to their policies? -- How many passwords are valid according to their policies?
validatePassword1 :: Input -> Bool validatePassword1 :: Input -> Bool
validatePassword1 (Input min' max' char' pass) = validatePassword1 (Input min' max' char' pass) =
c >= min' && c <= max' c >= min' && c <= max'
where where
c = foldl (\acc c' -> acc + match' char' c') 0 pass c = (length . filter (== char')) pass
-- How many passwords are valid according to the new interpretation of the -- How many passwords are valid according to the new interpretation of the
-- policies? -- policies?