Guest User

Untitled

a guest
Jan 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. -- Expert System
  2. module ExpertSystem where
  3. import IOExts
  4.  
  5. perguntas :: [String]
  6.  
  7. r_escritorio :: [[String]]
  8. r_programacao :: [[String]]
  9. r_servidor :: [[String]]
  10. r_render_3d :: [[String]]
  11.  
  12. fazer_perguntas_aux :: [String] -> [String] -> IO [String]
  13. fazer_perguntas :: [String] -> [String]
  14. isMember :: [String] -> [[String]] -> Bool
  15. comparar :: [String] -> [ ([[String]], String) ] -> String
  16.  
  17. -- Nossas perguntas.
  18. perguntas = [
  19. "Qual a sua cpu?\n[0] < 500 Mhz\n[1] >= 500 Mhz\n", -- x <- [0,1]
  20. "Qual a quantidade de memoria RAM?\n[0] < 128 MB\n[1] 128~512MB\n[2] > 512MB\n", -- y <- [0,1,2]
  21. "Qual o barramento da sua placa VGA?\n[0] < 128 bits\n[1] >= 128 bits\n", -- z <- [0,1]
  22. "Qual o tamanho do seu HD?\n[0] < 80 GB\n[1] >= 80 GB\n"] -- t <- [0,1]
  23.  
  24. -- Nossa Base de dados.
  25. r_escritorio = [ [x,y,z,t] | x <- ["0","1"], y <- ["0","1","2"], z <- ["0","1"], t <- ["0","1"], x == "0", y == "0" || y == "1" ]
  26. r_programacao = [ ["0","2","0","0"], ["1","0","0","0"], ["1","0","1","0"], ["1","1","0","0"], ["1","2","0","0"] ]
  27. r_servidor = [ ["0","2","0","1"], ["1","0","0","1"], ["1","0","1","1"], ["1","1","0","1"], ["1","2","0","1"] ]
  28. r_render_3d = [ ["0","2","1","0"], ["0","2","1","1"], ["1","1","1","0"], ["1","1","1","1"], ["1","2","1","0"], ["1","2","1","1"] ]
  29.  
  30. -- Funcao auxiliar para entrada e saida, necessita converter ainda (IO String par String).
  31. fazer_perguntas_aux [] res = return res
  32.  
  33. fazer_perguntas_aux (h:tail) res = do
  34. putStr (h)
  35. r <- getLine
  36. fazer_perguntas_aux tail (res ++ [r])
  37.  
  38. -- onde 'x' sao as perguntas. (converter 'IO String' para 'String')
  39. -- isto gera o vetor de respostas do usuario.
  40. fazer_perguntas x = unsafePerformIO ( fazer_perguntas_aux x [])
  41.  
  42. -- Verifica se um elemente pertence ao conjuto
  43. isMember a conjunto = [ x | x <- conjunto, x == a ] /= []
  44.  
  45. -- compara as respostas com a base de dados
  46. comparar r [] = "Inconclusivo, voce respondeu corretamente?"
  47.  
  48. comparar r (h:tail)
  49. | isMember r (fst h) = (snd h)
  50. | otherwise = comparar r tail
  51.  
  52. main = do
  53. putStr(comparar (fazer_perguntas perguntas) [
  54. (r_escritorio ,"Uso recomendado: Escritorio\n"),
  55. (r_programacao,"Uso recomendado: Programacao\n"),
  56. (r_servidor ,"Uso recomendado: Servidor\n"),
  57. (r_render_3d ,"Uso recomendado: Renderizacao 3D\n")])
Add Comment
Please, Sign In to add comment