Skip to content

Instantly share code, notes, and snippets.

@thejsj
Last active May 4, 2016 18:03
Show Gist options
  • Save thejsj/a64e2ec994b5603c62f137e30d0e4240 to your computer and use it in GitHub Desktop.
Save thejsj/a64e2ec994b5603c62f137e30d0e4240 to your computer and use it in GitHub Desktop.
import Data.List.Split
import Data.Char
import Data.Maybe
import Text.Read
converToFloat :: String -> Maybe Float
converToFloat x = readMaybe x :: Maybe Float
convertStringsToFloats :: [String] -> [Float]
convertStringsToFloats x = map fromJust $ filter (not . null) $ map converToFloat x
splitIntoNumbers :: String -> [Float]
splitIntoNumbers x = convertStringsToFloats $ splitOn "," x
assignBonus :: Float -> Float
assignBonus x
| x <= 10000.0 = x * 0.03
| x <= 15000.0 = x * 0.06
| x <= 25000.0 = x * 0.09
| otherwise = x * 0.15
getBonusesForEmployess = (map assignBonus) . splitIntoNumbers
main = do
print "Sales?:"
input <- getLine
print "Result:"
print $ getBonusesForEmployess input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment