コード例 #1
0
def main():
    rules_and_words = InputReader.fetch_input_lines()
    rules, words = seperate_rules_from_words(rules_and_words)
    rules = format_rules(rules)
    sol = "^" + build_regex(rules, "0", {}) + "$"
    print(sol)
    result = sum([1 for word in words if regex.match(sol, word)])
    print(result)
コード例 #2
0
def set_black_tiles(rounds):
    tiles = InputReader.fetch_input_lines()
    black_tiles = find_black_tiles(tiles)
    grid = initalize_grid(rounds)
    for black_tile in black_tiles:
        x_offset, y_offset = key_to_coords(black_tile)
        x = (2 * rounds) + x_offset
        y = (2 * rounds) + y_offset
        grid[x][y] = True
    return grid
コード例 #3
0
def main():
    ribbon_length = 0
    dimension_sets = InputReader.fetch_input_lines()
    for dimensions in dimension_sets:
        x, y, z = parse_dimensions(dimensions)
        xy = (2 * x) + (2 * y)
        xz = (2 * x) + (2 * z)
        yz = (2 * y) + (2 * z)
        ribbon_length += (x * y * z) + min(xy, xz, yz)
    print(ribbon_length)
コード例 #4
0
def main():
    sq_feet_wrapping_paper = 0
    dimension_sets = InputReader.fetch_input_lines()
    for dimensions in dimension_sets:
        x, y, z = parse_dimensions(dimensions)
        xy = x * y
        xz = x * z
        yz = y * z
        sq_feet_wrapping_paper += (2 * xy) + (2 * xz) + (2 * yz) + min(
            xy, xz, yz)
    print(sq_feet_wrapping_paper)
コード例 #5
0
def main():
    rules_and_words = InputReader.fetch_input_lines()
    rules, words = seperate_rules_from_words(rules_and_words)
    rules = format_rules(rules)
    mem_42 = build_regex(rules, "42", {})
    mem_31 = build_regex(rules, "31", {})
    solution_set = set()
    max_word_size = 0
    for word in words:
        max_word_size = max(max_word_size, len(word))
    for x in range(1, max_word_size):
        memo = {}
        memo["8"] = mem_42 + "+"
        memo["11"] = "(" + mem_42 + "){" + str(
            x) + "}" + "(" + mem_31 + "){" + str(x) + "}"
        sol = "^" + build_regex(rules, "0", memo) + "$"
        results = [word for word in words if regex.match(sol, word)]
        for result in results:
            solution_set.add(result)
    for blah in solution_set:
        print(blah)
    print(len(solution_set))
コード例 #6
0
def main():
    final_result = 0
    problems = InputReader.fetch_input_lines()
    reworked_problems = [shunting_yard(problem) for problem in problems]
    results = [evaluate(problem) for problem in reworked_problems]
    print(sum(results))
コード例 #7
0
def main():
    foods = InputReader.fetch_input_lines()
    alergen_to_words = map_alergens_to_words(foods)
    alergen_to_word = match_alergen_to_word(alergen_to_words)
    print_canonical_list(alergen_to_word)
コード例 #8
0
def main():
    nice_word_count = 0
    for word in InputReader.fetch_input_lines():
        if is_nice_word(word):
            nice_word_count += 1
    print(nice_word_count)
コード例 #9
0
def main():
    tiles = InputReader.fetch_input_lines()
    black_tiles = count_black_tiles(tiles)
    print(len(black_tiles))
コード例 #10
0
def main():
    foods = InputReader.fetch_input_lines()
    alergen_to_word = map_alergens_to_words(foods)
    print(count_non_alergen_ingredients(alergen_to_word, foods))