Fix black

This commit is contained in:
Gabriel Augendre 2022-12-03 22:30:29 +01:00
parent b5a01d5afb
commit c04ee4c040

View file

@ -25,7 +25,7 @@ DataType = list[tuple[str, str]]
def parse_data(data: list[str]) -> DataType: def parse_data(data: list[str]) -> DataType:
sacks = [] sacks = []
for line in data: for line in data:
stop = int(len(line) /2) stop = int(len(line) / 2)
halves = (line[:stop], line[stop:]) halves = (line[:stop], line[stop:])
sacks.append(halves) sacks.append(halves)
return sacks return sacks
@ -43,14 +43,17 @@ def solve_part_1(data: DataType) -> int:
def solve_part_2(data: list[str]) -> int: def solve_part_2(data: list[str]) -> int:
total = 0 total = 0
for chunk in chunks(data, 3): for chunk in chunks(data, 3):
common_letter = set(chunk[0]).intersection(set(chunk[1])).intersection(set(chunk[2])).pop() common_letter = (
set(chunk[0]).intersection(set(chunk[1])).intersection(set(chunk[2])).pop()
)
total += string.ascii_letters.index(common_letter) + 1 total += string.ascii_letters.index(common_letter) + 1
return total return total
def chunks(data, size): def chunks(data, size):
for i in range(0, len(data), size): for i in range(0, len(data), size):
yield data[i:i+size] yield data[i : i + size]
if __name__ == "__main__": if __name__ == "__main__":
main("inputs/day03-test1", expected_part_1=157, expected_part_2=70) main("inputs/day03-test1", expected_part_1=157, expected_part_2=70)