-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson9.hs
32 lines (22 loc) · 943 Bytes
/
lesson9.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Data.Char
myMap _ [] = []
myMap f (x:xs) = (f x):myMap f xs
remove _ [] = []
remove f (x:xs) = if f x
then remove f xs
else x:remove f xs
myProduct xs = foldl (*) 1 xs
myFoldl f init [] = init
myFoldl f init (x:xs) = f x (myFoldl f init xs)
myFoldl2 f init [] = init
myFoldl2 f init (x:xs) = myFoldl2 f (f init x) xs
myElem n xs = length xsWithN > 0
where xsWithN = filter (\t -> t == n) xs
isPalindrome sentence = treatedSentence == reverse treatedSentence
where noSpaceSentence = filter (\c -> c /= ' ') sentence
treatedSentence = map (\c -> toLower c) noSpaceSentence
harmonic 0 = 1
harmonic n = 1 `div` n + harmonic (n-1)
correctedHarmonic n = sum (take n values)
where pairs = zip (cycle [1.0]) [1.0, 2.0 ..]
values = map (\(first, second) -> first / second) pairs