diff options
| Commit | 3dd64f8dfcf6bbe728fd1075dce9b1c6abb1ee59 (patch) | |
|---|---|---|
| Author | 2023-01-12 08:58:46 +0000 | |
| Committer | 2023-01-12 08:58:46 +0000 | |
| Files | c28747f0226122f1ccb73fb1210c16441f648334 | |
| uni-projects-3dd64f8dfcf6bbe728fd1075dce9b1c6abb1ee59.tar uni-projects-3dd64f8dfcf6bbe728fd1075dce9b1c6abb1ee59.tar.gz uni-projects-3dd64f8dfcf6bbe728fd1075dce9b1c6abb1ee59.zip | ||
| Parent | 51a684a291963fbe8bb3f81ef04282233d083efa (diff) | |
[FP/HW3] Post-submission fix of countUniques to accept the whole file
1 files changed, 9 insertions, 4 deletions
| -rw-r--r-- | Year 2/Functional Programming/hw3.hs | 13 |
diff --git a/Year 2/Functional Programming/hw3.hs b/Year 2/Functional Programming/hw3.hs index 2b1b864..de81bd5 100644 --- a/Year 2/Functional Programming/hw3.hs +++ b/Year 2/Functional Programming/hw3.hs @@ -22,14 +22,19 @@ generate as bs = asiter as bs (head as) -- Задача 2 +countUniques :: String -> Int +countUniques f = foldr (\el accum -> accum + (countUniquesLine el)) 0 (lines f) + -- Пропускаме всичко до "|" (включително), преобразуваме стринговете в дължини, оставяме само тези, -- които отговарят на желаните цифри (1, 4, 7, 8) и бройм -countUniques :: String -> Int -countUniques inpt = length (filter (\v -> elem v [2, 3, 4, 7]) (map length (drop 11 (words inpt)))) +countUniquesLine :: String -> Int +countUniquesLine inpt = length (filter (\v -> elem v [2, 3, 4, 7]) (map length (drop 11 (words inpt)))) main :: IO() main = do - print(generate [10, 15, 25, 35, 45] [1, 5, 20, 30, 40, 50]) + print(generate [10, 15, 25] [1, 5, 20, 30]) + sample <- readFile "sample.txt" + print(countUniques sample) inpt <- readFile "input.txt" - print(foldr (\el accum -> accum + (countUniques el)) 0 (lines inpt)) + print(countUniques inpt) |
