def part_one(): possible = 0 for triangle in utils.load('3').split('\n'): if Triangle([int(side) for side in triangle.split(',')]).is_possible(): possible += 1 print("Your puzzle answer is", possible)
def part_one(): block_router = BlockRouter() for instruction in utils.load('1').split(', '): direction = instruction[0] steps = int(instruction[1:]) block_router.turn(direction) for i in range(steps): block_router.step() print("Your puzzle answer is", abs(block_router.x) + abs(block_router.y))
def part_two(): block_router = BlockRouter() for instruction in utils.load('1').split(', '): direction = instruction[0] steps = int(instruction[1:]) block_router.turn(direction) for i in range(steps): block_router.step() first_intersect = block_router.first_intersect print("Your puzzle answer is", abs(first_intersect[0]) + abs(first_intersect[1]))
def part_two(): possible = 0 table = [row.split(',') for row in utils.load('3').split('\n')] for x in range(3): sides = [] for y in range(len(table)): sides.append(int(table[y][x])) if len(sides) == 3: if Triangle(sides).is_possible(): possible += 1 sides = [] print("Your puzzle answer is:", possible)
def part_one(): pad = KeyPad([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1) instruction_set = utils.load('2') code = [] for key_set in instruction_set.split('\n'): for instruction in key_set: pad.process(instruction) code.append(pad.pad[pad.y][pad.x]) print("Your puzzle answer is", code)
def part_two(): pad = KeyPad([[None, None, '1', None, None], [None, '2', '3', '4', None], ['5', '6', '7', '8', '9'], [None, 'A', 'B', 'C', None], [None, None, 'D', None, None]], 0, 2) instructionSet = utils.load('2') code = [] for keySet in instructionSet.split('\n'): for instruction in keySet: pad.process(instruction) code.append(pad.pad[pad.y][pad.x]) print("Your puzzle answer is", code)