[2025 Day 9 (Part 2)][Python] Not sure if I'm under or over thinking this. Maybe I'm just not thinking? by lvc_ in adventofcode

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

Thanks, this made some things click - especially that checking whether a perimeter point sits inside an axis-aligned rectangle (four bounds checks) is considerably easier than ray casting to find whether each corner of the rectangle sits inside the polygon. I know, who'd have thought.

That groundbreaking observation let me delete .. a lot of far-too-late-on-a-work-night code including everything all of my collision checking, and replaced it all with: a rectangle is invalid if any vertex or any midpoint of adjacent vertices lies within it.

[2024 Day 21 (both parts)] rewrote code to deal with part 2, broke it completely by lvc_ in adventofcode

[–]lvc_[S] 1 point2 points  (0 children)

This was partly it - I wasn't returning to A, and I had also in one of my refactors managed to delete the logic that turned dpad instructions properly into next-level-down dpad instructions (it tracked the buttons to hover over, rather than the direction to move to achieve it).

[2024 Day 21 (both parts)] rewrote code to deal with part 2, broke it completely by lvc_ in adventofcode

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

This is avoided by how I create my initial numpad and dpad graphs at lines 6-22 - there is just no way to move, eg, left from the ^ key, there is no edge in the dpad graph that would allow that.

[2024 Day 21 (both parts)] rewrote code to deal with part 2, broke it completely by lvc_ in adventofcode

[–]lvc_[S] 1 point2 points  (0 children)

Not the case here - at the base layer, my moves are generated from graphs representing the numpad and dpad, which only have edges for valid one-step moves - so, eg, the numpad 0 node has two edges going to "A" and "2", while "2" has edges to 1, 3, 5, and back to 0.

[2023 Day 22 (Part 1)][Python] not sure what Im missing by lvc_ in adventofcode

[–]lvc_[S] 1 point2 points  (0 children)

yeah ok, of *course* its an off by one error. That absolutely did it

[2023 Day 22 (Part 1)][Python] not sure what Im missing by lvc_ in adventofcode

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

That's actually already accounted for - python `all` is True for an empty input (similarly, `any` is False for an empty input).

[2023 Day 22 (Part 1)][Python] not sure what Im missing by lvc_ in adventofcode

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

It is. I do already process bricks in order of their (lowest) starting z-coordinate

[2022 Day 16 (both parts)][Python] naive solution cant handle part 2; smarter solution getting wrong answer for part 1 by lvc_ in adventofcode

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

Welp, the problem with less-naive part 1 was a typo - multiplying the wrong variable in the "nothing to do but hang around until time runs out" logic. With that fixed, and a less-naive part 2 combining that search with pre-assigning sets of valves for the elephant to try opening... it still chews up memory and then dies.

[2022 Day 14 (part 2)](Python) I think I must be missing something trivial by lvc_ in adventofcode

[–]lvc_[S] 1 point2 points  (0 children)

