-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrainer.hs
More file actions
72 lines (62 loc) · 1.95 KB
/
trainer.hs
File metadata and controls
72 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Equation
import Regimen
import Data.Time (getCurrentTime, diffUTCTime)
import BlankCount
import EFA
import System.Environment (getArgs)
{- Project Goals
1. Get me more comfortable with doing basic math,
eliminating the gut reation of getting a calculator.
2. Give me some more experience with Haskell's type system.
3. Use multiple files.
4. Have easy to reason about command line arguemnts.
-}
numCorrect :: [Bool] -> [Char]
numCorrect xs = ("----" ++ (show correct) ++ " out of " ++ (show total) ++ "----")
where correct = length (filter true xs)
total = length xs
true b = b
train :: Regimen -> IO()
train regimen = do
equations <- genEquations regimen
start <- getCurrentTime
results <- etraining equations
end <- getCurrentTime
putStrLn $ numCorrect results
putStrLn ("Completed in " ++ (show (diffUTCTime end start)))
trainB :: BlankRegimen -> IO()
trainB regimen = do
start <- getCurrentTime
results <- bTraining regimen
end <- getCurrentTime
putStrLn $ numCorrect results
putStrLn ("Completed in " ++ (show (diffUTCTime end start)))
needsHelp :: [String] -> Bool
needsHelp xs = any (=="--help") xs
run :: [String] -> IO ()
run args = do
let rs = fromArgs args :: [Regimen]
let bs = fromArgs args :: [BlankRegimen]
mapM_ Main.trainB bs
mapM_ Main.train rs
-- Entry Point
main :: IO ()
main = do
putStrLn "Welcome to TRAINER.hs"
args <- getArgs
if (needsHelp args)
then putStrLn help
else run args
putStrLn "End"
-- Multi-line strings didn't work as I expect them to...
help :: [Char]
help = "the Arguments for TRAINER.hs are [-r <num-questions> <max-number> <1..4>]\n\
\the <1..4> represent the max operator to use\n\
\1 = +\n\
\2 = -\n\
\3 = *\n\
\4 = /\n\
\\n\
\if you give no arguments it just runs a defualt training regimen\n\
\to run the default it would look like\n\
\ trainer.exe -r 10 10 4 -r 10 50 2"