diff --git a/24/c.py b/24/c.py index f2f35ab..a5893a3 100644 --- a/24/c.py +++ b/24/c.py @@ -22,14 +22,10 @@ def getHexAdjacent(vec): }) return adj -def getHexAdjacentState(vec): - getHexAdjacent - return True - def toggle(boolean): return (False if boolean else True) -grid = {(0,0,0):{'state':False}}#'adj':getHexAdjacent((0,0,0)), +grid = {(0,0,0):{'state':False}} vectors = [] for direction in directions: @@ -39,12 +35,11 @@ for direction in directions: vec = getHexAdjacent(vec)[dir_] grid.update({vec:{'state':toggle(grid[vec]['state'] if vec in grid else False)}}) 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 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 for cell in grid: adj = getHexAdjacent(cell) @@ -66,16 +61,11 @@ while i < 100: if grid[cell_]['state'] == True: c+=1 else: - # print(len(grid_)) grid_.update({cell_:{'state':False}}) if grid[cell]['state'] == True and (c == 0 or c > 2): - # print('false') grid_[cell]['state'] = False elif grid[cell]['state'] == False and c == 2: - # print('true') grid_[cell]['state'] = True - # print(len(grid)) - # print(len(grid_)) i+=1 print(len([ x for x in grid_ if (grid_[x]['state'] == True)])) diff --git a/25/a.py b/25/a.py new file mode 100644 index 0000000..1b507a3 --- /dev/null +++ b/25/a.py @@ -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)) \ No newline at end of file