Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Expert System
- module ExpertSystem where
- import IOExts
- perguntas :: [String]
- r_escritorio :: [[String]]
- r_programacao :: [[String]]
- r_servidor :: [[String]]
- r_render_3d :: [[String]]
- fazer_perguntas_aux :: [String] -> [String] -> IO [String]
- fazer_perguntas :: [String] -> [String]
- isMember :: [String] -> [[String]] -> Bool
- comparar :: [String] -> [ ([[String]], String) ] -> String
- -- Nossas perguntas.
- perguntas = [
- "Qual a sua cpu?\n[0] < 500 Mhz\n[1] >= 500 Mhz\n", -- x <- [0,1]
- "Qual a quantidade de memoria RAM?\n[0] < 128 MB\n[1] 128~512MB\n[2] > 512MB\n", -- y <- [0,1,2]
- "Qual o barramento da sua placa VGA?\n[0] < 128 bits\n[1] >= 128 bits\n", -- z <- [0,1]
- "Qual o tamanho do seu HD?\n[0] < 80 GB\n[1] >= 80 GB\n"] -- t <- [0,1]
- -- Nossa Base de dados.
- 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" ]
- r_programacao = [ ["0","2","0","0"], ["1","0","0","0"], ["1","0","1","0"], ["1","1","0","0"], ["1","2","0","0"] ]
- r_servidor = [ ["0","2","0","1"], ["1","0","0","1"], ["1","0","1","1"], ["1","1","0","1"], ["1","2","0","1"] ]
- 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"] ]
- -- Funcao auxiliar para entrada e saida, necessita converter ainda (IO String par String).
- fazer_perguntas_aux [] res = return res
- fazer_perguntas_aux (h:tail) res = do
- putStr (h)
- r <- getLine
- fazer_perguntas_aux tail (res ++ [r])
- -- onde 'x' sao as perguntas. (converter 'IO String' para 'String')
- -- isto gera o vetor de respostas do usuario.
- fazer_perguntas x = unsafePerformIO ( fazer_perguntas_aux x [])
- -- Verifica se um elemente pertence ao conjuto
- isMember a conjunto = [ x | x <- conjunto, x == a ] /= []
- -- compara as respostas com a base de dados
- comparar r [] = "Inconclusivo, voce respondeu corretamente?"
- comparar r (h:tail)
- | isMember r (fst h) = (snd h)
- | otherwise = comparar r tail
- main = do
- putStr(comparar (fazer_perguntas perguntas) [
- (r_escritorio ,"Uso recomendado: Escritorio\n"),
- (r_programacao,"Uso recomendado: Programacao\n"),
- (r_servidor ,"Uso recomendado: Servidor\n"),
- (r_render_3d ,"Uso recomendado: Renderizacao 3D\n")])
Add Comment
Please, Sign In to add comment