From a8698c40abe5f53593b0fe1e1a70db95cc1413c4 Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 7 Apr 2012 16:32:05 -0400 Subject: [PATCH] added questioner --- questioner.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 questioner.hs diff --git a/questioner.hs b/questioner.hs new file mode 100644 index 0000000..9b5d3c3 --- /dev/null +++ b/questioner.hs @@ -0,0 +1,26 @@ +import Ask +import System.Random.Shuffle +import Control.Applicative +import qualified System.IO.Strict as So +import System.Console.Readline +import Control.Monad +import Text.Printf + +questionPath = "/home/wes/haskell/Questioner/questions.json" +getQuestionFile = So.readFile questionPath + +getjust (Just a) = a + +main = do + questions <- ((shuffleM . (return . repeat)) <$> decodeQuestions <$> getQuestionFile) + q <- questions + foldM_ ask (0, 0) (join (join q)) where + ask (t, a) q = do + printf "Percent correct so far: %f\n" ((a/t)*100 :: Float) + print q + answer <- readline "> " + let isCorrect = (correct (getjust answer) q) + printf "%s is %s\n\n" (getjust answer) (show isCorrect) + case isCorrect of + (True) -> return $ (t+1, a+1) + (False) -> return (t+1, a) \ No newline at end of file