コード例 #1
0
def solve_part_two():
    slopes = [(1, 1), 
            (1, 3),
            (1, 5),
            (1, 7),
            (2, 1)]

    map = get_list_from_file("aoc_2020_03_input")
    tree_counts = [get_trees_for_slope(map, row, column) for (row, column) in slopes]

    product = 1
    for tree_count in tree_counts:
        product *= tree_count 

    print(product)
コード例 #2
0
        return 0
    if found == "#":
        return 1 
    
    return check_for_neighbor_in_direction(test, test_index, direction)
    
run = 0

test_input = """L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL""".split("\n")

input = get_list_from_file("aoc_2020_11_input")
#input = test_input
input = pad_input(input) # Add extra buffer

width = len(input[0])
input = list("".join(input)) # Create list
output = list(input)
indices = [index for index, val in enumerate(input) if val != "*"] # Get indices we want to evaluate

draw_map(input, width)
run_turn_two(input, output, indices, width)
#2128
コード例 #3
0
    substring = string[start:end + 1]
    no_parens = substring.replace("(", "").replace(")", "")
    return string.replace(substring, str(eval_ltr(no_parens)), 1)


def solve_part_one(input):
    print(sum([int(eval_ltr(line)) for line in input_to_use]))


test_input = """2 * 3 + (4 * 5)
5 + (8 * 3 + 9 + 3 * 4 * 3)
5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))
((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2""".split("\n")

#input_to_use = test_input
input_to_use = get_list_from_file("aoc_2020_18_input")

solve_part_one(input_to_use)

# First attempt: 45283905003863
# Second attempt: 45283905029161 -- made sure to only replace first instance of string...

# 5 + 8 + ((5 * 9 * 7 * 9) * 8 * 8) + (8 * 7 + 8 * (6 + 9 * 3 * 2) * 6 + 6) + 3 * 9
# 5 + 8 + 181440 + 34566 + 3 * 9

# 8 * ((4 + 9 + 9) + 8) * (5 * 4 * (9 + 3 * 3 + 6) + 3) * (8 * 7 * 9 + (8 + 8 * 3 + 9 * 7) * (3 + 7 + 9) * 7) + 6
# 8 * 30 * 843 * 120099 + 6

# 3 * (2 + (9 * 2 * 2 + 8) * (7 * 6 * 7 * 3) * (3 * 9 * 7) * (6 * 6)) * 9 * 8 + 6
# 3 * 276051888 * 9 * 8 + 6
#59627207814
コード例 #4
0
def solve_part_one_final():
    map = get_list_from_file("aoc_2020_03_input")
    trees = get_trees_for_slope(map, 1, 3)
    print(trees)
コード例 #5
0
        "jmp", "nop") if "jmp" in command else command.replace("nop", "jmp")


def solve_part_two(commands):
    for index, command in enumerate(commands):
        converted_command = try_convert_command(command)
        if converted_command is None:
            continue

        converted_list = list(commands)
        converted_list[index] = converted_command

        accumulator, index = 0, 0
        evaluate(converted_list, index, accumulator, lambda com, index: index >
                 (len(com) - 1))


test_commands = """nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6""".split("\n")

commands = get_list_from_file("aoc_2020_08_input")
solve_part_one(list(commands))
solve_part_two(list(commands))