Skip to content

Commit

Permalink
day 4 part 1 complete. strip() FTW.
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-donco committed Dec 4, 2023
1 parent 8d17a58 commit 631da86
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
38 changes: 38 additions & 0 deletions day04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@


class LottoCard:
def __init__(self, card_number, list_of_winning_numbers, list_of_played_numbers):
self.card_number = card_number
self.winning_numbers = list_of_winning_numbers
self.played_number = list_of_played_numbers

def points(self):
card_points = 0
for win in self.winning_numbers:
if win in self.played_number:
if card_points == 0:
card_points = 1
else:
card_points = card_points * 2
return card_points


def part01(input_lines):
# working!
cards = []
total_points = 0
for game_card in input_lines:
(card, play_line) = game_card.split(":")
card_number = card.split(' ')[-1]
(winning_nums, played_nums) = play_line.split('|')
winning_list = [wn for wn in winning_nums.strip().split(" ") if wn.isnumeric()]
played_list = [pn for pn in played_nums.strip().split(" ") if pn.isnumeric()]
new_game_card = LottoCard(card_number, winning_list, played_list)
print(new_game_card.points())
total_points += new_game_card.points()
cards.append(new_game_card)
print(total_points)


def part02(input_lines):
pass
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import day01
import day02
import day03
import day04

if __name__ == '__main__':
today = '03'
today = '04'

if today == '04':
input_file = f'problem_inputs/day{today}_input.txt'
# input_file = f'problem_inputs/test_input.txt'
with open(input_file) as day_fp:
day_input = day_fp.readlines()
day_input = [f'{i}'.strip() for i in day_input]
day04.part01(day_input)
day04.part02(day_input)

if today == '03':
input_file = f'problem_inputs/day{today}_input.txt'
Expand Down

0 comments on commit 631da86

Please sign in to comment.