summaryrefslogtreecommitdiff
path: root/H49.hs
blob: 57f16b5ed20c9dcf99918e1b55effa5d85cf4dc2 (plain)
1
2
3
4
5
6
7
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)