-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings-mix.hs
More file actions
35 lines (30 loc) · 814 Bytes
/
strings-mix.hs
File metadata and controls
35 lines (30 loc) · 814 Bytes
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
module Codewars.G964.Mixin where
import Data.List
mix :: [Char] -> [Char] -> [Char]
mix s1 s2 = diff (filter e a) (filter e b)
where x1=lex s1
x2=lex s2
lex=filter (flip elem ['a'..'z'])
a=count $ sort x1
b=count $ sort x2
isect=intersect x1 x2
e (x,_) = flip elem isect x
count :: [Char]->[(Char,Int)]
count xs =
nub $
map c xs
where c x = (x, length $ filter ((==) x) xs)
diff :: [(Char,Int)]->[(Char,Int)]->[Char]
diff [] _ = ""
diff _ [] = ""
diff xs xy =
intercalate "/" $
map (\(a,b)->a++":"++b) $
sortOn fst $
map conv $
zip xs xy
where conv ((a1,b1),(a2,b2))= (num b1 b2, replicate (max b1 b2) a1)
num a b
| a > b = "1"
| a == b = "="
| otherwise = "2"