Skip to content

Instantly share code, notes, and snippets.

@luki
Created December 15, 2018 22:25
Show Gist options
  • Save luki/b7981ed41db3ba1ac714a22a5e3abc79 to your computer and use it in GitHub Desktop.
Save luki/b7981ed41db3ba1ac714a22a5e3abc79 to your computer and use it in GitHub Desktop.
code snippet from the video
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