def knot_hash(s: str): const = 17, 31, 73, 47, 23 input_lens = [ord(e) for e in s.strip()] input_lens.extend(const) d = range(256) total_rotation = 0 for i in range(64): d, cur_rotation = apply_rotations(d, input_lens, len(input_lens) * i) total_rotation += cur_rotation d.rotate(-total_rotation) res = [hex(reduce(xor, c)) for c in U.chunks(d, 16)] return ''.join(h[-2:] for h in res).replace('x', '0')
def parse_test_data(): return [ Debug.from_strings(lines) for lines in chunks(read_file('16.first', 2018), 4) ]
def aoc8_b(): pixels = (first(dropwhile(lambda v: v == 2, pixel_vals)) for pixel_vals in zip(*layers)) letters = cycle('\u2588') return [''.join(next(letters) if v else ' ' for v in row) for row in U.chunks(pixels, width)]
from collections import Counter from itertools import dropwhile, cycle from operator import itemgetter from cytoolz import first import pyaoc2019.utils as U __author__ = 'acushner' data = [int(v) for v in first(U.read_file('08'))] width = 25 height = 6 layer_size = width * height layers = list(U.chunks(data, layer_size)) def aoc8_a(): least_zeroes = min((Counter(l) for l in layers), key=itemgetter(0)) return least_zeroes[1] * least_zeroes[2] def aoc8_b(): pixels = (first(dropwhile(lambda v: v == 2, pixel_vals)) for pixel_vals in zip(*layers)) letters = cycle('\u2588') return [''.join(next(letters) if v else ' ' for v in row) for row in U.chunks(pixels, width)] def __main(): print(aoc8_a()) print()
def aoc03_b(triangles): by_column = zip(*triangles) triangles = chunks(chain.from_iterable(by_column), 3) return aoc03_a(triangles)
def _reassemble(chunks): size = math.isqrt(len(chunks)) return [ ''.join(words) for c in U.chunks(chunks, size) for words in zip(*(s.split('/') for s in c)) ]
def _stitch(tiles: dict): res = [] for ts in chunks(tiles.values(), 5): res.extend(reduce(add, (t[r] for t in ts)) for r in range(len(ts[0]))) return res