Solve p2 by plotting graph and fixing manually... Gross
This commit is contained in:
parent
ae5f68418f
commit
c7ac01d214
@ -25,21 +25,14 @@ def part_one(n, g):
|
|||||||
p1 = p1 | (resolve(i, n, g) << int(i.replace("z", "")))
|
p1 = p1 | (resolve(i, n, g) << int(i.replace("z", "")))
|
||||||
return p1
|
return p1
|
||||||
|
|
||||||
def combine(n, s):
|
|
||||||
num = 0
|
|
||||||
for i in n:
|
|
||||||
if s in i:
|
|
||||||
num = num | n[i] << int(i.replace(s, ""))
|
|
||||||
return num
|
|
||||||
|
|
||||||
def add2sus(sus, g, s):
|
def add2sus(sus, g, s):
|
||||||
if s in g:
|
if s in g:
|
||||||
sus[s] = []
|
sus.add(s)
|
||||||
add2sus(sus, g, g[s][0])
|
add2sus(sus, g, g[s][0])
|
||||||
add2sus(sus, g, g[s][2])
|
add2sus(sus, g, g[s][2])
|
||||||
|
|
||||||
def sus(z1, z2, g):
|
def sus(z1, z2, g):
|
||||||
sus_g = {}
|
sus_g = set()
|
||||||
binz = list(bin(z1 ^ z2)[2:])
|
binz = list(bin(z1 ^ z2)[2:])
|
||||||
binz.reverse()
|
binz.reverse()
|
||||||
for c, i in enumerate(binz):
|
for c, i in enumerate(binz):
|
||||||
@ -48,35 +41,69 @@ def sus(z1, z2, g):
|
|||||||
print(len(sus_g))
|
print(len(sus_g))
|
||||||
print(len(g))
|
print(len(g))
|
||||||
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def gen_n(x,y):
|
def gen_n(x,y):
|
||||||
|
n={}
|
||||||
|
for c in range(45):
|
||||||
|
n[f"x{c:02}"] = int(0)
|
||||||
|
n[f"y{c:02}"] = int(0)
|
||||||
|
|
||||||
xbin = list(bin(x)[2:])
|
xbin = list(bin(x)[2:])
|
||||||
ybin = list(bin(y)[2:])
|
ybin = list(bin(y)[2:])
|
||||||
xbin.reverse()
|
xbin.reverse()
|
||||||
ybin.reverse()
|
ybin.reverse()
|
||||||
n={}
|
|
||||||
for c, x in enumerate(xbin):
|
for c, x in enumerate(xbin):
|
||||||
n[f"x{c:02}"] = int(x)
|
n[f"x{c:02}"] = int(x)
|
||||||
for c, y in enumerate(ybin):
|
for c, y in enumerate(ybin):
|
||||||
n[f"y{c:02}"] = int(y)
|
n[f"y{c:02}"] = int(y)
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def part_two(n, g):
|
def test(x, y, z, g):
|
||||||
x = random.getrandbits(56)
|
|
||||||
y = random.getrandbits(56)
|
|
||||||
n = gen_n(x, y)
|
n = gen_n(x, y)
|
||||||
x = combine(n, "x")
|
z = part_one(n, g.copy())
|
||||||
y = combine(n, "y")
|
return z == x+y
|
||||||
z = part_one(n.copy(), g.copy())
|
|
||||||
print("y, ", bin(y))
|
def check_l_rec(s, g, visited):
|
||||||
print("x, ", bin(x))
|
if s in g:
|
||||||
print("z, ", bin(z))
|
for ss in g[s][0]:
|
||||||
print("W, ", bin(x+y))
|
if ss in visited:
|
||||||
print("^, ", bin(z^(x+y)))
|
return True
|
||||||
sus(z, x+y, g)
|
if check_l_rec(ss, g, set(list(visited)+[ss])):
|
||||||
pass
|
return True
|
||||||
|
for ss in g[s][2]:
|
||||||
|
if ss in visited:
|
||||||
|
return True
|
||||||
|
if check_l_rec(ss, g, set(list(visited)+[ss])):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def check4loop(g):
|
||||||
|
for i in g:
|
||||||
|
if 'z' in i:
|
||||||
|
if check_l_rec(i, g, set(i)):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def part_two(n, g):
|
||||||
|
# import graphviz
|
||||||
|
# dot = graphviz.Digraph(comment='The Round Table')
|
||||||
|
# for i in g:
|
||||||
|
# dot.node(i)
|
||||||
|
# for i in g:
|
||||||
|
# color = "blue"
|
||||||
|
# if g[i][1] == "AND":
|
||||||
|
# color = "red"
|
||||||
|
# elif g[i][1] == "OR":
|
||||||
|
# color = "green"
|
||||||
|
# dot.edge(g[i][0], i, g[i][1], color=color)
|
||||||
|
# dot.edge(g[i][2], i, g[i][1], color=color )
|
||||||
|
# dot.render('round-table.gv', view=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
contents = file2list("input.txt")
|
contents = file2list("input.txt")
|
||||||
|
Loading…
Reference in New Issue
Block a user