def part1(content): yes_answer_count = 0 for answers in content: yes_answers = {} for question in answers: yes_answers[question] = 1 yes_answer_count += len(yes_answers) print("Sum of yes answers: {}".format(yes_answer_count)) def part2(content): answer_count = 0 for answers_group in content: answers_list = answers_group.split(" ") answers = answers_list[0] answer_list = [question for question in answers] for answers in answers_list[1:]: new_answer_list = [] for question in answers: if question in answer_list: new_answer_list.append(question) answer_list = new_answer_list answer_count += len(answer_list) print("Sum of yes answers: {}".format(answer_count)) if __name__ == "__main__": content = misc.read_content() part1(parse_lines(content, "")) part2(parse_lines(content, " "))
import sys sys.path.insert(0, "..") import misc def parse_lines(lines): c = [] for line in lines: c.append(line) return c def part1(content): pass def part2(content): pass if __name__ == "__main__": content = parse_lines(misc.read_content()) part1(content) part2(content)
n = count_occupied_2(content, x, y) if c == "L" and n == 0: new_content[y][x] = "#" elif c == "#" and n >= 5: new_content[y][x] = "L" return new_content def part2(content): new_content = apply_rules_2(content) while new_content != content: content = new_content new_content = apply_rules_2(content) count = 0 for line in content: for c in line: if c == "#": count += 1 print("# of occupied seats: {}".format(count)) if __name__ == "__main__": content = [list(line) for line in misc.read_content()] part1(content) part2(content)
if not has_sum: return number def part1(content): print( "First number which is not a sum to 2 numbers in the last 25 numbers: {}" .format(get_number_without_sum(content))) def part2(content): invalid_number = get_number_without_sum(content) for index in range(len(content)): sum_of_numbers = content[index] inner_index = index + 1 while sum_of_numbers < invalid_number: sum_of_numbers += content[inner_index] if sum_of_numbers == invalid_number: number_range = content[index:inner_index] print( "Sum of smallest and largest number in series: {}".format( min(number_range) + max(number_range))) inner_index += 1 if __name__ == "__main__": content = [int(n) for n in misc.read_content()] part1(content) part2(content)
def part2(content, num_rows, num_cols): increments = [ [1, 1], [3, 1], [5, 1], [7, 1], [1, 2], ] tree_counts = [] for increment in increments: x, y = increment tree_count = traverse(content, num_rows, num_cols, x, y) print("Right: {}, down {} - {}".format(x, y, tree_count)) tree_counts.append(tree_count) product = 1 for t in tree_counts: product *= t print("Product: {} * {} * {} * {} = {}".format(tree_counts[0], tree_counts[1], tree_counts[2], tree_counts[3], product)) if __name__ == "__main__": lines = misc.read_content() num_rows = len(lines) num_cols = len(lines[0]) content = "".join(lines) part1(content, num_rows, num_cols) part2(content, num_rows, num_cols)
num_3_differences, chain + [possible_rating] ]) elif diff == 3: configurations.insert(0, [ new_ratings, max_rating - diff, num_1_differences, num_3_differences + 1, chain + [possible_rating] ]) else: configurations.insert(0, [ new_ratings, max_rating - diff, num_1_differences, num_3_differences, chain + [possible_rating] ]) for all_used, num_1_differences, num_3_differences, _ in chains: if all_used: print("# 1 diff * # 3 diff = {} * {} = {}".format( num_1_differences, num_3_differences, num_1_differences * num_3_differences)) print("# of chains: {}".format(len(chains))) def part2(ratings): pass if __name__ == "__main__": ratings = [int(x) for x in misc.read_content("input_test_large.txt")] part1(ratings) part2(ratings)