def part_one(): text = getLines("resources/22.txt", to_int=False) deck = new_deck(10007) # text = """ # deal with increment 7 # deal with increment 9 # cut -2""".splitlines()[1:] # text = """ # deal into new stack # cut -2 # deal with increment 7 # cut 8 # cut -4 # deal with increment 7 # cut 3 # deal with increment 9 # deal with increment 3 # cut -1""".splitlines()[1:] # deck = new_deck(10) for i in range(0, 2) for t in text: deck = shuf(deck, t) for k, v in enumerate(deck): if i == 2019: print(k)
def part_two(): text = getLines("resources/22.txt", to_int=False) # front = list(range(0, 100000)) # back = list(range(119315717514047-100000, 119315717514047)) front = list(range(0, 400000)) back = list(range(119315717514047-400000, 119315717514047)) # text = """ # deal with increment 7 # deal with increment 9 # cut -2""".splitlines()[1:] # text = """ # deal into new stack # cut -2 # deal with increment 7 # cut 8 # cut -4 # deal with increment 7 # cut 3 # deal with increment 9 # deal with increment 3 # cut -1""".splitlines()[1:] # deck = new_deck(10) deck = (front, back) last = 0 for i in range(0, 10): for t in text: deck = shuf2(deck, t, 10011931571751404707) for i, v in enumerate(deck[0]): if i == 2020: print(last - v) last = v
def test_part_one(): lines = getLines("resources/8.txt", False) layers = get_layers(lines[0], height=6, width=25) counts = [] for layer in layers: counts.append((layer.count('0'), layer.count('1') * layer.count('2'))) assert sorted(counts)[0][1] == 1848
def test_part_two_file(): a = get_asteroids(getLines('resources/10.txt', to_int=False)) d = distances(a) t = d[(20, 18)] s = sorted(t, key=attrgetter('angle', 'length')) abc = accumulate(s) result = rotate_laser(abc) assert (result[199].tox == 7 and result[199].toy == 6)
def get_orbiters(filename): lines = test_one.getLines(filename, to_int=False) d = dict() for line in lines: planets = str.split(line, ')') orbiter = planets[1] orbited = planets[0] if orbiter not in d: d[orbiter] = orbited return d
def test_part_two(): h = 6 w = 25 lines = getLines("resources/8.txt", False) layers = get_layers(lines[0], height=h, width=w) layers_by_row = [] for layer in layers: rows = [] for row in get_rows(layer, w): rows.append(row) layers_by_row.append(rows) img = get_transparent_image(height=h, width=w) img = decode_image(img, layers_by_row) render(img)
def part_two(): text = """ Z L X W C Z P Q B K ###########.#.#.#.#######.############### #...#.......#.#.......#.#.......#.#.#...# ###.#.#.#.#.#.#.#.###.#.#.#######.#.#.### #.#...#.#.#...#.#.#...#...#...#.#.......# #.###.#######.###.###.#.###.###.#.####### #...#.......#.#...#...#.............#...# #.#########.#######.#.#######.#######.### #...#.# F R I Z #.#.#.# #.###.# D E C H #.#.#.# #.#...# #...#.# #.###.# #.###.# #.#....OA WB..#.#..ZH #.###.# #.#.#.# CJ......# #.....# ####### ####### #.#....CK #......IC #.###.# #.###.# #.....# #...#.# ###.### #.#.#.# XF....#.# RF..#.#.# #####.# ####### #......CJ NM..#...# ###.#.# #.###.# RE....#.# #......RF ###.### X X L #.#.#.# #.....# F Q P #.#.#.# ###.###########.###.#######.#########.### #.....#...#.....#.......#...#.....#.#...# #####.#.###.#######.#######.###.###.#.#.# #.......#.......#.#.#.#.#...#...#...#.#.# #####.###.#####.#.#.#.#.###.###.#.###.### #.......#.....#.#...#...............#...# #############.#.#.###.################### A O F N A A D M """.splitlines()[1:] text = getLines("resources/20.txt", to_int=False) print(graph_stuff2(text))
def test_part_two(): lines = test_one.getLines("resources/14.txt", to_int=False) target = 1000000000000 guess = 5000000 low_guess = 1000000 high_guess = 10000000 out = find_ore_req(lines, guess)[0] last_high = 0 last_low = 0 for _ in range(0, 200): if out < target: last_low = out low_guess = guess guess = int((low_guess + high_guess) / 2) out = find_ore_req(lines, guess)[0] elif out > target: last_high = out high_guess = guess guess = int((low_guess + high_guess) / 2) out = find_ore_req(lines, guess)[0] if out in (last_high, last_low): break assert guess == 6216589
def test_part_one(): part_one = getLines('resources/10.txt', to_int=False) assert get_max(part_one) == ((20, 18), 280)
new_grid[k] = "." else: if adj_bugs == 1: new_grid[k] = "#" else: new_grid[k] = "." return new_grid def bd_rating(grid): rating = 0 for k, v in grid.items(): if v == "#": i = k[1] * 5 + k[0] rating = rating + int(pow(2, i)) return rating lines = getLines("resources/24.txt", to_int=False) grid = {(j, i): w for i, v in enumerate(lines) for j, w in enumerate(v)} ratings = {} for i in range(0, 100): rating = bd_rating(grid) if rating not in ratings: ratings[rating] = True grid = tick(grid) else: print("twice", rating) break
def part_one(): text = getLines("resources/20.txt", to_int=False) print(get_shortest(text))