• 83 Posts
  • 272 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle



  • Personally, I’ve yet to see a single American successfully use guns to protect any other constitutional right from government infringement.

    The Battle of Athens is probably the most uniquely clear-cut example of what you’re asking for, unless we count the American Revolutionary War itself.

    Other successful examples mostly involve activists using non-violent protest to push for change, while using firearms to protect themselves from violent reactionaries that would otherwise murder them. Notably, the civil rights movement of the 1950s and 60s. For a modern example, there’s various “John Brown Gun Clubs” and other community defense organizations providing security at LGBTQ events against fascist groups that seek to terrorize event-goers.

    It’s also worth noting that resistance is often worthwhile even if it doesn’t result in unqualified victory. For example, the Black Panthers’ armed cop-watching activities saved a lot of Black folks from brutal beatings at the hands of the police, even if the organization was eventually crushed by the federal government.

    I have seen lots of examples like Waco and Ruby Ridge, where the government should have tried harder to deescalate, but in the end, everyone died. The closest example I can think of where the government did backoff was the Bundy standoff and all those guys were “defending” was their ability to let their cattle graze illegally on federal land because they didn’t want to pay for access like everyone else.

    It sounds like you might be in a bit of a filter-bubble. I don’t mean any offense by this, it’s a normal thing that tends to happen to people. If the news sources you read and the people you talk to don’t mention these things because it doesn’t mesh with their worldview, how would you hear about them?
















  • Nim

    Part 1 was just a simple search. Part 2 looked like it just needed a trivial modification, but with the removal of the one-way tiles, the result I was getting was getting for the example was too large. I switched to a different method of determining the path length, but didn’t yet figure out what what I had been doing wrong. Since the search space was now significantly larger, my part 2 code took almost an hour to come up with the answer.

    I rewrote part 2 to simplify the maze into a graph with a node for each intersection and for the start and goal tiles, with edge costs equal to the path length between each. This resulted in significantly faster iteration (17 seconds instead of 52 minutes), but didn’t actually reduce the search space. I’m assuming there’s some clever optimization that can be done here, but I’m not sure what it is.

    The rewrite was still getting the wrong answer, though. I eventually figured out that it was including paths that didn’t actually reach the goal, as long as they didn’t revisit any nodes. I changed my recursive search function to return a large negative result at dead ends, which fixed the issue.






  • Nim

    I am not making good time on these anymore.

    For part 1, I walked through the dig plan instructions, keeping track of the highest and lowest x and y values reached, and used those to create a character grid, with an extra 1 tile border around it. Walked the instructions again to plot out the trench with #, flood-filled the exterior with O, and then counted the non-O tiles. Sort of similar to the pipe maze problem.

    This approach wouldn’t have been viable for part 2, due to the scale of the numbers involved. Instead I counted the number of left and right turns in the trench to determine whether it was being dug in a clockwise or counterclockwise direction, and assumed that there were no intersections. I then made a polygon that followed the outer edge of the trench. Wherever there was a run of 3 inward turns in a row, that meant there was a rectangular protrusion that could be chopped off of the main polygon. Repeatedly chopping these off eventually turns the polygon into a rectangle, so it’s just a matter of adding up the area of each. This worked great for the example input.

    Unfortunately when I ran it on the actual input, I ran out sets of inward turns early, leaving an “inside out” polygon. I thought this meant that the input must have intersections in it that I would have to untwist somehow. To keep this short, after a long debugging process I figured out that I was introducing intersections during the chopping process. The chopped regions can have additional trench inside of them, which results in those parts ending up outside of the reduced polygon. I solved this by chopping off the narrowest protrusions first.


  • Nim

    Another tough one. Judging by the relative lack of comments here, I wasn’t the only one that had trouble. For me this one was less frustrating and more interesting than day 12, though.

    I solved part 1 by doing a recursive depth-first search, biasing towards a zigzag path directly to the goal in order to establish a baseline path cost. Path branches that got more expensive than the current best path terminated early. I also stored direction, speed, and heat loss data for each tile entered. Any path branch that entered a tile in the same direction and at the same (or greater) speed as a previous path was terminated, unless it had a lower temperature loss.

    This ran pretty slowly, taking around an hour to finish. I took a break and just let it run. Once it completed, it had gotten pretty late, so I did a quick naive modification for part 2 to account for the new movement restrictions, and let that run overnight. The next day it was still running, so I spent some time trying to think of a way to speed it up. Didn’t really get anywhere on my own, so I started reading up on A* to refresh my memory on how it worked.

    The solution that I arrived at for the rewrite was to use Dijkstra’s algorithm to pre-compute a map of what the minimum possible costs would be from each tile to the goal, if adjacent tiles could be moved to without restriction. I then used that as the heuristic for A*. While I was writing this, the original part 2 program did finish and gave the correct answer. Since I was already this far in though, I figured I’d finish the rewrite anyway.

    The new program got the wrong answer, but did so very quickly. It turned out that I had a bug in my Dijkstra map. I was sorting the node queue by the currently computed cost to move from that node to the goal, when it instead should have been sorted by that plus the cost to enter that node from a neighbor. Since the node at the head of the queue is removed and marked as finalized on each iteration, some nodes were being finalized before their actual minimum costs were found.

    When using the A* algorithm, you usually want your heuristic cost estimate to underestimate the actual cost to reach the goal from a given node. If it overestimates instead, the algorithm will overlook routes that are potentially more optimal than the computed route. This can be useful if you want to find a “good enough” route quickly, but in this case we need the actual best path.



  • Nim

    I’m caught up!

    This one was pretty straighforward. Iterate through the beam path, recursively creating new beams when you hit splitters. The only gotcha is that you need a way to detect infinite loops that can be created by splitters. I opted to record energized non-special tiles as - or |, depending on which way the beam was traveling, and then abort any path that retreads those tiles in the same way. I meant to also use + for where the beams cross, but I forgot and it turned out not to be necessary.

    Part 2 was pretty trivial once the code for part 1 was written.