View difference between Paste ID: JMmuca6m and V7SJNs94
SHOW: | | - or go back to the newest paste.
1
data State = LeftSide | LeftPeriod | AtSymbol | RightSide | RightPeriod | End
2
   
3
correctEmails pattern
4
    | isValid pattern = rawr LeftPeriod pattern
5
    | otherwise = 0
6
    where isValid str = all (\x -> elem x "abcde?@.") str
7
8
-- |
9
10
rawr :: State -> String -> Int
11
 
12
rawr End [] = 1
13
rawr _ [] = 0
14
15
rawr state ('?':xs) = sum [rawr state (y:xs) | y <- (allowedChars state)] + 5 * rawr state ('a':xs)
16
17
rawr LeftSide ('@':xs) = rawr AtSymbol xs
18
rawr LeftSide ('.':xs) = rawr LeftPeriod xs
19
rawr LeftSide ( _ :xs) = rawr LeftSide xs
20
21
rawr LeftPeriod ('@': xs) = 0
22
rawr LeftPeriod ('.': xs) = 0
23
rawr LeftPeriod ( _ : xs) = rawr LeftSide xs
24
25
rawr AtSymbol ('@':xs) = 0
26
rawr AtSymbol ('.':xs) = 0
27
rawr AtSymbol ( _ :xs) = rawr RightSide xs
28
29
rawr RightSide ('@':xs) = 0
30
rawr RightSide ('.':xs) = rawr RightPeriod xs
31
rawr RightSide ( _ :xs) = rawr RightSide xs
32
 
33
rawr RightPeriod ('@':xs) = 0
34
rawr RightPeriod ('.':xs) = 0
35
rawr RightPeriod ( _ :xs) = rawr End xs
36
 
37
rawr End ('@':xs) = 0
38
rawr End ('.':xs) = rawr RightPeriod xs
39
rawr End ( _ :xs) = rawr End xs
40
 
41
-- |
42
 
43
allowedChars :: State -> [Char]
44
allowedChars LeftSide = "@."
45
allowedChars RightSide = "."
46
allowedChars End = "."
47
allowedChars _ = []