# print(graph) roots = [] for c in graph: if all(c not in v.next for v in graph.values()): roots.append(c) print('roots:', roots) roots.sort() lol = '' wtf(graph, roots[0], set(roots[1:]), set()) advent.submit_answer(1, lol) ############ time = {} for c in ascii_uppercase: time[c] = ord(c) - ord('A') + 61 class W: def __init__(self): self.left = 0 self.job = '' def __repr__(self): if not self.job: return 'W(-)' return 'W({}, {})'.format(self.job, self.left)
serial_no = int(fin.read()) grid = [] for j in range(300 + 1): grid.append([]) for i in range(300 + 1): grid[j].append(fuel(i, j)) # serial_no = 18 # for l in grid[45:45+3]: # print(l[33:33+3]) ans = max( ((x, y) for x in range(1, 301 - 3 + 1) for y in range(1, 301 - 3 + 1)), key=get_power) advent.submit_answer(1, '{},{}'.format(*ans)) maxp = get_power(ans) maxpsize = 2 print('to beat:', maxp) prevp = maxp consecutive_desc = 0 for sz in range(1, 301): print('size', sz, '...', end=' ') ans = max(((x, y) for x in range(1, 301 - sz + 1) for y in range(1, 301 - sz + 1)), key=lambda xy: get_power(xy, sz)) p = get_power(ans, sz) print(ans, p)
# sys.stdout.write(str(cur_marble) + '\r') if cur_marble % 23 != 0: cur_idx = (cur_idx + 1) % len(marbles) + 1 marbles.insert(cur_idx, cur_marble) else: cur_idx = (cur_idx - 7) % len(marbles) points = cur_marble + marbles.pop(cur_idx) scores[cur_marble % nplayers + 1] += points # print('\n>>>', cur_marble, points, last_marble) winner_score = max(scores.values()) advent.submit_answer(1, winner_score) marbles = blist([0]) cur_marble = 0 cur_idx = 0 cur_player = 1 scores = {} last_marble *= 100 for i in range(1, nplayers + 1): scores[i] = 0 while cur_marble < last_marble: cur_marble += 1
cavern = list(map(lambda l: list(l.strip()), fin)) setup(cavern) played_rounds = 0 dump() while not do_round(): dump() played_rounds += 1 winners = elves if elves else goblins total_hp = sum(map(lambda w: w[2], winners.values())) ans = (played_rounds-1)*total_hp advent.submit_answer(1, ans) min_atk = 4 max_atk = 50 while min_atk != max_atk: cur_atk = (min_atk + max_atk) // 2 LOG = True log('[{}, {}] -> {}\n', min_atk, max_atk, cur_atk) log('Simulating...') LOG = False setup(cavern, True, cur_atk)
tree[cur_id] = (childs, n[cur_len:cur_len+nmeta]) return meta_sum + sum(tree[cur_id][1]), cur_len + nmeta def tree_value(root): me = tree[root] nchilds = len(me[0]) if nchilds: tot = 0 for child_index in me[1]: if 1 <= child_index <= nchilds: tot += tree_value(me[0][child_index - 1]) return tot return sum(me[1]) tree = {} nums = list(map(int, fin.read().split())) ans, _ = scan(nums, 0) advent.submit_answer(1, ans) # for k, v in tree.items(): # print(k, ':', v) value = tree_value(0) advent.submit_answer(2, value)
# fill(500 - minx + 1, 0) # except IndexError: # print('IndexError!!!') # pass # with open('viz_filled.txt', 'w') as f: # for line in grid: # f.write(''.join(map(' ~|#'.__getitem__, line)) + '\n') filled = 0 for row in grid[1:]: for cell in row: if cell == WATER: filled += 1 advent.submit_answer(1, filled) # Assuming that a situation like this one will never happen: # # # #~~~X# # #~~#X# # ####X# # X# retained = filled for row in grid: prev = SAND for x, cell in enumerate(row):
cnts2 = compute_counts(600) # with open('oo1', 'w') as f: # for p in sorted(cnts, key=cnts.get): # f.write('{:<6d} {}'.format(cnts[p], p)) # f.write('\n') # with open('oo2', 'w') as f: # for p in sorted(cnts2, key=cnts2.get): # f.write('{:<6d} {}'.format(cnts2[p], p)) # f.write('\n') best_count = 0 best = None for p in pts: c1, c2 = cnts1[p], cnts2[p] if c1 == c2: if c1 > best_count: best_count = c1 best = p assert best_count == 4215 advent.submit_answer(1, best_count) ans2 = count_within_distance(10000) advent.submit_answer(2, ans2)
for y in range(maxy - miny + 1): grid.append([' '] * (maxx - minx + 1)) print('mark points') for p in points: grid[p[1] - miny][p[0] - minx] = '#' print('write grid') with open('/tmp/grd{:02d}.txt'.format(sims + 1), 'w') as f: for line in grid: f.write(''.join(line) + '\n') print('\nOpen up the grdXX.txt files in /tmp and take a look!\n') print('In my case, number 4 had the solution, which was:') print('##### ##### # # # # # # ###### ###### ##### ') print('# # # # ## # ## # # # # # # #') print('# # # # ## # ## # # # # # # #') print('# # # # # # # # # # # # # # # #') print('##### ##### # # # # # # ## ##### # ##### ') print('# # # # # # # # # ## # # # # ') print('# # # # # # # # # # # # # # # ') print('# # # # ## # ## # # # # # # ') print('# # # # ## # ## # # # # # #') print('# # # # # # # # # # ###### # #') print('\nSo a total of', init_sims + 4 + 1, 'seconds to get to it.') print( '\nGiven how I solved this, as you can imagine the following answers are only valid for this input.' ) advent.submit_answer(1, 'RPNNXFZR') advent.submit_answer(2, init_sims + 4 + 1)
states = set() for i in range(10): curstate = get_ans(grid) states.add(curstate) newgrid = copy.deepcopy(grid) for x in range(gridw): for y in range(gridh): newgrid[x][y] = transform(grid, x, y) grid = newgrid res = get_ans(grid) advent.submit_answer(1, res) # dump(grid) for i in range(10, 1000000000): curstate = get_ans(grid) if curstate not in states: states.add(curstate) print(i, ':', curstate) else: print('---->', i, ':', curstate) newgrid = copy.deepcopy(grid) for x in range(gridw):