Add week 2 lab
This commit is contained in:
parent
51fb515dd2
commit
acc8123b11
1 changed files with 39 additions and 0 deletions
39
02-lab.hs
Normal file
39
02-lab.hs
Normal 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
|
Reference in a new issue