Ejemplo n.º 1
0
def compat_position_extrinsic(o0, p0, n0, v0, o1, p1, n1, v1, scale):
    """ Find compatible versions of two representative positions (with specified normals and orientations) """
    t0, t1, middle = np.cross(n0, o0), np.cross(n1, o1), intermediate_pos(v0, n0, v1, n1)
    p0, p1 = lattice_op(p0, o0, n0, middle, scale), lattice_op(p1, o1, n1, middle, scale)
    x = min(all_combinations([0, 1], [0, 1], [0, 1], [0, 1]),
        key = lambda x : np.linalg.norm((p0 + scale * (o0 * x[0] + t0 * x[1])) - (p1 + scale * (o1 * x[2] + t1 * x[3]))))
    result = (p0 + scale * (o0 * x[0] + t0 * x[1]), p1 + scale * (o1 * x[2] + t1 * x[3]))
    return result
Ejemplo n.º 2
0
def compat_position_extrinsic(o0, p0, n0, v0, o1, p1, n1, v1, scale):
    """ Find compatible versions of two representative positions (with specified normals and orientations) """
    t0, t1, middle = np.cross(n0, o0), np.cross(n1, o1), intermediate_pos(
        v0, n0, v1, n1)
    p0, p1 = lattice_op(p0, o0, n0, middle,
                        scale), lattice_op(p1, o1, n1, middle, scale)
    x = min(all_combinations([0, 1], [0, 1], [0, 1], [0, 1]),
            key=lambda x: np.linalg.norm(
                (p0 + scale * (o0 * x[0] + t0 * x[1])) -
                (p1 + scale * (o1 * x[2] + t1 * x[3]))))
    result = (p0 + scale * (o0 * x[0] + t0 * x[1]),
              p1 + scale * (o1 * x[2] + t1 * x[3]))
    return result
Ejemplo n.º 3
0
def compat_orientation_extrinsic(o0, n0, o1, n1):
    """ Find compatible versions of two representative orientations (with specified normals) """
    return max(
        all_combinations([o0, np.cross(n0, o0), -o0, -np.cross(n0, o0)],
                         [o1, np.cross(n1, o1)]),
        key=lambda x: np.dot(x[0], x[1]))
Ejemplo n.º 4
0
            if property_tally[p] > 0:
                score *= property_tally[p]
            else:
                return (0, False)
    return score, calorie_target_met

ingredients_list = list()
recipes_list     = list()
best_ignoring_calories = 0
best_calorie_target    = 0

with open(puzzleinput) as f:
    for ingredients_text in f:
        i = list(re.match(regex, ingredients_text).groups())
        i = [i[0], int(i[1]), int(i[2]), int(i[3]), int(i[4]), int(i[5])]
        ingredient = dict(zip(['name'] + properties, i))
        ingredients_list.append(ingredient)

ingredient_names = [i['name'] for i in ingredients_list]
all_ingredient_combinations = all_combinations(ingredient_names, teaspoons)
for combination in all_ingredient_combinations:
    recipes_list.append(Counter(combination).items())

for recipe in recipes_list:
    current_score, calorie_target_met = score(recipe)
    best_ignoring_calories = max(current_score, best_ignoring_calories)
    if calorie_target_met:
        best_calorie_target = max(current_score, best_calorie_target)
print('part 1: %d' % best_ignoring_calories)
print('part 2: %d' % best_calorie_target)
Ejemplo n.º 5
0
def compat_orientation_extrinsic(o0, n0, o1, n1):
    """ Find compatible versions of two representative orientations (with specified normals) """
    return max(all_combinations([o0, np.cross(n0, o0), -o0, -np.cross(n0, o0)], [o1, np.cross(n1, o1)]),
        key = lambda x: np.dot(x[0], x[1]))