-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgraycode.py
More file actions
29 lines (25 loc) · 729 Bytes
/
graycode.py
File metadata and controls
29 lines (25 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# import sys
'''
Adnane Aabbar
github : @adnaneaabbar
'''
mul = lambda: map(int, input().strip().split())
seq = lambda: list(map(int, input().strip().split()))
mulstr = lambda: map(str, input().strip().split())
seqstr = lambda: list(map(str, input().strip().split()))
readInt = lambda: int(input())
readLine = lambda: input().strip()
# USACO Guide input handling
# sys.stdin = open("input.in", "r")
# sys.stdout = open("output.out", "w")
# sys.stdin = open("measurement.in", "r")
# sys.stdout = open("measurement.out", "w")
n = readInt()
res = [0]
for i in range(1, 2**n):
# prev xor current
res.append(res[-1] ^ ( i & -i))
for c in res:
ans = bin(c).lstrip('0b')
ans = '0' * (n-len(ans)) + ans
print(ans)