Advertisement
Vladi1442

Untitled

Aug 10th, 2022
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Topic about lists
  2.  
  3. fact :: Int -> Int
  4. fact n = product [1..n]
  5.  
  6. hasElements :: [Int] -> Bool
  7. hasElements [] = False
  8. hasElements n = n /= []
  9.  
  10. hasElements' :: [Int] -> Bool
  11. hasElements' [] = False
  12. hasElements' n = length n /= 0
  13.  
  14. hasElements'' :: [Int] -> Bool
  15. hasElements'' [] = False
  16. hasElements'' n = not $ null n
  17.  
  18. hasElementsButWithMagic :: [Int] -> Bool
  19. hasElementsButWithMagic = not . null
  20.  
  21. myLengthPM :: [Int] -> Int
  22. myLengthPM [] = 0
  23. myLengthPM (_:xs) = 1 + myLength xs
  24.  
  25. myLengthNonPM :: [Int] -> Int
  26. myLengthNonPM [] = 0
  27. myLengthNonPM xs
  28.    | null xs = 0
  29.    | otherwise = 1 + (myLength $ tail xs)  
  30.  
  31. getClosedInterval :: Int -> Int -> [Int]
  32. getClosedInterval x y = [min x y .. max x y]
  33.  
  34. isInside :: Int -> Int -> Int -> [Int]
  35. isInside x y n = n `elem` [min x y .. max x y]
  36.  
  37. removeFirst :: Int -> [Int] -> [Int]
  38. removeFirst n (x:xs)
  39.    | x == n = removeFirst n xs
  40.    | otherwise = removeFirst n xs
  41.  
  42. removeAllRec :: Int -> [Int] -> [Int]
  43. removeAllRec n (x:xs)
  44.    | x == n = removeAllRec n xs
  45.    | otherwise = x : removeAllRec n xs
  46.  
  47. removeAllHOF :: Int -> [Int] -> [Int]
  48. removeAllHOF n xs = filter (\x -> x == n) xs
  49.  
  50. incrementByLC :: Int -> [Int] -> [Int]
  51. incrementByLC n xs = [n + x | x <- xs]
  52.  
  53. incrementByHOF :: Int -> [Int] -> [Int]
  54. incrementByHOF n xs = map (+n) xs
  55.  
  56. rev = read . reverse . show
  57. rev' n = read $ reverse $ show n
  58.  
  59. sumDivs n = sum [d | d <- [1..n], mod n d == 0]
  60.  
  61. isPrime n = n > 2 && [1, n] == [d | d <- [1..n], mod n d == 0]
  62.  
  63. sumDig = sum . map digitToInt . show
  64. sumDig' n = sum $ map digitToInt $ show n
  65.  
  66. getPrimesLC :: Int -> Int -> [Int]
  67. getPrimesLC x y = [d | d <- [min x y .. max x y], isPrime d && elem '7' $ show d]
  68.  
  69. getPrimesHOF :: Int -> Int -> [Int]
  70. getPrimesHOF x y = filter (\d -> isPrime d && elem '7' $ show d) [min x y .. max x y]
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement