summaryrefslogtreecommitdiff
path: root/H49.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-04-04 17:38:20 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-04-04 17:38:20 +0800
commit13c0046a6dbd41b15358e76856922144ac76e768 (patch)
treedfee06a0f90b0b0b6048eafec7c46da253c79328 /H49.hs
parentb47befab3696c40c710ee80f366fa376ec967b30 (diff)
downloadh99-13c0046a6dbd41b15358e76856922144ac76e768.tar.gz
h99-13c0046a6dbd41b15358e76856922144ac76e768.tar.bz2
h99-13c0046a6dbd41b15358e76856922144ac76e768.zip
+46 +47 +48 +49 +50
Diffstat (limited to 'H49.hs')
-rw-r--r--H49.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/H49.hs b/H49.hs
new file mode 100644
index 0000000..57f16b5
--- /dev/null
+++ b/H49.hs
@@ -0,0 +1,8 @@
+import Control.Monad (replicateM)
+
+gray = map construct . (flip replicateM) ['0','1']
+ where construct x = zipWith (\a b -> if a == b then '0' else '1') ('0':x) x
+
+gray' :: Integral a => a -> [String]
+gray' 0 = [""]
+gray' n = foldr (\s acc -> ("0" ++ s):("1" ++ s):acc) [] $ gray (n-1)