Skip to content

Commit

Permalink
Solve day 7 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 26, 2023
1 parent b4fd6d7 commit c9f10bf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions year_2023/day07/camel_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"2",
"J",
]
JOKER = "J"

Play = namedtuple("Play", ["hand", "bid"])

Expand All @@ -37,6 +38,15 @@ class HandType(Enum):

def _get_hand_type(hand, use_jokers=False):
counts = Counter(hand)
if use_jokers and JOKER in counts:
joker_count = counts[JOKER]
if joker_count == 5:
return HandType.FIVE_OF_KIND

del counts[JOKER]
most_common = counts.most_common(1)
counts[most_common[0][0]] += joker_count

if len(counts) == 1:
return HandType.FIVE_OF_KIND

Expand Down

0 comments on commit c9f10bf

Please sign in to comment.