Skip to content

Commit ee86d27

Browse files
committed
estudo sobre propriedades da operacao XOR
1 parent 718d071 commit ee86d27

File tree

9 files changed

+392
-0
lines changed

9 files changed

+392
-0
lines changed

python/Xor/.idea/Xor.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Xor/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Xor/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Xor/.idea/workspace.xml

Lines changed: 291 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Xor/raw/Xor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
https://www.geeksforgeeks.org/given-a-set-find-xor-of-the-xors-of-all-subsets/
2+
https://www.geeksforgeeks.org/sum-xor-possible-subsets/
3+
https://www.geeksforgeeks.org/maximum-xor-using-k-numbers-1-n/
4+
https://www.geeksforgeeks.org/calculate-xor-1-n/
5+
http://codeforces.com/blog/entry/10229

python/Xor/solutions/PrimeXor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'''
2+
https://www.hackerrank.com/challenges/prime-xor/problem
3+
'''
4+
5+
if __name__ == '__main__':
6+
pass

python/Xor/solutions/Xor.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def isPowerOf2(n):
2+
return (n & (n - 1)) == 0
3+
4+
5+
print([(isPowerOf2(i) and i > 1, i) for i in range(0, 100)])
6+
7+
8+
def sum_n_xor(n):
9+
acc = 1
10+
for x in range(2, n + 1):
11+
acc = acc ^ x
12+
return acc
13+
14+
def sum_n_xor2(n):
15+
o = n & 3
16+
if o == 0:
17+
return n
18+
elif o == 1:
19+
return 1
20+
elif o == 2:
21+
return n + 1
22+
else:
23+
return 0
24+
25+
26+
print([(x, sum_n_xor(x)) for x in range(4, 25)])
27+
print([(x, sum_n_xor2(x)) for x in range(4, 25)])
28+
29+
if __name__ == '__main__':
30+
pass

0 commit comments

Comments
 (0)