3 ms·
> module Main where > input = "aaaabbbcca" > r :: String -> (Char,Int) -> [(String, Int)] > r [] (c,n) = [([c],n)] > r (x:xs) (c,n) > | c == x = r xs (c,n
by solresol 6y ago
> module Main where
> input = "aaaabbbcca"
> r :: String -> (Char,Int) -> [(String, Int)]
> r [] (c,n) = [([c],n)]
> r (x:xs) (c,n)
> | c == x = r xs (c,n+1)
> | otherwise = (([c],n): r xs (x,1))
> main = putStrLn (show (r (tail input) (head input, 1) ))
4 minutes 42 seconds.
And no, I don't write code like this normally, but I guess this is me when I'm under time pressure... anyway, I could refactor it nicely afterwards in the 25 minutes allocated.
- deleted 6y ago[deleted]
- hyperrealgopher 6y agoGreat solution that avoids using any functions that do the heavy lifting for you! Thanks for showing!