-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.hs
21 lines (17 loc) · 790 Bytes
/
02.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Data.Char
import Data.List
main = do
input <- getContents
let parsed_input = map transform $ lines input
where
transform = filter (any isAlphaNum) . groupBy of_same_char_category
of_same_char_category = (\x y -> generalCategory x == generalCategory y)
let a = length . filter char_count_in_limit $ parsed_input
where
char_count_in_limit [min, max, char, string] = count_char_in_word char string `elem` [read min .. read max]
count_char_in_word c word = length . filter (== head c) $ word
print a
let x = length . filter password_valid $ parsed_input
where
password_valid [min, max, char, string] = length (filter (== head char) [string !! (read min -1), string !! (read max -1)]) == 1
print x