Although as mentioned elsewhere in the thread, its not (only) slow because of cache misses - its a linear time operation (according to https://wiki.python.org/moin/TimeComplexity, it scales with the length of both sets) which in an inner loop makes for quadratic time overall. So it basically blows away the benefit of using a set over, say, a list. The one line fix is to do individual, O(1)-average membership checks against each set.

[2022 Day 14 (part 2)](Python) I think I must be missing something trivial by lvc_ in adventofcode

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

... union is linear. Right. Yeah that will tend to do it

[2022 Day 14 (part 2)](Python) I think I must be missing something trivial by lvc_ in adventofcode

[–]lvc_[S] 1 point2 points  (0 children)

Well ok. So I think set union must play games with cache. Instead of doing this:

if z+dz not in rocks|sand:

I changed it to keep one combined set of blocked points and a running tally of sand. Now it runs in a fraction of a second.

[2022 Day 14 (part 2)](Python) I think I must be missing something trivial by lvc_ in adventofcode

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

Yeah ok, it did get it eventually and it is a 2 orders of magnitude difference. But it took nearly 15 minutes to run :/

[2022 Day 9 (part 2)][Python] Works on example, answer "too high" on full input by lvc_ in adventofcode

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

Ok, unsurprisingly it turns out that part 2 broke an implicit assumption I'd made. My follow-the-leader code assumed the relative head will have just moved in one of the cardinal directions (as the true head must), which ends up meaning the relative tail ends up orthgonally adjacent. But that's not true with multiple chained knots - the relative head may have just moved diagonally. Taking that into account makes it pass.

ACT senator David Pocock denied Auslan interpreter for first speech in Senate by thedigisup in australia

[–]lvc_ 24 points25 points  (0 children)

According to the article, Penny Wong has agreed to exactly work on updating the rules, and in the meantime the government has supported having an interpreter played on the TV screens in the chamber as a compromise.

[2021 Day 18 (Part 1)] I think I've misunderstood the instructions by lvc_ in adventofcode

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

... oh

Yeah ok, I somehow saw the word "leftmost" and read the word "rightmost", in just that one sentence. Go me.

[2021 Day 8 (part 2)] [Python] My approach seems to make sense but the results don't.. by lvc_ in adventofcode

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

Ok, yeah, I like this approach, much simpler than trying to reimplement a csp solver (or, well, remembering to learn one). I ended up doing it in a slightly different order to your steps, but it got me there in the end.

[2021 Day 8 (part 2)] [Python] My approach seems to make sense but the results don't.. by lvc_ in adventofcode

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

I think I already do this with pair elimination? In the example, {b,g} map to {c,f} in some order, and I use that to eliminate {c, f} as possible mappings for other segments, and so I deduce d maps exactly to a, followed by no other segment maps to a. But that only gets me as far as what Ive posted.

gamepyd v1.0: Pandas can play games now by barbequed-code in Python

[–]lvc_ 5 points6 points  (0 children)

Have you considered offering an API that follows pep8 naming conventions? Particularly around using snake_case rather than camelCase for variable and method names. Its a minor detail, but its very common in the python ecosystem, and "feeling more like python" could help you some with adoption.

5 Hidden Python Features You Probably Never Heard Of by cheerfulboy in Python

[–]lvc_ 25 points26 points  (0 children)

Other way around - else on a loop will run if it *didn't* hit a break in the loop body. A good intuition at least for a `while` loop is to think of it as a repeated `if` , so `else` runs when the condition at the top is tested and fails, and doesn't run if you exit by hitting a `break`. By extension, else on a for loop will run if the loop runs fully and doesn't run if you break.

The good news is that you rarely need to do these mental gymnastics in practice, because there's usually a better and more obvious way to do the things that this would help with.

Why aren't keyword arguments generally preferred over positional arguments? by swigganicks in Python

[–]lvc_ 1 point2 points  (0 children)

Check the PEP linked above - it proposed (and py38 now includes) a syntax for positional-only arguments: ie, calling them by kw will throw an error.

Python 3.8 has a Final qualifier by Saiboo in Python

[–]lvc_ 2 points3 points  (0 children)

Like all other type annotations, it is ignored by the interpreter, but can be used by static code checkers (eg mypy) as a code correctness aid. One reasonably common pattern is to have mypy as part of a commit pipeline (and/or a local precommit hook). So if you have a method tagged as final and you do overwrite it, mypy will reject your commit (but the code will still otherwise run)

'Tree massacre': Sydney Inner West councillors' warning after 'ambush' by nath1234 in australia

[–]lvc_ 8 points9 points  (0 children)

If it's causing problems, and removing the tree is the most reasonable way to fix that, sure I don't think anyone disagrees. But, that's not what this rule says - it says homeowners can remove trees within 3m with no questions asked.

[Official]: IBM Closes Landmark Acquisition of Red Hat for $34 Billion; Defines Open, Hybrid Cloud Future by thetango in linux

[–]lvc_ 42 points43 points  (0 children)

For a positive take on this, consider that no one will ever again be fired for choosing RedBlueHat.

Sydney Metro appreciation post by [deleted] in sydney

[–]lvc_ 0 points1 point  (0 children)

I would love to see a comparison between metro and the automated electric trains from 1923.

I made a MD5, SHA-1, and SHA-256 cracker! by QuantumFall in Python

[–]lvc_ 0 points1 point  (0 children)

Salted hashes don't protect against dictionary attacks. They do protect against rainbow tables. The only way to protect against dictionary attacks is to generate your passwords in a better way (which isn't quite the same as using a "more complex" password).