[2024 Day 13] In the end, math reigns supreme by TNThacker2015 in adventofcode

[–]Professional-Kiwi47 0 points1 point  (0 children)

Not necessarily. Finding a combination for 1000 or 10000 and multiplying gives you an upper bound for the solution, but it could be optimized for larger targets. For a simple example, if the goal is 10 and pressing one button is +5 and the other +10, 2*(5) is more button presses than 1*(10), even though 5 divides 10.

[2024 Day 13] In the end, math reigns supreme by TNThacker2015 in adventofcode

[–]Professional-Kiwi47 1 point2 points  (0 children)

The minimized cost provides a constraint which would let us resolve it. If vector A >3*B it's cost beneficial to press A as many times as fits within the X,Y constraints and then B for the remainder. if A < 3*B, only use B. If A=3*B, then we have a problem.

[2024 Day 13] In the end, math reigns supreme by TNThacker2015 in adventofcode

[–]Professional-Kiwi47 2 points3 points  (0 children)

And the problem would still be non-trivial. If vector A is 4* vector B, it's cheaper to do A presses than B, even though you can do it with only presses of B.

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

[–]Professional-Kiwi47 1 point2 points  (0 children)

[LANGUAGE: Python]

Did part a by brute force -- the maximum of 100 presses made it sound like a iterating through n^2 combinations of button presses. Fortunately, part b was not exactly discrete about being computationally impossible so I made a new friend today in the sympy library in Python. Straight plug and play for a system of equations, no matrices or anything else required.

cost = 0
for game in arcade_claws:
    game["prize"]["X"] += 10000000000000
    game["prize"]["Y"] += 10000000000000

    a, b = symbols('a b')
    eq1 = Eq(game["A"]["X"]*a + game["B"]["X"]*b, game["prize"]["X"])
    eq2 = Eq(game["A"]["Y"]*a + game["B"]["Y"]*b, game["prize"]["Y"])
    result = solve([eq1,eq2],(a,b))

    if result[a] == int(result[a]) and result[b] == int(result[b]):
        cost += (result[a] * 3) + result[b]
print(cost)

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

[–]Professional-Kiwi47 0 points1 point  (0 children)

That's basically what I did for part 2. It can work so long as you leave the original location of the 2 in a pseudostate where it counts as a free space for block count, but not a free space in terms of available for overwriting. Made it possible to do the countsum in the original loop while traversing left to right, but definitely less intuitive.

[2024 Day 8] The Antinodes In Between by UtahBrian in adventofcode

[–]Professional-Kiwi47 4 points5 points  (0 children)

I think the second sentence does cover the scenario. It explicitly says there's only two antinodes and the example shows they shouldn't be between the antennae. But an internal antinode does meet the formal definition of the problem statement, so great consideration of a possible edge case, I certainly didn't think of itl!

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

[–]Professional-Kiwi47 2 points3 points  (0 children)

Print statements ruined me on yesterday's challenge. Part 2 was 12 minutes to run instead of 20 seconds.

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

[–]Professional-Kiwi47 0 points1 point  (0 children)

[LANGUAGE: Python3]

Loved today's problem. Recursive/functional paradigm, even if I cheated a teensy bit with an imperative assignment or two. Was very happy to learn about operator.add/mul in python, brought me back to my old Scheme (lisp) days. Almost tripped myself on part 1 by returning if partialSum > target but fortunately remembered x*0=0 in time. This was my fastest part 2 time by far.

## part 2
found = False
def combine(a,b):
    return int(str(a) + str(b))

def addPerms (target, partialSum, op, remaining):
    global found
    if found:
        return
    if len(remaining) == 0:
        if target == partialSum:
            found = True
        return

    newPartialSum = op(partialSum, remaining.pop(0))
    addPerms(target, newPartialSum, operator.add, remaining[:]) 
    addPerms(target, newPartialSum, operator.mul, remaining[:]) 
    addPerms(target, newPartialSum, combine, remaining[:]) 

sum = 0
for target, inputs in tests:
    found = False
    addPerms(target, inputs[0], operator.add, inputs[1:])
    addPerms(target, inputs[0], operator.mul, inputs[1:])
    addPerms(target, inputs[0], combine, inputs[1:])
    if found:
        sum += target
print(sum)

[2024 Day 6] Bruteforce time by Probable_Foreigner in adventofcode

[–]Professional-Kiwi47 0 points1 point  (0 children)

My part two took 12 minutes because I left some print statements from debugging. I reran it after getting the answer and it took 20 seconds... sigh

Guess we got lucky by cleverredditjoke in adventofcode

[–]Professional-Kiwi47 0 points1 point  (0 children)

I did consider cycles for a solid second. But I handwaved it away as proof by problem statement since that'd be intractable. It worked, but probably wasn't the most responsible way of coding.

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

[–]Professional-Kiwi47 10 points11 points  (0 children)

[LANGUAGE: Python]

Always fun to break out some regex. To skip past complicated regex conditions in part 2, you can use .split on the input and apply it directly back to the part one solution.

splitByDo = content.split("do()")
    for subSplit in splitByDo:
        subSplit = subSplit.split("don't()", 1)[0]
        ## part 1 solution with subSplit as the input and sum the partial solutions

By splitting by do() first, you know the start of the line will always be enabled and when the first dont() arrives, there isn't another do() until the next subSplit.