Skip to content
Snippets Groups Projects
Commit d360e719 authored by Raphael Cameron Felten's avatar Raphael Cameron Felten
Browse files

feat: sheet_3

parents
No related branches found
No related tags found
No related merge requests found
universalQ :: (a -> Bool) -> [a] -> Bool
universalQ function list = foldr (&&) True (map function list)
map' :: (a -> b) -> [a] -> [b]
map' function list = foldr (\x acc -> function x : acc) [] list
removeDuplicates :: Eq a => [a] -> [a]
removeDuplicates list = foldr (\x acc -> if (filter (==x) acc) /= [] then acc else x : acc) [] list
\ No newline at end of file
data Rose a = Node a [Rose a] deriving Show
zipWithRose :: (a -> b -> c) -> Rose a -> Rose b -> Rose c
zipWithRose function (Node a1 children1) (Node a2 children2) = Node (function a1 a2) (zipWith (zipWithRose function) children1 children2)
mapAndFold :: (a -> b) -> (b -> b -> b) -> Rose a -> b
mapAndFold f g (Node r children) = g (f r) (foldr (g) (map (mapAndFold f g) children))
\ No newline at end of file
dropMult :: Int -> [Int] -> [Int]
dropMult x xs = [y | y <- xs, y `mod` x /= 0]
dropAll :: [Int] -> [Int]
dropAll (x:xs) = x : dropAll (dropMult x xs)
primes :: [Int]
primes = dropAll [2 ..]
goldbach :: Int -> [(Int, Int)]
goldbach n = [(x, y) | x <- takeWhile (<= n) primes, y <- takeWhile (<= n) primes, x + y == n, x `mod` 2 == 1, y `mod` 2 == 1, x <= y]
range :: [a] -> Int -> Int -> [a]
range (pre:xs) m n = if m > 0 && n > 0 then range xs (m - 1) (n - 1) else if m > 0 then range (xs:post) (m - 1) n else if n > 0 then range (pre:xs) m (n-1) else if m <= 0 && n <=0 then (pre:xs)++ [post] else []
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment