Add day part 2
parent
eae5d96cf4
commit
0fd7b3dc96
|
@ -10,7 +10,7 @@ def parse_input() -> tuple[list[int], list[int]]:
|
||||||
line2.append(int(num2))
|
line2.append(int(num2))
|
||||||
return line1, line2
|
return line1, line2
|
||||||
|
|
||||||
def main() -> int:
|
def part_1():
|
||||||
line1, line2 = parse_input()
|
line1, line2 = parse_input()
|
||||||
line1.sort()
|
line1.sort()
|
||||||
line2.sort()
|
line2.sort()
|
||||||
|
@ -21,6 +21,22 @@ def main() -> int:
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
def part_2():
|
||||||
|
line1, line2 = parse_input()
|
||||||
|
|
||||||
|
appears = {}
|
||||||
|
for line in line2:
|
||||||
|
appears[line] = appears.get(line, 0) + 1
|
||||||
|
|
||||||
|
result = sum(appears.get(num, 0) * num for num in line1)
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
print("Part 1: ", end="")
|
||||||
|
part_1()
|
||||||
|
print("Part 2: ", end="")
|
||||||
|
part_2()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue