Skip to content

Commit

Permalink
Add solution part 2 day 4
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoMinheere committed Dec 4, 2023
1 parent 362b571 commit 89ba6ca
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions 2023/d4/python/solution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import time
import re
from functools import reduce

def p1(data):
answer = 0
Expand All @@ -21,12 +19,34 @@ def p1(data):

return answer


def p2(data):
pass
answer = 0

hand = {}
cards = {}

for i, line in enumerate(data):
card_number, rest = line.split(": ")
win_nums, own_nums = rest.split("|")
win_nums = [x for x in win_nums.replace(" ", " ").split(" ") if x.isnumeric()]
own_nums = [x for x in own_nums.replace(" ", " ").split(" ") if x.isnumeric()]

points_in_card = len([x for x in own_nums if x in win_nums])

cards[i] = {"copies": 1, "wins": points_in_card}

for i, v in cards.items():
for y in range(v["copies"]):
answer += 1
for w in range(i, i+v["wins"]):
cards[w+1]["copies"] += 1


return answer

if __name__ == "__main__":
with open("../input") as t:
# with open("2023/d3/input") as t:
data = t.read().splitlines()

start_p1 = time.time()
Expand All @@ -35,8 +55,8 @@ def p2(data):
p1_time = time.time() - start_p1
print("P1 took " + str(round(p1_time * 1000)) + " ms")

# start_p2 = time.time()
# answer_2 = p2(data, True)
# print(f"P2 answer = {answer_2}")
# p2_time = time.time() - start_p2
# print("P2 took " + str(round(p2_time * 1000)) + " ms")
start_p2 = time.time()
answer_2 = p2(data)
print(f"P2 answer = {answer_2}")
p2_time = time.time() - start_p2
print("P2 took " + str(round(p2_time * 1000)) + " ms")

0 comments on commit 89ba6ca

Please sign in to comment.