Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main :: IO()
- main = do
- print $ "Hello world"
- print $ "Let's go, let's do it!"
- dominates f g xs = and [abs (f x) >= abs (g x) | x <- xs]
- seriesSum :: Double -> Int -> Double
- seriesSum n x = [ s | i <- [1..n], s <- [x^i + fromIntegral (i^2) + 1]]
- listOfIndexes lst = (\x -> [xi + 10 | xi <- lst, x == xi])
- listOfIndexes :: Int -> [Int] -> [Int]
- listOfIndexes n xs = [ index | (x, index) <- zip xs [0..], x == n]
- findNb :: Integer -> Integer
- findNb m = helper 1 2
- where
- helper :: Integer -> Integer -> Integer
- helper cSum toAdd
- | cSum > m = -1
- | cSum == m = toAdd - 1
- | otherwise = helper (cSum + toAdd*toAdd*toAdd) (toAdd+1)
- kthNumber p xs = (\k -> if length filtered > k then error "No such number" else filtered!!(k-1))
- where
- filtered = filter p xs
- applyEveryKth f k xs = helper 1 xs
- where
- helper :: Int -> [Int] -> [Int]
- helper _ [] = []
- helper i (x:xs)
- | i == k = f x : helper 1 xs
- | otherwise = x : helper (i+1) xs
- speak :: String -> (Char -> String)
- speak str c = foldl (\ acc (pos, x) -> if x == c then acc ++ show pos else acc ++ [x]) [] $ zip str $ reverse [0 .. length str-1]
- iterator f xs = helper xs
- where
- helper :: [Int] -> Bool
- helper [] = True
- helper (x:xs)
- | null xs = True
- | head xs == f x = helper xs
- | otherwise = False
- getIndices xs = (\x -> head [(pos1, pos2) | (x1, pos1) <- zip xs [0..], (x2, pos2) <- zip xs [0..], x = x1 + x2 && pos1 /= pos2])
- removeEveryKth n xs = helper xs 1
- where
- helper :: [Int] -> Int -> [Int]
- helper [] _ = []
- helper (x:xs) index
- | index == n = f x : helper xs 1
- | otherwise = x : helper xs (index+1)
- factorize :: Int -> [Int]
- factorize num = helper num 2
- where
- helper :: Int -> Int -> [Int]
- helper 1 _ = []
- helper leftover divs
- | mod leftover divs == 0 = divs : helper (div leftover 10) divs
- | otherwise = helper leftover (divs+1)
- digits :: Int -> [Int]
- digits = map digitToInt
- decreasing :: [Int] -> Bool
- decreasing [] = False
- decreasing xs = [ (pos1, pos2) | (pos1, pos2) <- zip xs [0..], pos1 /= pos2]
- decDigits :: Int -> Bool
- decDigits n = decreasing (digits n) && nub (digits n) == digits n
- isInteresting :: Int -> Bool
- isInteresting n = mod n (sum . map digitToInt . show) == 0
- specialSum :: Int -> Int -> Int
- specialSum x y = [d | d <- [x..y], (elem '6' $ show d) && (mod (d-1) 4 == 0)]
- onlyArithmetic :: [Int] -> Int
- onlyArithmetic xs = [ xss | xss <- xs, isArithmetic xs]
- isArithmetic :: [Int] -> Bool
- isArithmetic xs = length xs > 2 && xs == take (length xs) [xs!!0, xs!!1 ..]
- fact :: Int -> Int
- fact 0 = 1
- fact n = n * fact (n-1)
- mySin :: Integer -> Integer
- mySin n x = ((-1)**n * x**(2*n+1)) / (fact $ fromIntegral (2*n+1)) + mySin (n-1) x
- dominates :: (Int -> Int) -> (Int -> Int) -> [Int] -> Bool
- dominates f g xs = all (\x -> f x >= g x) xs
- reverseOrdSuff :: Int -> Int
- reverseOrdSuff n = helper (div n 10) (mod n 10)
- where
- helper :: Int -> Int -> Int
- helper 0 result = 0
- helper leftover result
- | mod leftover 10 > mod result 10 = helper (div leftover 10) (result * 10 + mod leftover 10)
- | otherwise = False
- sumUnique :: [Int] -> Int
- sumUnique = sum . map onlyUnique
- onlyUnique :: [[Int]] -> Int
- onlyUnique = sum . concat . filter ((==1) . length) . group . sort
- myPolynomial :: (Int -> Int) -> [Int] -> (Int -> Int)
- myPolynomial f ys = (\x -> sum [i * f(y * x) | (y, i) <- zip ys [1..]])
- sumExpr :: (Num a) => (a -> a) -> [a] -> (a -> a)
- sumExpr f ys = (\x -> sum [y * f(x^i) | (y, i) <- zip ys [1..]])
- upperBound :: (Ord a) => (a -> a) -> a -> (a -> a)
- upperBound f y = (\x -> max (f x) y)
- getOddCompositionValue :: [(Int -> Int)] -> (Int -> Int)
- getOddCompositionValue fs = (\x -> foldr (\ f x -> f x) x [f | (f, i) <- zip fs [1..], odd i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement