Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created April 15, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KirinDave/10c6c81fbb98536fd8d8 to your computer and use it in GitHub Desktop.
Save KirinDave/10c6c81fbb98536fd8d8 to your computer and use it in GitHub Desktop.
I might have coded it this way.
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"
BDAACABACDBCDADCCBDA
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
@KirinDave
Copy link
Author

To build:
ghc --make grader

To run:
./grader trickyInput.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment