Facebook
From Capacious Tapir, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 77
  1. import System.IO
  2. import Control.Monad
  3. import Data.List
  4.  
  5. num :: String -> String -> Int
  6. num [] [] = 0
  7. num (x:xs) (y:ys)
  8.     | x == y = 1 + num xs ys
  9.     | otherwise = num xs ys
  10.  
  11. percentage key sub = (num key sub) `div` (genericLength key)
  12.  
  13. passOrFail :: (Fractional a) => a -> String
  14. passOrFail x
  15.     | x < 0.9 = "fail"
  16.     | otherwise = "pass"
  17.  
  18. main :: IO ()
  19. main = do
  20.     key <- getLine
  21.     putStrLn "You entered the key"
  22.     input_line <- getLine
  23.     let n = read input_line :: Int
  24.    
  25.     replicateM n $ do
  26.       str <- getLine
  27.       putStrLn "Bravo!"
  28.       let p = passOrFail $ percentage key str
  29.       putStrLn p
  30.       return ()
  31.     return ()