Untitled

 avatar
unknown
plain_text
2 years ago
2.5 kB
0
Indexable
--1
poly2 :: Integer -> Integer -> Integer -> Integer -> Integer
poly2 a b c x = a*x*x + b*x + c

--2
eeny :: Integer -> String
eeny x = if (even x)
        then "eeny"
        else "meeny"

--3
fizzbuzz :: Integer -> String
fizzbuzz x = if (x `mod` 15 == 0)
            then "FizzBuzz"
            else if (x `mod` 3 == 0)
            then "Fizz"
            else if (x `mod` 5 == 0)
            then "Buzz"
            else ""
{-
fizzbuzz x 
    | mod x 15 == 0 = "FizzBuzz"
    | mod x 3 == 0 = "Fizz"
    | mod x 5 == 0 = "Buzz"
    | otherwise = ""
-}

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)

--4
tribonacci :: Integer -> Integer
tribonacci n
    | n < 3 = 1
    | n == 3 = 2
    | otherwise = tribonacci (n - 1) + tribonacci (n - 2) + tribonacci (n - 3)

tribonacciEcuational :: Integer -> Integer
tribonacciEcuational 1 = 1
tribonacciEcuational 2 = 1
tribonacciEcuational 3 = 2
tribonacciEcuational n =
    tribonacciEcuational (n - 1) + tribonacciEcuational (n - 2) + tribonacciEcuational (n - 3)

--5
binomial :: Integer -> Integer -> Integer
binomial n k 
    | k == 0 = 1
    | n == 0 = 0
    | otherwise = binomial (n - 1) (k) + binomial (n - 1) (k - 1)

--6
verifL :: [Int] -> Bool
verifL lista = length (lista) `mod` 2 == 0

--7 
takefinal :: [Int] -> Int -> [Int]
takefinal lista n = if (length (lista) < n)
                    then lista
                    else
                    drop (length (lista) - n) lista

--8
remove :: [Int] -> Int -> [Int]
remove lista n = (take (n - 1) lista) ++ (drop (n) lista)


-- 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

--9
myreplicate :: Int -> Int -> [Int]
myreplicate 0 v = []
myreplicate n v = v : myreplicate (n - 1)(v)

--10
sumImp :: [Int] -> Int
sumImp [] = 0
sumImp (h:t)
    | even h = sumImp t
    | otherwise = h + t'
    where t' = sumImp t

totalLen :: [String] -> Int
totalLen [] = 0
totalLen (h:t)
    | (take 1 h) == ['A'] = length(h) + t'
    | otherwise = totalLen t
    where t' = totalLen t
Editor is loading...