milkywayw icon

Untitled

milkywayw | PRO | 09/17/19 09:54:24 PM UTC | 0 ⭐ | 12325 👁️ | Never ⏰ | []
Haskell |

1.21 KB

|

None

|

0 👍

/

0 👎

data State = LeftSide | LeftPeriod | AtSymbol | RightSide | RightPeriod | End
   
correctEmails pattern
    | isValid pattern = rawr LeftPeriod pattern
    | otherwise = 0
    where isValid str = all (\x -> elem x "abcde?@.") str
 
-- |
 
rawr :: State -> String -> Int
 
rawr End [] = 1
rawr _ [] = 0
 
rawr state ('?':xs) = sum [rawr state (y:xs) | y <- (allowedChars state)] + 5 * rawr state ('a':xs)
 
rawr LeftSide ('@':xs) = rawr AtSymbol xs
rawr LeftSide ('.':xs) = rawr LeftPeriod xs
rawr LeftSide ( _ :xs) = rawr LeftSide xs
 
rawr LeftPeriod ('@': xs) = 0
rawr LeftPeriod ('.': xs) = 0
rawr LeftPeriod ( _ : xs) = rawr LeftSide xs
 
rawr AtSymbol ('@':xs) = 0
rawr AtSymbol ('.':xs) = 0
rawr AtSymbol ( _ :xs) = rawr RightSide xs
 
rawr RightSide ('@':xs) = 0
rawr RightSide ('.':xs) = rawr RightPeriod xs
rawr RightSide ( _ :xs) = rawr RightSide xs
 
rawr RightPeriod ('@':xs) = 0
rawr RightPeriod ('.':xs) = 0
rawr RightPeriod ( _ :xs) = rawr End xs
 
rawr End ('@':xs) = 0
rawr End ('.':xs) = rawr RightPeriod xs
rawr End ( _ :xs) = rawr End xs
 
-- |
 
allowedChars :: State -> [Char]
allowedChars LeftSide = "@."
allowedChars RightSide = "."
allowedChars End = "."
allowedChars _ = []

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