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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
module Utils where
import List (intercalate, intersect)
none :: (a -> Bool) -> [a] -> Bool
none p xs = not (any p xs)
sameLength :: [a] -> [b] -> Bool
sameLength xs ys = length xs == length ys
count :: a -> [a] -> Int
count _ [] = 0
count x (y:ys) | x == y = 1 + count x ys
| otherwise = count x ys
countBy :: (a -> Bool) -> [a] -> Int
countBy p xs = length (filter p xs)
disjoint :: [a] -> [a] -> Bool
disjoint xs ys = null (intersect xs ys)
dropLast :: Int -> [a] -> [a]
dropLast n xs = reverse (drop n (reverse xs))
lpad :: Int -> String -> String
lpad n s = replicate (n - length s) ' ' ++ s
rpad :: Int -> String -> String
rpad n str = str ++ replicate (n - length str) ' '
indentStr :: Int -> String -> String
indentStr n str = intercalate "\n" $ map (replicate n ' ' ++) $ lines str
(+\+) :: String -> String -> String
s1 +\+ s2 = s1 ++ '\n' : s2
|