module Solutions.P11 (encodeModified) where
import Problems.Lists
import Problems.P04
import Problems.P09
encodeModified :: Eq a => [a] -> [Encoding a]
encodeModified :: forall a. Eq a => [a] -> [Encoding a]
encodeModified [a]
xs = [[a]] -> [Encoding a]
forall a. [[a]] -> [Encoding a]
encodePacked ([[a]] -> [Encoding a]) -> [[a]] -> [Encoding a]
forall a b. (a -> b) -> a -> b
$ [a] -> [[a]]
forall a. Eq a => [a] -> [[a]]
pack [a]
xs
encodePacked :: [[a]] -> [Encoding a]
encodePacked :: forall a. [[a]] -> [Encoding a]
encodePacked [] = []
encodePacked ([]:[[a]]
ls) = [[a]] -> [Encoding a]
forall a. [[a]] -> [Encoding a]
encodePacked [[a]]
ls
encodePacked ([a
x]:[[a]]
ls) = a -> Encoding a
forall a. a -> Encoding a
Single a
x Encoding a -> [Encoding a] -> [Encoding a]
forall a. a -> [a] -> [a]
: [[a]] -> [Encoding a]
forall a. [[a]] -> [Encoding a]
encodePacked [[a]]
ls
encodePacked (l :: [a]
l@(a
x:[a]
_):[[a]]
ls) = Int -> a -> Encoding a
forall a. Int -> a -> Encoding a
Multiple ([a] -> Int
forall a. [a] -> Int
myLength [a]
l) a
x Encoding a -> [Encoding a] -> [Encoding a]
forall a. a -> [a] -> [a]
: [[a]] -> [Encoding a]
forall a. [[a]] -> [Encoding a]
encodePacked [[a]]
ls