Cyno

joined 1 year ago
[–] [email protected] 1 points 1 year ago (3 children)

I went with a matrix approach and was just planning to handle it through indexes but kinda gave up halfway implementing the finding of numbers, their start/end positions... I'm guessing a regex but that might have issues if we have identical numbers later, so not sure. Will surely go back to it eventually though :P

[–] [email protected] 1 points 1 year ago

Thanks, I managed to find the culprit in the end however - I was using a forward-look of 5 characters for finding if it matches a word so in a string of a3two for example, it would register the two before the 3. It was an easy fix once i found the issue.

[–] [email protected] 1 points 1 year ago

Thanks, I managed to find the culprit in the end however - I was using a forward-look of 5 characters for finding if it matches a word so in a string of a3two for example, it would register the two before the 3. It was an easy fix once i found the issue.

[–] [email protected] 3 points 1 year ago

Was pretty simple in Python with a regex to get the game number, and then the count of color. for part 2 instead of returning true/false whether the game is valid, you just max the count per color. No traps like in the first one, that I've seen, so it was surprisingly easy

def process_game(line: str):
    game_id = int(re.findall(r'game (\d+)*', line)[0])

    colon_idx = line.index(":")
    draws = line[colon_idx+1:].split(";")
    # print(draws)
    
    if is_game_valid(draws):
        # print("Game %d is possible"%game_id)
        return game_id
    return 0

            
def is_game_valid(draws: list):
    for draw in draws:
        red = get_nr_of_in_draw(draw, 'red')
        if red > MAX_RED:
            return False
        
        green = get_nr_of_in_draw(draw, 'green')
        if green > MAX_GREEN:
            return False
        
        blue = get_nr_of_in_draw(draw, 'blue')
        if blue > MAX_BLUE:
            return False    
    return True
        
            
def get_nr_of_in_draw(draw: str, color: str):
    if color in draw:
        nr = re.findall(r'(\d+) '+color, draw)
        return int(nr[0])
    return 0


# f = open("input.txt", "r")
f = open("input_real.txt", "r")
lines = f.readlines()
sum = 0
for line in lines:
    sum += process_game(line.strip().lower())
print("Answer: %d"%sum)
[–] [email protected] 1 points 1 year ago (2 children)

Do share if you find the input that was causing trouble, I'm tripping on some miniscule error as well and i have no idea what could it be

[–] [email protected] 3 points 1 year ago (2 children)

Oh god, sorry to hear that 😅i'm feeling desperate enough to try that, i just wrote a different implementation and i get the same (wrong) result. At this point I just want to know what i misunderstood or mistyped cuz its driving me crazy

[–] [email protected] 1 points 1 year ago (4 children)

I'm stuck on one of these intricacies now! I saw some of the ideas on how other people did it but i honestly have no clue what i did wrong. Got any tricky examples to share?

[–] [email protected] 1 points 1 year ago

Oh sorry, just saw this thread and got excited, will delete to keep it clean

[–] [email protected] 1 points 1 year ago

Fetches from the database again, it's just a temporary bundle of data rather than a persistent cache. We have caching for commonly-read/rarely-updated entities but its not feasible for everything ofc.

[–] [email protected] 2 points 1 year ago (1 children)

If you find or run into that article later please share it, I'd definitely like to read it!

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Ah sorry, forgot to mention it here because I originally posted it on csharp and then crossposted. I'm specifically thinking about c#, EF and .net core for web dev.

view more: ‹ prev next ›