lab3
unknown
haskell
3 years ago
1.8 kB
9
Indexable
import Data.Char
vocaleCuv :: String -> Int
vocaleCuv "" = 0
vocaleCuv (h:t)
| elem h "aeiouAEIOU" = 1 + t'
| otherwise = t'
where t' = vocaleCuv t
nrVocale :: [String] -> Int
nrVocale [] = 0
nrVocale (h:t)
| h == reverse h = vocaleCuv h + t'
| otherwise = t'
where t' = nrVocale t
f :: Int -> [Int] -> [Int]
f val [] = []
f val (h:t)
| h `mod` 2 == 0 = h:val:t'
| otherwise = h:t'
where t' = f val t
divizori :: Int -> [Int]
divizori n = [n `div` x| x <- reverse [1..n], n `mod` x == 0]
listadiv :: [Int] -> [[Int]]
listadiv lista = [divizori k| k <- lista]
inIntervalComp::Int -> Int -> [Int] -> [Int]
inIntervalComp stg drp lis = [k | k <- lis, k >= stg, k <= drp]
inIntervalRec :: Int -> Int -> [Int] -> [Int]
inIntervalRec a b [] = []
inIntervalRec a b (h:t)
| a <= h && h <= b = h : t'
| otherwise = t'
where t' = inIntervalRec a b t
pozitiveComp :: [Int] -> Int
pozitiveComp l = length [k | k <- l, k > 0]
pozitiveRec :: [Int] -> Int
pozitiveRec [] = 0
pozitiveRec (h:t)
| h > 0 = 1 + t'
| otherwise = t'
where t' = pozitiveRec t
pozitiiImpareRec :: [Int] -> Int -> [Int]
pozitiiImpareRec [] a = []
pozitiiImpareRec (h:t) a
| odd h = a : t'
| otherwise = t'
where t' = pozitiiImpareRec t (a + 1)
numere = [0..]
pozitiiImpareComp :: [Int] -> [Int]
pozitiiImpareComp lista = [i | (i, x) <- zip numere lista, odd x]
multDigitsRec :: String -> Int
multDigitsRec "" = 1
multDigitsRec (h:t)
| isDigit h = (digitToInt h) * t'
| otherwise = t'
where t' = multDigitsRec t
multDigitsComp :: String -> Int
multDigitsComp sir = product [digitToInt k| k <- sir, isDigit k]
Editor is loading...