Added F solution (not original) and fixed permissions

This commit is contained in:
Claudio Maggioni 2019-04-04 22:03:21 +02:00
parent f843a4acc9
commit b80e414707
4 changed files with 76 additions and 0 deletions

0
bit_difference.py Normal file → Executable file
View file

66
charging_chaos.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python3
# Inspired by descriptive part of oldest answer in
# https://stackoverflow.com/questions/23308954
def try_flips(Outlets, Devices, nDev, l):
# Try all the devices in all the outlets
# Find the flip configurations in bitwise form
# that are compatible (present) in all the outlets
S = set()
for j in range(len(Devices)):
S.add(Outlets[0] ^ Devices[j])
for i in range(1, len(Outlets)):
row = set()
for j in range(len(Devices)):
row.add(Outlets[i] ^ Devices[j])
S = S.intersection(row)
# If no common configuration is found, then no flip can
# solve this case
if len(S) == 0:
return "NOT POSSIBLE"
# Otherwise, pick the one with the smallest number of 1s
# (which represent flips) and return the number of flips
m = None
for s in S:
b = count_bits(s)
if m is None or b < m:
m = b
return str(m)
def count_bits(x):
i = 0
while x != 0:
i = i + (x & 1)
x = x >> 1
return i
def read_switches():
O = input().split()
for i in range(len(O)):
O[i] = int(O[i], 2)
return O
if __name__ == "__main__":
t = int(input())
for i in range(t):
line = input().split()
n, l = int(line[0]), int(line[1])
Outlets = read_switches()
Devices = read_switches()
print("Case #" + str(i + 1) + ": " + try_flips(Outlets, Devices, n, l))

10
charging_chaos.txt Normal file
View file

@ -0,0 +1,10 @@
3
3 2
01 11 10
11 00 10
2 3
101 111
010 001
2 2
01 10
10 01

0
modular_exponentiation.py Normal file → Executable file
View file