From 13c0046a6dbd41b15358e76856922144ac76e768 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Sat, 4 Apr 2015 17:38:20 +0800 Subject: +46 +47 +48 +49 +50 --- H49.hs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 H49.hs (limited to 'H49.hs') 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) -- cgit v1.2.3-70-g09d2