|
1
|
|
|
from operator import and_, or_, xor |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
def CreateTable(first, second): |
|
5
|
|
|
rows = len(first) + 1 |
|
6
|
|
|
cols = len(second) + 1 |
|
7
|
|
|
table = [] |
|
8
|
|
|
for i in range(rows): |
|
9
|
|
|
if i == 0: |
|
10
|
|
|
table.append([''] + list(map(int, list(second)))) |
|
11
|
|
|
else: |
|
12
|
|
|
table.append([int(first[i - 1])] + [''] * (cols - 1)) |
|
13
|
|
|
return table |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def Bit(first, second, operator): |
|
17
|
|
|
BitTable = CreateTable(first, second) |
|
18
|
|
|
for row in range(1, len(first) + 1): |
|
19
|
|
|
for col in range(1, len(second) + 1): |
|
20
|
|
|
BitTable[row][col] = operator(BitTable[0][col], BitTable[row][0]) |
|
21
|
|
|
return sum( |
|
22
|
|
|
[int(''.join(map(str, BitTable[i][1:])), 2) for i in range(1, len(BitTable))] |
|
23
|
|
|
) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def checkio(first, second): |
|
27
|
|
|
return sum( |
|
28
|
|
|
[ |
|
29
|
|
|
Bit(bin(first)[2:], bin(second)[2:], and_), |
|
30
|
|
|
Bit(bin(first)[2:], bin(second)[2:], or_), |
|
31
|
|
|
Bit(bin(first)[2:], bin(second)[2:], xor), |
|
32
|
|
|
] |
|
33
|
|
|
) |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
# These "asserts" using only for self-checking and not necessary for |
|
37
|
|
|
# auto-testing |
|
38
|
|
|
if __name__ == '__main__': |
|
39
|
|
|
assert checkio(4, 6) == 38 |
|
40
|
|
|
assert checkio(2, 7) == 28 |
|
41
|
|
|
assert checkio(7, 2) == 18 |
|
42
|
|
|
|