Jump to content

Unique characters in each string: Difference between revisions

m
→‎{{header|Haskell}}: Inlined charCounts
m (→‎{{header|Haskell}}: Pruned unused imports)
m (→‎{{header|Haskell}}: Inlined charCounts)
Line 263:
onceInEach [] = []
onceInEach ws@(x : xs) =
S.elems $
let freq = charCounts (concat ws)
in S.filter
wordCount = length ws
((wordCount ==) . fromJust . flip M.lookup freq)
in filter
( foldr
((wordCount ==) . fromJust . flip M.lookup freq)
( (S.elemsintersection $. S.fromList)
(S.fromList foldrx)
(S.intersection . S.fromList)xs
(S.fromList x)
where
xs
wordCount = length )ws
freq =
foldr
(flip (M.insertWith (+)) 1)
xsM.empty
let freq = charCounts (concat ws)
 
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLnprint . onceInEach)
[ "1a3c52debeffd",
"2b6178c97a938stf",
"3ycxdb1fgxa2yz"
]</lang>
 
------------------------- GENERIC ------------------------
 
charCounts :: String -> M.Map Char Int
charCounts =
foldr
(flip (M.insertWith (+)) 1)
M.empty</lang>
{{Out}}
<pre>123abc</pre>
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.