Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Functional Programming
diff options
context:
space:
mode:
1 files changed, 9 insertions, 4 deletions
-rw-r--r--Year 2/Functional Programming/hw3.hs13
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)