Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.Char
  2.  
  3. --Main Funktion
  4. function :: [String] -> (Int -> Int) -> [Int]
  5. function [] _ = []
  6. function (x:xs) f | "old" `sublist` x = f (getInt x) : function xs f
  7.              | "new" `sublist` x = getInt x : function xs f
  8.     where
  9.         sublist :: String -> String -> Bool
  10.         sublist xs@(x:s) (y:s') = if x == y then sublist s s' || sublist xs s' else sublist xs s'
  11.         sublist [] _ = True
  12.         sublist _ [] = False
  13.  
  14.         getInt :: String -> Int
  15.         getInt xs = calcVal $ getIntList xs
  16.  
  17.         calcVal :: [Int] -> Int
  18.         calcVal [] = 0
  19.         calcVal (x:xs) = x * 10^(length xs) + calcVal xs
  20.  
  21.         getIntList :: String -> [Int]
  22.         getIntList [] = []
  23.         getIntList (x:xs) = if isDigit x then digitToInt x : getIntList xs else getIntList xs
  24.  
  25.  
  26. --TestWerte
  27. chaos =["old price: 40", "new price: 21", "old price: 29", "old price: 50", "new price: 101"]
  28.  
  29. discount :: Int -> Int
  30. discount x
  31.     | x <= 20 = (x * 8) `div` 10
  32.     | x <= 50 =  (x * 6) `div` 10
  33.     | otherwise = (x * 4) `div` 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement