feat: day 4 part 2 done
This commit is contained in:
1 parent
3a76f01756
commit
17d8c24da4
3 files changed
+32
-2
No files matched your search
@@ -1,5 +1,9 @@
|
||||
from src.modules.day_4 import count_scratchcard_points
|
||||
from src.modules.day_4 import count_real_points, count_scratchcard_points
|
||||
|
||||
|
||||
def test_scratchcards():
|
||||
assert count_scratchcard_points(r"src/assets/day_4_test.txt") == 13
|
||||
|
||||
|
||||
def test_scratchcards_real():
|
||||
assert count_real_points(r"src/assets/day_4_test.txt") == 30
|
||||
@@ -3,6 +3,7 @@ import re
|
||||
|
||||
def run():
|
||||
print(f"Scratchcard points: {count_scratchcard_points(r'src/assets/day_4.txt')}")
|
||||
print(f"Scratchcard real points: {count_real_points(r'src/assets/day_4.txt')}")
|
||||
|
||||
|
||||
def count_scratchcard_points(path: str):
|
||||
@@ -13,6 +14,31 @@ def count_scratchcard_points(path: str):
|
||||
return total
|
||||
|
||||
|
||||
def count_real_points(path: str):
|
||||
card_list = read_scratchcards(path)
|
||||
card_index_list = [1] * card_list.__len__()
|
||||
index = 0
|
||||
while index < card_list.__len__():
|
||||
card = card_list[index]
|
||||
card_matchings = get_card_matchings(card)
|
||||
|
||||
if card_matchings != 0:
|
||||
for n_card_index in range(index + 1, index + card_matchings + 1):
|
||||
card_index_list[n_card_index] += card_index_list[index]
|
||||
|
||||
index += 1
|
||||
|
||||
return sum(card_index_list)
|
||||
|
||||
|
||||
def get_card_matchings(card: tuple[list[int], list[int]]) -> int:
|
||||
sum = 0
|
||||
for number in card[1]:
|
||||
if number in card[0]:
|
||||
sum += 1
|
||||
return sum
|
||||
|
||||
|
||||
def get_card_points(card: tuple[list[int], list[int]]) -> int:
|
||||
sum = 0
|
||||
for number in card[1]:
|
||||
|
||||
Reference in new issue
Block a user