3 import Numeric (showIntAtBase)
4 import Data.Char (intToDigit)
9 let nBits = read line1 :: Int
10 let n = fromIntegral $ 2 ^ nBits
11 let codes = [toGray x | x <- [0..(n - 1)]]
12 putStrLn $ unlines $ map (showBits nBits) codes
14 toGray :: Word16 -> Word16
15 toGray n = n `xor` (n `shiftR` 1)
17 showBits :: Int -> Word16 -> String
18 showBits k n = prefix ++ suffix
19 where suffix = showIntAtBase 2 intToDigit n ""
20 prefix = replicate (k - length suffix) '0'