Exemplo n.º 1
0
# manh(p1[, p2]) - n-dim Manhattan dist; omit p2 for dist from origin
# is_prime
# adjs - set of dx,dy values for LRUD adjacencies
# diags - set of dx,dy values for diagonals
# all_dirs set of dx,dy values for all 8 surrounding values

test = len(sys.argv) > 1
input_file = 'input' + sys.argv[0].split('.')[1].lstrip('/') + ('.test' if test else '')

p1 = 0
p2 = 0

inp = []
with open(input_file) as f:
    for line in f:
        inp.append(line.strip())
        pass # if need custom
    inp = utils.load_num_lines(f) # one int per line
    inp = utils.load_comma_sep_nums(f) # 1,2,3,...
    inp = utils.load_split_lines(f) # asdf asdf asdf ...
    inp = utils.load_one_line_of_nums(f) # 1 2 3 ...
    inp = utils.load_grid(f, str) # 2D grid of X type

# Part 1

print(f'Part 1: {p1}')

# Part 2

print(f'Part 2: {p2}')
Exemplo n.º 2
0
#!/usr/bin/env python3

import sys

import utils

test = len(sys.argv) > 1
input_file = 'input' + sys.argv[0].split('.')[1].lstrip('/') + ('.test' if test
                                                                else '')

p1 = 0

with open(input_file) as f:
    cmds = utils.load_split_lines(f)


def run(debug):
    global p1
    ip = 0
    regs = {k: 0 for k in 'abcdefgh'}
    regs['a'] = 1 if debug else 0
    while ip in range(len(cmds)):
        if debug and ip >= 9:
            # short circuit execution, necessary registers set
            return regs
        cmd = cmds[ip]
        op = cmd[0]
        if op == 'set':
            x = cmd[1]
            try:
                y = int(cmd[2])