Дан список и два числа: m и n (0 < m < 1000). Необходимо заменить все элементы списка с индексами, кратными m, на n.
Пример:
changeEls [1, 2, 3, 4, 5] 2 7
> [7, 2, 7, 4, 7]
newtype PSet a = PSet{ contains :: (a -> Bool) } | |
newtype PSet2 a = PSet2{ contains2 :: (a -> Bool) } | |
newtype PSet3 a = PSet3{ contains3 :: (a -> Bool) } | |
-- сложение множеств | |
instance Monoid (PSet a) where | |
mempty = PSet (\a -> False) | |
mappend (PSet f1) (PSet f2) = PSet (\a -> (f1 a) || (f2 a)) | |
-- пересечение множеств |
data ReverseList a = RNil | RCons (ReverseList a) a | |
showAsList :: (Show a) => ReverseList a -> String | |
showAsList RNil = "" | |
showAsList (RCons RNil h) = show h | |
showAsList (RCons tl hl) = (showAsList tl) ++ ", " ++ (show hl) | |
toList :: ReverseList a -> [a] |
data PeanoNumber = Zero | Succ (PeanoNumber) | Pred (PeanoNumber) deriving Show | |
isSimple :: PeanoNumber -> Bool | |
isSimple Zero = True | |
isSimple (Succ (Pred _)) = False | |
isSimple (Pred (Succ _)) = True | |
isSimple (Succ num) = isSimple num | |
isSimple (Pred num) = isSimple num |
my_foldr :: (a -> b -> b) -> b -> [a] -> b | |
my_foldr f x [] = x | |
my_foldr f x (h : t) = f h (my_foldr f x t) | |
my_foldl :: (b -> a -> b) -> b -> [a] -> b | |
my_foldl f x [] = x | |
my_foldl f x (h : t) = my_foldl f (f x h) t | |
my_map :: (a -> b) -> [a] -> [b] | |
my_map _ [] = [] |
data BinaryTree = EmptyTree | |
| Leaf Integer | |
| Node Integer BinaryTree BinaryTree | |
hasLeft :: BinaryTree -> Bool | |
hasLeft (EmptyTree) = False | |
hasLeft (Leaf _) = False | |
hasLeft (Node _ EmptyTree _) = False | |
hasLeft (Node _ _ _) = True |