예제 #1
0
from solutions import helpers
import numpy as np
import re

np.set_printoptions(edgeitems=30, linewidth=100000)

filename = 'input'

strings = helpers.read_each_line_as_string(filename)

pattern = re.compile(
    '(\w+) x=(-?\d+)..(-?\d+),y=(-?\d+)..(-?\d+),z=(-?\d+)..(-?\d+)')

all_cubes = []
x_points = set()
y_points = set()
z_points = set()
for row in strings[:]:
    m = pattern.match(row)
    is_on = m.group(1) == 'on'
    xmin, xmax, ymin, ymax, zmin, zmax = list(map(int, m.group(*range(2, 8))))

    current_cube = [
        is_on, [(xmin, xmax + 1), (ymin, ymax + 1), (zmin, zmax + 1)]
    ]
    all_cubes.append(current_cube)

    x_points.update((xmin, xmax + 1))
    y_points.update((ymin, ymax + 1))
    z_points.update((zmin, zmax + 1))
예제 #2
0
from solutions import helpers

filename = 'input'

instructions = helpers.read_each_line_as_string(filename)

(x, y, aim) = (0, 0, 0)
for instruction in instructions:
    (direction, amt) = instruction.split()
    amt = int(amt)
    match direction:
        case "forward":
            x += amt
            y += amt * aim
        case "down":
            aim += amt
        case "up":
            aim -= amt


print(x, y)
print(x*y)