Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Functional Programming
diff options
context:
space:
mode:
Commit9ae3405e7b1593c7f52ddc37947a4fb6181ae29a (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-18 14:26:45 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-18 14:26:45 +0200
Files87183c31e6e354fdf783edf682b19c2200e3e48e /Year 2/Functional Programming
uni-projects-9ae3405e7b1593c7f52ddc37947a4fb6181ae29a.tar
uni-projects-9ae3405e7b1593c7f52ddc37947a4fb6181ae29a.tar.gz
uni-projects-9ae3405e7b1593c7f52ddc37947a4fb6181ae29a.zip
Parent44afe3c90c7e911ab96c0971db87bafcc12e935f (diff)
[FP/HW3] Solved first exercise
1 files changed, 19 insertions, 0 deletions
-rw-r--r--Year 2/Functional Programming/hw3.hs19
diff --git a/Year 2/Functional Programming/hw3.hs b/Year 2/Functional Programming/hw3.hs
index 432285a..2766fd9 100644
--- a/Year 2/Functional Programming/hw3.hs
+++ b/Year 2/Functional Programming/hw3.hs
@@ -1,3 +1,19 @@
+-- Задача 1
+
+generate :: [Int] -> [Int] -> [[Int]]
+generate as bs = [x : take (takelen - skiplen) (drop skiplen alx) | x <- as,
+ let alx = tail (alterconif x as bs),
+ takelen <- [1,3..(length alx)],
+ skiplen <- 0 : [takelen - 1 | takelen > 1]]
+ where
+ alterconif :: Int -> [Int] -> [Int] -> [Int]
+ alterconif cn a [] = []
+ alterconif cn [] b = []
+ alterconif cn a b
+ | (head a) < cn = alterconif cn (tail a) b
+ | (head b) < cn = alterconif cn a (tail b)
+ | otherwise = head a : head b : alterconif (head b) (tail a) (tail b)
+
-- Задача 2
countUniques :: String -> Int
@@ -5,4 +21,7 @@ countUniques inpt = length (filter (\v -> elem v [2, 3, 4, 7]) (map length (drop
main :: IO()
main = do
+ print(generate [10, 15, 25, 35] [1, 5, 20, 30, 40])
print(countUniques "be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe")
+
+