
% gray(N,C) :- C is the N-bit Gray code

Can you apply the method of "result caching" in order to make the predicate more efficient, when it is to be used repeatedly?
-}

gray :: Int -> [String]
gray 0 = [""]
gray nb = map (\x -> '0':x) prev ++ map (\x -> '1':x) prev
    where prev = gray (nb - 1)