Skip to content

Commit

Permalink
feat: 2023 day 4 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Dec 5, 2023
1 parent a890c45 commit b45107a
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 0 deletions.
43 changes: 43 additions & 0 deletions adventofcode/_2023/day4/challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from adventofcode.utils import open_input


def main():
data = open_input('adventofcode/_2023/day4/input.txt')
answer_1 = get_answer(data)
# answer_2 = get_answer(data)

print(answer_1)
# print(answer_2)

return answer_1


def get_answer(data):
"""
- you have a list of cards, one set is the winning numbers, one set is your numbers
- check if you have the winning numbers. You get a point for the first match, then doubled for every match
"""
answer = 0
for index, line in enumerate(data):
sanatized_line = line.split(':')[1].split('|')
winnings = sanatized_line[0].split()
my_nums = sanatized_line[1].split()

points = 0
for num in my_nums:
if num in winnings:
points += 1

if points == 1:
answer += 1
elif points >= 2:
temp = 1
for i in range(points - 1): # -1 hack to account for the 1st iteration not being included here
temp = temp * 2 # Double the answer for x num of points
answer += temp

return answer


if __name__ == '__main__':
main()
Loading

0 comments on commit b45107a

Please sign in to comment.