Solve p2 by plotting graph and fixing manually... Gross

This commit is contained in:
Daniel Weber 2024-12-24 14:09:14 -05:00
parent ae5f68418f
commit c7ac01d214

View File

@ -25,21 +25,14 @@ def part_one(n, g):
p1 = p1 | (resolve(i, n, g) << int(i.replace("z", "")))
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):
if s in g:
sus[s] = []
sus.add(s)
add2sus(sus, g, g[s][0])
add2sus(sus, g, g[s][2])
def sus(z1, z2, g):
sus_g = {}
sus_g = set()
binz = list(bin(z1 ^ z2)[2:])
binz.reverse()
for c, i in enumerate(binz):
@ -48,35 +41,69 @@ def sus(z1, z2, g):
print(len(sus_g))
print(len(g))
pass
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:])
ybin = list(bin(y)[2:])
xbin.reverse()
ybin.reverse()
n={}
for c, x in enumerate(xbin):
n[f"x{c:02}"] = int(x)
for c, y in enumerate(ybin):
n[f"y{c:02}"] = int(y)
return n
def part_two(n, g):
x = random.getrandbits(56)
y = random.getrandbits(56)
def test(x, y, z, g):
n = gen_n(x, y)
x = combine(n, "x")
y = combine(n, "y")
z = part_one(n.copy(), g.copy())
print("y, ", bin(y))
print("x, ", bin(x))
print("z, ", bin(z))
print("W, ", bin(x+y))
print("^, ", bin(z^(x+y)))
sus(z, x+y, g)
pass
z = part_one(n, g.copy())
return z == x+y
def check_l_rec(s, g, visited):
if s in g:
for ss in g[s][0]:
if ss in visited:
return True
if check_l_rec(ss, g, set(list(visited)+[ss])):
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():
contents = file2list("input.txt")