Lab2_PF
unknown
plain_text
3 years ago
2.6 kB
12
Indexable
--Exercitiul 1
poly2 :: Double -> Double -> Double -> Double -> Double
poly2 x a b c = a * x * x + b * x + c
--Exercitiul 2
eeny :: Integer -> String
eeny x
| even x = "eeny"
| otherwise = "meeny"
--Exercitiul 3
fizzbuzz :: Integer -> String
fizzbuzz x
| x `mod` 15 == 0 = "FizzBuzz"
| x `mod` 3 == 0 = "Fizz"
| x `mod` 5 == 0 = "Buzz"
| otherwise = ""
fizzbuzz' :: Integer -> String
fizzbuzz' x = if(mod x 15 == 0) then "FizzBuzz"
else if(mod x 3 == 0) then "Fizz"
else if(mod x 5 == 0) then "Buzz"
else ""
fibonacciCazuri :: Integer -> Integer
fibonacciCazuri n
| n < 2 = n
| otherwise = fibonacciCazuri (n - 1) + fibonacciCazuri (n - 2)
fibonacciEcuational :: Integer -> Integer
fibonacciEcuational 0 = 0
fibonacciEcuational 1 = 1
fibonacciEcuational n =
fibonacciEcuational (n - 1) + fibonacciEcuational (n - 2)
tribonacciCazuri :: Integer -> Integer
tribonacciCazuri n
| n < 1 = 0
| n <= 2 && n >= 1 = 1
| otherwise = tribonacciCazuri(n-1) + tribonacciCazuri(n-2) + tribonacciCazuri(n-3)
tribonacciEcuational :: Integer -> Integer
tribonacciEcuational 0 = 0
tribonacciEcuational 1 = 1
tribonacciEcuational 2 = 1
tribonacciEcuational 3 = 2
tribonacciEcuational n = tribonacciEcuational(n-1) +tribonacciEcuational(n-2) +tribonacciEcuational(n-3)
binomial :: Integer -> Integer -> Integer
binomial n k
| k == 0 = 1
| n == 0 = 0
| otherwise = (binomial (n - 1) k) + (binomial (n - 1) (k - 1))
verifL :: [Int] -> Bool
verifL v
| mod (length v) 2 == 0 = True
| otherwise = False
takefinal :: [a] -> Int -> [a]
takefinal v n
| (length v) <= n = v
| otherwise = drop ((length v) - n) v
remove :: [Int] -> Int -> [Int]
remove v n = concat[(take (n - 1) v), (drop (n) v)]
-- semiPareRec [0,2,1,7,8,56,17,18] == [0,1,4,28,9]
semiPareRec :: [Int] -> [Int]
semiPareRec [] = []
semiPareRec (h:t)
| even h = h `div` 2 : t'
| otherwise = t'
where t' = semiPareRec t
myreplicate :: Int -> a -> [a]
myreplicate n v
| n == 0 = []
| otherwise = v:myreplicate (n - 1) v
sumImp :: [Int] -> Int
sumImp [] = 0
sumImp (h:t)
| mod h 2 == 1 = h + t'
| otherwise = t'
where t' = sumImp t
totalLen :: [String] -> Int
totalLen [] = 0
totalLen (h:t)
| take 1 h == "A" = (length h) + t'
| otherwise = t'
where t' = totalLen t
Editor is loading...