mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-12-22 05:41:51 +01:00
Solve day3 part 2
This commit is contained in:
parent
2e029f2b8f
commit
4acef023c2
1 changed files with 15 additions and 6 deletions
|
@ -7,8 +7,8 @@ def main(filename: str, expected_part_1: int = None, expected_part_2: int = None
|
|||
with open(filename) as f:
|
||||
data = f.read().strip().split("\n")
|
||||
|
||||
data = parse_data(data)
|
||||
solution_part_1 = solve_part_1(data)
|
||||
data_1 = parse_data(data)
|
||||
solution_part_1 = solve_part_1(data_1)
|
||||
|
||||
print(f"1. Found {solution_part_1}")
|
||||
if expected_part_1:
|
||||
|
@ -41,10 +41,19 @@ def solve_part_1(data: DataType) -> int:
|
|||
return total
|
||||
|
||||
|
||||
def solve_part_2(data: DataType) -> int:
|
||||
return 0
|
||||
def solve_part_2(data: List[str]) -> int:
|
||||
total = 0
|
||||
for chunk in chunks(data, 3):
|
||||
common_letter = set(chunk[0]).intersection(set(chunk[1])).intersection(set(chunk[2])).pop()
|
||||
total += string.ascii_letters.index(common_letter) + 1
|
||||
return total
|
||||
|
||||
|
||||
def chunks(data, size):
|
||||
for i in range(0, len(data), size):
|
||||
yield data[i:i+size]
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("inputs/day03-test1", expected_part_1=157)
|
||||
main("inputs/day03", expected_part_1=7716)
|
||||
|
||||
main("inputs/day03-test1", expected_part_1=157, expected_part_2=70)
|
||||
main("inputs/day03", expected_part_1=7716, expected_part_2=2973)
|
||||
|
|
Loading…
Reference in a new issue