summaryrefslogtreecommitdiff
path: root/H49.hs
diff options
context:
space:
mode:
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)