Add week 2 lab

This commit is contained in:
akp 2023-10-11 10:24:15 +01:00
parent 51fb515dd2
commit acc8123b11
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

39
02-lab.hs Normal file
View file

@ -0,0 +1,39 @@
import Data.Char
orB :: Bool -> Bool -> Bool
orB x y = x || y
swap :: (x, y) -> (y, x)
swap (x, y) = (y, x)
middle :: [a] -> [a]
middle x = tail (take ((length x) - 1) x)
condrev :: [a] -> [a]
condrev x | (length x) >= 7 = reverse x
| otherwise = x
dblmagic :: [Int] -> [Int]
dblmagic x = filter (>10) (map (*2) x)
wtfstring :: String -> String
wtfstring x = reverse (map (toUpper) x)
addindex :: [a] -> [(Int, a)]
addindex x = zip [0..((length x) - 1)] x
relcmp :: (Num a, Ord a) => a -> a -> Bool
relcmp x y | x > y && x < (y*2) = True
| otherwise = False
third :: [a] -> a
-- third x = head (tail (tail x))
-- third x = x!!2
third (_:_:x:_) = x
safetail :: [a] -> [a]
-- safetail x = if (length x) == 0 then [] else tail x
-- safetail x | length x == 0 = []
-- | otherwise = tail x
safetail [] = []
safetail (_:xs) = xs