Advertisement
Vladi1442

Untitled

Aug 19th, 2022
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO()
  2. main = do
  3.     print $ "Hello world"
  4.     print $ "Let's go, let's do it!"
  5.  
  6. dominates f g xs = and [abs (f x) >= abs (g x) | x <- xs]
  7.  
  8. seriesSum :: Double -> Int -> Double
  9. seriesSum n x = [ s | i <- [1..n], s <- [x^i + fromIntegral (i^2) + 1]]
  10.  
  11. listOfIndexes lst = (\x -> [xi + 10 | xi <- lst, x == xi])
  12.  
  13. listOfIndexes :: Int -> [Int] -> [Int]
  14. listOfIndexes n xs = [ index | (x, index) <- zip xs [0..], x == n]
  15.  
  16. findNb :: Integer -> Integer
  17. findNb m = helper 1 2
  18.     where
  19.         helper :: Integer -> Integer -> Integer
  20.         helper cSum toAdd
  21.             | cSum > m = -1
  22.             | cSum == m = toAdd - 1
  23.             | otherwise = helper (cSum + toAdd*toAdd*toAdd) (toAdd+1)
  24.  
  25. kthNumber p xs = (\k -> if length filtered > k then error "No such number" else filtered!!(k-1))
  26.     where
  27.         filtered = filter p xs
  28.  
  29. applyEveryKth f k xs = helper 1 xs
  30.     where
  31.         helper :: Int -> [Int] -> [Int]
  32.         helper _ [] = []
  33.         helper i (x:xs)
  34.             | i == k = f x : helper 1 xs
  35.             | otherwise = x : helper (i+1) xs
  36.  
  37. speak :: String -> (Char -> String)
  38. speak str c = foldl (\ acc (pos, x) -> if x == c then acc ++ show pos else acc ++ [x]) [] $ zip str $ reverse [0 .. length str-1]
  39.  
  40. iterator f xs = helper xs
  41.     where
  42.         helper :: [Int] -> Bool
  43.         helper [] = True
  44.         helper (x:xs)
  45.             | null xs = True
  46.             | head xs == f x = helper xs
  47.             | otherwise = False
  48.  
  49. getIndices xs = (\x -> head [(pos1, pos2) | (x1, pos1) <- zip xs [0..], (x2, pos2) <- zip xs [0..], x = x1 + x2 && pos1 /= pos2])
  50.  
  51. removeEveryKth n xs = helper xs 1
  52.     where
  53.         helper :: [Int] -> Int -> [Int]
  54.         helper [] _ = []
  55.         helper (x:xs) index
  56.             | index == n = f x : helper xs 1
  57.             | otherwise = x : helper xs (index+1)
  58.  
  59. factorize :: Int -> [Int]
  60. factorize num = helper num 2
  61.     where
  62.         helper :: Int -> Int -> [Int]
  63.         helper 1 _ = []
  64.         helper leftover divs
  65.             | mod leftover divs == 0 = divs : helper (div leftover 10) divs
  66.             | otherwise = helper leftover (divs+1)
  67.  
  68. digits :: Int -> [Int]
  69. digits = map digitToInt
  70.  
  71. decreasing :: [Int] -> Bool
  72. decreasing [] = False
  73. decreasing xs = [ (pos1, pos2) | (pos1, pos2) <- zip xs [0..], pos1 /= pos2]
  74.  
  75. decDigits :: Int -> Bool
  76. decDigits n = decreasing (digits n) && nub (digits n) == digits n
  77.  
  78. isInteresting :: Int -> Bool
  79. isInteresting n = mod n (sum . map digitToInt . show) == 0
  80.  
  81. specialSum :: Int -> Int -> Int
  82. specialSum x y = [d | d <- [x..y], (elem '6' $ show d) && (mod (d-1) 4 == 0)]
  83.  
  84. onlyArithmetic :: [Int] -> Int
  85. onlyArithmetic xs = [ xss | xss <- xs, isArithmetic xs]
  86.  
  87. isArithmetic :: [Int] -> Bool
  88. isArithmetic xs = length xs > 2 && xs == take (length xs) [xs!!0, xs!!1 ..]
  89.  
  90. fact :: Int -> Int
  91. fact 0 = 1
  92. fact n = n * fact (n-1)
  93.  
  94. mySin :: Integer -> Integer
  95. mySin n x = ((-1)**n * x**(2*n+1)) / (fact $ fromIntegral (2*n+1)) + mySin (n-1) x
  96.  
  97. dominates :: (Int -> Int) -> (Int -> Int) -> [Int] -> Bool
  98. dominates f g xs = all (\x -> f x >= g x) xs
  99.  
  100. reverseOrdSuff :: Int -> Int
  101. reverseOrdSuff n = helper (div n 10) (mod n 10)
  102.     where
  103.         helper :: Int -> Int -> Int
  104.         helper 0 result = 0
  105.         helper leftover result
  106.             | mod leftover 10 > mod result 10 = helper (div leftover 10) (result * 10 + mod leftover 10)
  107.             | otherwise = False
  108.  
  109. sumUnique :: [Int] -> Int
  110. sumUnique = sum . map onlyUnique
  111.  
  112. onlyUnique :: [[Int]] -> Int
  113. onlyUnique = sum . concat . filter ((==1) . length) . group . sort
  114.  
  115. myPolynomial :: (Int -> Int) -> [Int] -> (Int -> Int)
  116. myPolynomial f ys = (\x -> sum [i * f(y * x) | (y, i) <- zip ys [1..]])
  117.  
  118. sumExpr :: (Num a) => (a -> a) -> [a] -> (a -> a)
  119. sumExpr f ys = (\x -> sum [y * f(x^i) | (y, i) <- zip ys [1..]])
  120.  
  121. upperBound :: (Ord a) => (a -> a) -> a -> (a -> a)
  122. upperBound f y = (\x -> max (f x) y)
  123.  
  124. getOddCompositionValue :: [(Int -> Int)] -> (Int -> Int)
  125. getOddCompositionValue fs = (\x -> foldr (\ f x -> f x) x [f | (f, i) <- zip fs [1..], odd i])
  126.  
  127.  
  128.  
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement