Created
December 15, 2018 22:25
-
-
Save luki/b7981ed41db3ba1ac714a22a5e3abc79 to your computer and use it in GitHub Desktop.
code snippet from the video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type State = Int | |
checkInput :: State -> String -> State | |
checkInput s [] = s | |
checkInput 0 (x:xs) | |
| x == 'j' = checkInput 1 xs | |
| x == 'p' = checkInput 0 xs | |
| x == 'g' = checkInput 0 xs | |
| otherwise = checkInput 0 xs | |
checkInput 1 (x:xs) | |
| x == 'j' = checkInput 1 xs | |
| x == 'p' = checkInput 2 xs | |
| x == 'g' = checkInput 0 xs | |
| otherwise = checkInput 0 xs | |
checkInput 2 (x:xs) | |
| x == 'j' = checkInput 1 xs | |
| x == 'p' = checkInput 0 xs | |
| x == 'g' = checkInput 3 xs | |
| otherwise = checkInput 0 xs | |
checkInput 3 (x:xs) | |
| x == 'j' = checkInput 1 xs | |
| x == 'p' = checkInput 0 xs | |
| x == 'g' = checkInput 0 xs | |
| otherwise = checkInput 0 xs | |
automatonAccepts :: String -> Bool | |
automatonAccepts str = 3 == checkInput 0 str | |
main = do | |
putStrLn . show $ automatonAccepts "jpg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment