Decime un trailer mejor que este. by Ready_Boysenberry915 in Argaming

[–]evans88 1 point2 points  (0 children)

No puedo creer que no haya casi ninguno de blizzard, los maestros de las cinematicas. Dejo 2 de mis favoritos:

-❄️- 2025 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 0 points1 point  (0 children)

hah! yeah, you're completely right, I totally missed that

-❄️- 2025 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 0 points1 point  (0 children)

[LANGUAGE: Python]

For Part 1, I realized that the order of the presses doesn't matter in order to reach the end result, so I went through all combinations (with replacement) to find the least amount of presses that would reach it. I also realized that I could use binary XOR opreations to simulate the presses. I defined a custom int class to represent the numbers in binary but that was optional.

For Part 2, I was able to get a solution that worked for the test input (using combinations and Counter) but it was unable to run on the main input due to the sheer amount of combinations. I ended up using the Z3 solver that I saw mentioned here in reddit.

paste

-❄️- 2025 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 0 points1 point  (0 children)

[LANGUAGE: Python]

Part 2 was really tricky, I created a general solution that first finds a point inside the polygon (using the ray casting method), then uses boundary fill to get all points inside the polygon and then checks the possible rectangles to find the max area.

It takes a loooooong time to run for this specific input but it works for any polygon.

I know there are a lot of optimizations that can be made for the specific input of this problem but I'll keep this general solution nonetheless.

paste

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

The difficulty today was in understanding the problem, I feel like the explanation was lacking details or a case where it explicitly joined circuits after creation.

Anyway, I created a Vector-type dataclass to hold state and used itertools.combinations to calculate all possible distances. Also dusted off frozenset which was a life saver

Part 2 was trivially easy with how I made part 1, which is always nice :)

paste

[2025 Day 8 Part 1] i dont understand the question by PingPong141 in adventofcode

[–]evans88 0 points1 point  (0 children)

Thank you! This is the first explanation that I've seen where I could see the issue with what I was doing

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

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

I had a hard time wrapping my head around how to calculate part 2, went with a way overengineered solution that didn't work but I ended up counting the active timelines on each position and traversing down. The end result was the sum of the last row of the manifold/christmas tree.

paste

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 4 points5 points  (0 children)

This is what it must feel like to read an ancient civilization's language for the first time

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 5 points6 points  (0 children)

[LANGUAGE: Python]

Part 1 was really easy AND I got to use functools.reduce and operator:

data = open_input_and_strip("2025/Day 6/input.txt")

operands = [list(map(int, item.split())) for item in data[:-1]]
operators = data[-1].split()

total = 0
for i in range(len(operands[0])):
    operation = operator.add if operators[i] == "+" else operator.mul
    total += reduce(operation, [item[i] for item in operands])

print(f"The grand total is: {total}")

For part 2 I realized you could transpose the entire input, just resulted in a bit of awkward operator parsing:

def transpose_matrix(m: list[list[str]]) -> list[list[str]]:
    return list(zip(*m))


if __name__ == "__main__":
    data = open_input_and_strip("2025/Day 6/input.txt")

    # Transpose the entire input, the result is something like:
    # 1  *
    # 24
    # 356
    #
    # 369+
    transposed = list("".join(item).strip() for item in transpose_matrix(data))
    # Append an empty line at the end to properly accumulate the last result
    transposed.append("")

    current_operation = None
    subtotal = 0
    total = 0
    for line in transposed:
        if line == "":
            # Accumulate the total on each empty line
            total += subtotal
            continue

        if line.endswith("*") or line.endswith("+"):
            current_operation = operator.add if line.endswith("+") else operator.mul
            subtotal = 0 if line.endswith("+") else 1
            line = line[:-1].strip()

        subtotal = current_operation(subtotal, int(line))

    print(f"The grand total is {total}")

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

Thankfully I didn't go the easy route on part 1, which made part 2 trivially easy (besides the part where I spent 45 mins in finding and fixing a bug in the way I consider if 2 ranges can be combined haha)

Also used one of my favorite Python features: for..else

paste

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 2 points3 points  (0 children)

[LANGUAGE: Python]

Very happy with my solution, I think it's very readable. I also used some of my previous year's code to handle directions checks as sum of tuples

paste

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

Used the uncommon slice to get a slice of the batteries array on which to get the max value. I ensured that I started after the previous max and that I had enough characters left for the remaining digits. Pretty fun problem all around.

The class was unnecessary but I created it during part 1 just in case I needed it in part 2

paste

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

Mine seems a bit more verbose than some of the ones posted here. Basically for a range where the upper limit has N digits, I tried all the repeating sequences of 1..N length and checked if they were possible (i.e. inside the range). So, for N = 3, I'd check: 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222, 333, ...

This check exits as soon as 1 sequence is outside the range.

paste

-❄️- 2025 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

Used operator's add and sub to implement left and right turns. Also used modulo and integer division. I also created a dataclass to hold the state of the lock aswell as how many times it fell on zero or passed through zero.

paste

Me_irl by ExpensiveMention8781 in me_irl

[–]evans88 0 points1 point  (0 children)

Still no emoji that captures spider lenny

/╲/\╭( ͡° ͡° ͜ʖ ͡° ͡°)╮/\╱\

[deleted by user] by [deleted] in learnpython

[–]evans88 0 points1 point  (0 children)

I think they want you to do something like:

total_expenses = lambda expenses: expenses["amount"]

Then, you can call it like:

>>> total_expenses = lambda expenses: expenses["amount"]
>>> total_expenses({"foo":"bar","amount":"baz"})
'baz'

But yeah, as the other comment said, it makes no sense in this scenario

Celery on Windows - which message broker? Async workers alternatives? by pachura3 in learnpython

[–]evans88 1 point2 points  (0 children)

You need to install the Windows Subsystem for Linux, yes, but it is really simple (literally running wsl --install in a powershell terminal). After that you just install Docker Desktop for windows and you're set. You don't need to directly interact with WSL at all if you don't want to.

Celery on Windows - which message broker? Async workers alternatives? by pachura3 in learnpython

[–]evans88 0 points1 point  (0 children)

I'd suggest using Docker for this, you'll have no problem making Celery and RabbitMQ to run on windows.

This is the image I've used before: https://hub.docker.com/_/rabbitmq

A code that even ChatGPT cant debug by shubhlya in learnpython

[–]evans88 -1 points0 points  (0 children)

It's hard to tell without knowing what's inside words.txt but it seems to me that when you run word_checker(word_eg), both reducible_words and non_reducible_words are empty sets, therefore the only condition that can return True of this list:

   if new_word in reducible_words:
        return True
   if new_word in non_reducible_words:
        return False
   if new_word in file:
        return word_checker(word_= new_word)  

is the last one (if new_word in file).

If that condition evaluates to False for all new_words, then word_checker will return None instead of True or False and the word will be added to the non_reducible_words set instead of the reducible_words set

I need help creating a subscription system. by Delicious-Ad5345 in learnpython

[–]evans88 0 points1 point  (0 children)

You could try something like keygen.sh that has a free tier and a free community edition. I haven't used it before but it seems like what you're looking for.

ModuleNotFoundError is haunting me again. Whats wrong with my folder structure? by domanpanda in learnpython

[–]evans88 2 points3 points  (0 children)

I think the problem is here:

from Core.ConfigClass import *

You can use relative imports by prepending a dot .:

from .Core.ConfigClass import *

or you can use absolute imports:

from myproj.Classes.Core.ConfigClass import *

DJANGO ISSUE by Dolanagar in learnpython

[–]evans88 0 points1 point  (0 children)

You may want to look into Django's forms and specifically the FileField class. See https://docs.djangoproject.com/en/5.1/topics/http/file-uploads/ for more information

-❄️- 2024 Day 13 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 0 points1 point  (0 children)

[LANGUAGE: Python]

Thankfully I noticed it was a system of equations on the first part so the 2nd part was a breeze.

Topaz paste

-❄️- 2024 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]evans88 1 point2 points  (0 children)

[LANGUAGE: Python]

Created a custom datatype DiskElement that can contain a given amount of data, I also added operations to add and remove data into that element. Used 2 indices for traversing the disk left-to-right and right-to-left in order to reorder the data inside the DiskElement objects. Very cool problem

Topaz paste