Skip to content

Instantly share code, notes, and snippets.

View belyaev-mikhail's full-sized avatar

Mikhail Belyaev belyaev-mikhail

  • SPBSTU
  • Saint-Petersburg, Russia
View GitHub Profile
@belyaev-mikhail
belyaev-mikhail / 3_3
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_3
3_3
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))
-- пересечение множеств
@belyaev-mikhail
belyaev-mikhail / 3_2
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_2
3_2
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]
@belyaev-mikhail
belyaev-mikhail / 3_1
Created June 10, 2019 22:06 — forked from ChinarevaEV/3_1
3_1
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

1 вариант

Problem 1

Дан список и два числа: m и n (0 < m < 1000). Необходимо заменить все элементы списка с индексами, кратными m, на n.

Пример:

changeEls [1, 2, 3, 4, 5] 2 7
> [7, 2, 7, 4, 7]