Пример #1
0
import common
year_common = common.import_year_common(2019)

tape = common.extract_numbers(common.read_file('2019/25/data.txt'))

moves = [
    'south',
    'take monolith',
    'east',
    'take asterisk',
    'west',
    'north',
    # 'west',
    # 'take coin',
    # 'north',
    # 'east',
    # 'take astronaut ice cream',
    # 'west',
    # 'south',
    # 'east',
    'north',
    'north',
    # 'take mutex',
    'west',
    'take astrolabe',
    'west',
    # 'take dehydrated water',
    'west',
    'take wreath',
    'east',
    'south',
Пример #2
0
import numpy as np
import common
knot_hash_full = common.import_year_common(2017).knot_hash_full

data = 'hwlqcszp'
# data = 'flqrgnkx' # sample data

rows = list()

# part 1
count = 0
for r in range(128):
    hash_input = data + '-' + str(r)
    ints, representation = knot_hash_full(hash_input)
    rows.append(ints)
    for i in range(len(ints)):
        for b in range(8):
            if (ints[i] & (1 << b)) > 0:
                count += 1

print(count)


# part 2
def is_used(x, y):
    num_i = int(x / 8)
    bit = 7 - (x % 8)
    num = rows[y][num_i]
    return (num & (1 << bit)) > 0

Пример #3
0
import common
import itertools as it
run_intcode = common.import_year_common(2019).run_intcode
tape_to_mem = common.import_year_common(2019).tape_to_mem

tape = common.extract_numbers(common.read_file('2019/07/data.txt'))


class IterGlue:
    def __init__(self):
        self.forward_to = None

    def iterate(self):
        yield from self.forward_to


def prepend(values, iterator):
    yield from iter(values)
    yield from iterator


def solve(phases):
    max_result = 0
    for perm in it.permutations(phases, 5):
        glue = IterGlue()
        i1 = run_intcode(tape_to_mem(tape),
                         prepend([perm[0], 0], glue.iterate()))
        i2 = run_intcode(tape_to_mem(tape), prepend([perm[1]], i1))
        i3 = run_intcode(tape_to_mem(tape), prepend([perm[2]], i2))
        i4 = run_intcode(tape_to_mem(tape), prepend([perm[3]], i3))
        i5 = run_intcode(tape_to_mem(tape), prepend([perm[4]], i4))