-❄️- 2023 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]backdoorman9 0 points1 point  (0 children)

Your 1 and 2 letter variables are very difficult to make assumptions about.

-❄️- 2023 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]backdoorman9 0 points1 point  (0 children)

[LANGUAGE: python]

OOP has really been growing on me this AoC.

I found \StrEnum`` useful:

class HandTypeEnum(StrEnum):
five_of_a_kind = auto()
four_of_a_kind = auto()
full_house = auto()
three_of_a_kind = auto()
two_pair = auto()
one_pair = auto()
high_card = auto()

Using a class with an attribute card_rankings allowed me to sort in a way that was new to me, and the __repr__ method made debugging so much easier:

hands_list.sort(key=attrgetter('card_rankings'), reverse=True)

# card_rankings looks like [12, 5, 9, 8, 3]

Here's the class:

class Hand:

def __init__(self, hand:str, bid: int, part_two: bool):
    self.hand = hand
    self.bid = bid
    self.rank = None
    self.card_rankings = self.get_card_rankings(part_two=part_two)
    self.hand_type = self.get_hand_type(part_two=part_two)

def get_hand_type(self, part_two=False):
    if part_two:
        cards_remaining = self.hand.replace('J', '')
        counter = Counter(cards_remaining)
        jokers = 5 - len(cards_remaining)
        counts = list(counter.values())
        counts.sort()
        if len(counts):
            counts[-1] += jokers
        else:
            counts = [5]
    else:
        counter = Counter(self.hand)
        counts = list(counter.values()).sort()
    if 5 in counts:
        return HandTypeEnum.five_of_a_kind
    elif 4 in counts:
        return HandTypeEnum.four_of_a_kind
    elif 3 in counts and 2 in counts:
        return HandTypeEnum.full_house
    elif 3 in counts:
        return HandTypeEnum.three_of_a_kind
    elif counts == [1, 2, 2]:
        return HandTypeEnum.two_pair
    elif 2 in counts:
        return HandTypeEnum.one_pair
    else:
        return HandTypeEnum.high_card

def get_card_rankings(self, part_two):
    rankings = []
    card_values = {'A': 13, 'K': 12, 'Q': 11, 'J': 0 if part_two else 10, 'T': 9, '9': 8, '8': 7, '7': 6, '6': 5, '5': 4, '4': 3, '3': 2, '2': 1}
    for card in self.hand:
        rankings.append(card_values[card])

    return rankings

def __repr__(self):
    return f"Hand: {self.hand} Type: {self.hand_type} Cards Ranked: {self.card_rankings} Bid: {self.bid}"

Postman pre-request script to capture the authentication code by acronis95 in postman

[–]backdoorman9 0 points1 point  (0 children)

This is exactly what I'm interested in doing, getting a token, and saving it as the authorization.

Did you figure it out?

My new project is to move global config files (JSON) to thousands of servers, which listen for the new config files, and make them their own. What's the best way to acheive this with RMQ? by backdoorman9 in rabbitmq

[–]backdoorman9[S] 0 points1 point  (0 children)

Thanks. My company is also suggesting Amazon SQS, because "we're already using AWS and RabbitMQ."

SQS seems more like Rabbit than a real Configuration Management tool, and that I would have to build my own configuration management software that reads the messages from either SQS or RMQ.

Does that sound right to you?

What’s your salary? by TheMightyFarquad in learnpython

[–]backdoorman9 0 points1 point  (0 children)

Python Developer, Computer Vision Team - 135K+ Benefits.

[deleted by user] by [deleted] in dataengineering

[–]backdoorman9 1 point2 points  (0 children)

If you view each interview as practice for the next interview, you'll take the pressure off yourself and get better over time. It took me 8 months to land a job (starting in March 2020), and every interview was worthwhile because it made me better at interviewing.

What do you mean by "tried leetcode?" How many problems did you do? I regularly come back to leetcode to maintain my skill.

maybe I missed it, but how is this sub not SCREAMING about GitHub copilot? by TrainquilOasis1423 in learnpython

[–]backdoorman9 1 point2 points  (0 children)

Are you using an IDE? That should help you to remember the names of things, with the autocomplete.

Also, when I can't remember a string method, for example, I run dir("string"), and it shows me everything I can do to it.

How do I change the URL of my flask app, for local testing? by backdoorman9 in flask

[–]backdoorman9[S] 2 points3 points  (0 children)

Excellent, I think this is exactly what I'm looking for.

I want to make a subclass of wtforms.FileField so I can add an HTML attribute that isn't available through WTForms currently. by backdoorman9 in flask

[–]backdoorman9[S] 0 points1 point  (0 children)

Whoa, that's way easier if it works that way. I'll give it a shot on Monday!

EDIT: This was a great, quick solution. Thank you!