<- back

advent of code - day 7


See the puzzle here.

See my full solution here.

Part 1

As usual, the first part wasn't so bad. I think the trickiest part was determining if the hand was a full house or a three of a kind. Here's the snippet where I did that:

if(!isFiveOfAKind && !isFourOfAKind) {
 let hasThreeOfAKind = false;
 for(let i=0; i   if(hand.filter((card) => card === hand[i]).length === 3) {
   hasThreeOfAKind = true;
 if(hasThreeOfAKind) {
  for(let i=0; i    if(hand.filter((card) => card === hand[i]).length === 2) {
    isFullHouse = true;
 if(hasThreeOfAKind && !isFullHouse) {
  isThreeOfAKind = true;

Basically, I checked if there was a three of a kind, then I checked if there was also a pair. If there wasn't a pair, then it was just a three of a kind. If there was a pair, then it was a full house.

The other types of hands were pretty straight-forward to check for.

Part 2

To be honest, I almost gave up on this one.

I got it basically right pretty quickly, but whenever I submitted the answer to the site it said I was wrong. I spent an hour or two pouring over print statements of what was going on looking for the various edge cases I was missing.

Most of the edge cases were in situations where there were multiple wildcards, but in at least one case I had focused on the wildcards so much that I had messed up the logic for a normal hand with no wildcard.

Eventually, I ironed out all the bugs and got the right answer.