summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-03-16 15:58:42 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-03-16 15:58:42 +0800
commit7f77f812350e8fb1687343faa17cf23d797883d5 (patch)
tree71651c63f9bd60d69a75e12df13bb4bd4b5dac8e
parent63acd97fb088da2ae5aee5d36460ee30e3bbeabb (diff)
downloadh99-7f77f812350e8fb1687343faa17cf23d797883d5.tar.gz
h99-7f77f812350e8fb1687343faa17cf23d797883d5.tar.bz2
h99-7f77f812350e8fb1687343faa17cf23d797883d5.zip
+11
-rw-r--r--p11.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/p11.hs b/p11.hs
new file mode 100644
index 0000000..77b7295
--- /dev/null
+++ b/p11.hs
@@ -0,0 +1,15 @@
+import Control.Arrow
+import Data.List
+
+data ListItem a = Single a | Multiple a Int
+ deriving (Show)
+
+encode :: Eq a => [a] -> [(a,Int)]
+encode xs = map (head &&& length) $ group xs
+
+encodeModified :: Eq a => [a] -> [ListItem a]
+encodeModified = map helper . encode
+ where
+ helper (a,1) = Single a
+ helper (a,c) = Multiple a c
+