-
-
Save KirinDave/10c6c81fbb98536fd8d8 to your computer and use it in GitHub Desktop.
I might have coded it this way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char (isAlpha, toUpper) | |
import System.Environment (getArgs) | |
-- These are the correct answers we expect to see. | |
correctAnswers = "BDAACABACDBCDADCCBDA" | |
main = do | |
args <- getArgs -- We require 1 argument | |
cont <- readFile (head args) | |
let answers = filter isAlpha cont | |
theScore = score answers | |
in do putStr (grade theScore) | |
putStrLn $ " (Score was " ++ (show theScore) ++ ")" | |
score :: String -> Int | |
score = length . filter correct . zip correctAnswers . map toUpper | |
where correct p = fst p == snd p | |
grade :: Int -> String | |
grade score | |
| score >= 15 = "Passed" | |
| otherwise = "Failed" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BDAACABACDBCDADCCBDA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. B | |
2. D | |
3. A | |
4. A | |
5. C | |
6. A | |
7. A | |
8. A | |
9. C | |
10. D | |
11. B | |
12. C | |
13. D | |
14. A | |
15. D | |
16. C | |
17. C | |
18. B | |
19. D | |
20. A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To build:
ghc --make grader
To run:
./grader trickyInput.txt