diff options
[FP/HW3] Solved first exercise
1 files changed, 19 insertions, 0 deletions
| -rw-r--r-- | Year 2/Functional Programming/hw3.hs | 19 |
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") + + |
