Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Char
- --Main Funktion
- function :: [String] -> (Int -> Int) -> [Int]
- function [] _ = []
- function (x:xs) f | "old" `sublist` x = f (getInt x) : function xs f
- | "new" `sublist` x = getInt x : function xs f
- where
- sublist :: String -> String -> Bool
- sublist xs@(x:s) (y:s') = if x == y then sublist s s' || sublist xs s' else sublist xs s'
- sublist [] _ = True
- sublist _ [] = False
- getInt :: String -> Int
- getInt xs = calcVal $ getIntList xs
- calcVal :: [Int] -> Int
- calcVal [] = 0
- calcVal (x:xs) = x * 10^(length xs) + calcVal xs
- getIntList :: String -> [Int]
- getIntList [] = []
- getIntList (x:xs) = if isDigit x then digitToInt x : getIntList xs else getIntList xs
- --TestWerte
- chaos =["old price: 40", "new price: 21", "old price: 29", "old price: 50", "new price: 101"]
- discount :: Int -> Int
- discount x
- | x <= 20 = (x * 8) `div` 10
- | x <= 50 = (x * 6) `div` 10
- | otherwise = (x * 4) `div` 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement