if any(v == 2 for v in count.values()): twos += 1 if any(v == 3 for v in count.values()): threes += 1 return twos * threes def part2(s: str): lines = s.splitlines() for i, line1 in enumerate(lines): for line2 in lines[i + 1:]: diff = 0 for x, y in zip(line1.strip(), line2.strip()): if x != y: diff += 1 if diff > 1: break if diff == 1: return "".join(x for x, y in zip(line1.strip(), line2.strip()) if x == y) if __name__ == "__main__": print("----- Part 1 -----") r1 = part1(get_input_content("2")) print(r1) print("----- Part 2 -----") r2 = part2(get_input_content("2")) print(r2)
return len(res) def part2(s: str): min_length = 1000000000 for rem in range(65, 91): res = [] for x in s: if ord(x) == rem or ord(x) == rem + 32: continue if res and abs(ord(res[-1]) - ord(x)) == 32: res.pop() else: res.append(x) if len(res) < min_length: min_length = len(res) return min_length if __name__ == "__main__": day = __file__.split("day")[-1].split(".")[0] input_content = get_input_content(day) print("----- Part 1 -----") r1 = part1(input_content) print(r1) print("----- Part 2 -----") r2 = part2(input_content) print(r2)