mirror of
https://github.com/peter-tanner/advent-of-code-2020.git
synced 2024-11-30 10:50:17 +08:00
Thanks, and have fun :)
This commit is contained in:
parent
5bcca706c8
commit
02453aca1d
14
24/c.py
14
24/c.py
|
@ -22,14 +22,10 @@ def getHexAdjacent(vec):
|
||||||
})
|
})
|
||||||
return adj
|
return adj
|
||||||
|
|
||||||
def getHexAdjacentState(vec):
|
|
||||||
getHexAdjacent
|
|
||||||
return True
|
|
||||||
|
|
||||||
def toggle(boolean):
|
def toggle(boolean):
|
||||||
return (False if boolean else True)
|
return (False if boolean else True)
|
||||||
|
|
||||||
grid = {(0,0,0):{'state':False}}#'adj':getHexAdjacent((0,0,0)),
|
grid = {(0,0,0):{'state':False}}
|
||||||
|
|
||||||
vectors = []
|
vectors = []
|
||||||
for direction in directions:
|
for direction in directions:
|
||||||
|
@ -39,12 +35,11 @@ for direction in directions:
|
||||||
vec = getHexAdjacent(vec)[dir_]
|
vec = getHexAdjacent(vec)[dir_]
|
||||||
grid.update({vec:{'state':toggle(grid[vec]['state'] if vec in grid else False)}})
|
grid.update({vec:{'state':toggle(grid[vec]['state'] if vec in grid else False)}})
|
||||||
vectors.append(vec)
|
vectors.append(vec)
|
||||||
# print({x:vectors.count(x) for x in vectors})
|
|
||||||
# print(len([vectors.count(x) for x in vectors if (vectors.count(x) % 2 == 1)]))
|
|
||||||
|
|
||||||
#Part 1
|
#Part 1
|
||||||
print(len([ x for x in grid if (grid[x]['state'] == True)])) # Black => True, white => false
|
print(len([ x for x in grid if (grid[x]['state'] == True)])) # Black => True, white => false
|
||||||
|
|
||||||
|
#Part 2
|
||||||
grid_ = deepcopy(grid) #expand our space by one hextile in each direction
|
grid_ = deepcopy(grid) #expand our space by one hextile in each direction
|
||||||
for cell in grid:
|
for cell in grid:
|
||||||
adj = getHexAdjacent(cell)
|
adj = getHexAdjacent(cell)
|
||||||
|
@ -66,16 +61,11 @@ while i < 100:
|
||||||
if grid[cell_]['state'] == True:
|
if grid[cell_]['state'] == True:
|
||||||
c+=1
|
c+=1
|
||||||
else:
|
else:
|
||||||
# print(len(grid_))
|
|
||||||
grid_.update({cell_:{'state':False}})
|
grid_.update({cell_:{'state':False}})
|
||||||
|
|
||||||
if grid[cell]['state'] == True and (c == 0 or c > 2):
|
if grid[cell]['state'] == True and (c == 0 or c > 2):
|
||||||
# print('false')
|
|
||||||
grid_[cell]['state'] = False
|
grid_[cell]['state'] = False
|
||||||
elif grid[cell]['state'] == False and c == 2:
|
elif grid[cell]['state'] == False and c == 2:
|
||||||
# print('true')
|
|
||||||
grid_[cell]['state'] = True
|
grid_[cell]['state'] = True
|
||||||
# print(len(grid))
|
|
||||||
# print(len(grid_))
|
|
||||||
i+=1
|
i+=1
|
||||||
print(len([ x for x in grid_ if (grid_[x]['state'] == True)]))
|
print(len([ x for x in grid_ if (grid_[x]['state'] == True)]))
|
||||||
|
|
30
25/a.py
Normal file
30
25/a.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
div = 20201227
|
||||||
|
|
||||||
|
card_public = 5764801
|
||||||
|
door_public = 17807724
|
||||||
|
|
||||||
|
def transform(subject,lpt):
|
||||||
|
value = 1
|
||||||
|
c = 0
|
||||||
|
while c < lpt:
|
||||||
|
value *= subject
|
||||||
|
value = value % div
|
||||||
|
# print(c, value)
|
||||||
|
c+=1
|
||||||
|
return value
|
||||||
|
|
||||||
|
def bruteforce(value_goal):
|
||||||
|
lpt = 1
|
||||||
|
value = 1
|
||||||
|
while True:
|
||||||
|
value *= 7
|
||||||
|
value = value % div
|
||||||
|
if value == value_goal:
|
||||||
|
return lpt
|
||||||
|
lpt += 1
|
||||||
|
|
||||||
|
card_lpt_size = bruteforce(card_public)
|
||||||
|
door_lpt_size = bruteforce(door_public)
|
||||||
|
print(card_lpt_size, door_lpt_size)
|
||||||
|
print(transform(door_public,card_lpt_size))
|
Loading…
Reference in New Issue
Block a user