Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Task where
  2.  
  3. calc :: [Char] -> IO()
  4. calc x =  putStr (machine "" x "" 0 0 1)
  5.    
  6. machine :: [Char] -> [Char] -> [Char] -> Int -> Int -> Int -> [Char]
  7. machine answer (x:xs) subline state start current = case state of
  8.     0 -> case x of
  9.         '+' -> next answer "+" 6 current
  10.         _   -> next answer "" 0 0
  11.     1 -> case x of
  12.         'a' -> next answer (subline ++ "a") 2 start
  13.         'b' -> next answer (subline ++ "b") 3 start
  14.         'c' -> next answer (subline ++ "c") 4 start
  15.         '+' -> next answer "+" 1 current
  16.         _   -> next answer "" 0 0
  17.     2 -> case x of
  18.         'a' -> next answer (subline ++ "a") 2 start
  19.         '-' -> next answer (subline ++ "-") 1 start        
  20.         '+' -> next log "+" 5 current
  21.         _   -> next answer "" 0 0  
  22.     3 -> case x of
  23.         'b' -> next answer (subline ++ "b") 3 start
  24.         '-' -> next answer (subline ++ "-") 1 start        
  25.         '+' -> next log "+" 5 current
  26.         _   -> next answer "" 0 0  
  27.     4 -> case x of
  28.         'c' -> next answer (subline ++ "c") 4 start
  29.         '-' -> next answer (subline ++ "-") 1 start        
  30.         '+' -> next log "+" 5 current
  31.         _   -> next answer "" 0 0
  32.     5 -> case x of
  33.         'a' -> next answer (subline ++ "a") 2 start
  34.         'b' -> next answer (subline ++ "b") 3 start
  35.         'c' -> next answer (subline ++ "c") 4 start
  36.         '+' -> next log "+" 5 current
  37.         _   -> next answer "" 0 0
  38.     6 -> case x of
  39.         'a' -> next answer (subline ++ "a") 2 start
  40.         'b' -> next answer (subline ++ "b") 3 start
  41.         'c' -> next answer (subline ++ "c") 4 start
  42.         '+' -> next log "+" 5 current
  43.         _   -> next answer "" 0 0
  44.     _ -> "error"
  45.     where   next a b c d = case xs of
  46.                 [] -> a
  47.                 _ -> machine a xs b c d (current + 1)
  48.             log = answer ++ show start ++ "::" ++ show current ++ " " ++ subline ++ "+" ++ ['\n']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement