My slightly profane and crass notes for Advent of Code Problems.
Nothing I put here should be taken as a critizism of the contest itself, which is amazingly well done and awesome.
Can you compare some numbers?
How about a rolling sequence of numbers?
Align some crabs to explode some holes.
Basic loops and some adding.
How much can you over complicate and inductive logic? A lot? I bet it is a lot.
You have a field of numbers. Find low points.
Find the low points.
Find the area of basins that feed into the low points. The problem statement eleminates the hard bits for you.
XKCD - https://xkcd.com/297/
Can you use a stack as you parse?
Can you break your above code and record different numbers? (also, remember that int sucks, and long rules)
Conways game of life with some modifications. Normally you do conways with two maps, before and after. And you base after only on before to avoid tripping yourself up. With this one, the beasts can chain flash so you can't do that.
So the easy way is to have some special values for things that have flashed and can't flash anymore. I used -2.
Run some cycles.
Run some cycles until they all flash.
Easy as eating pancakes.
Basic recusive path counting with some funny rules. Used memoization, but didn't actually need it.
Some simple folding points around in a 2d map. Thank fuck there were no rotations. I always fuck up rotations.
This was a fun one. It comes down to a memoized recursive count.
A simple search problem. "Wrap over 9 to 1" is not the same thing as mod 10, clownass. Wasted a lot of time on that.
The key here is to use a form where you can read one bit at a time. Turning the hex into a bit string and then recording the position works well. The parsing is simple as long as you pay attention to the rules.
Throw some things into a target. Pretty straight forward dx and dy simulation. Tricks: For some weird reasons, the dy range can be negative or positive.
Fucking shit snail math. Basically, are you good at binary tree modifications.
This one is fun. The only weird part is the "explode" operation which involves digging around in the tree for things to twiddle. Trick there is to do an in order traversal list and use that to find your things to twiddle.
Insert dick into bear trap. Thrust through the pain.
Basically, take some sets of coordinates, permute them in 24 ways and try to map them onto each other until all your blood is gone. No problems.
One trick is that if you start with one sensor and then add other sensors to that map as they match enough, you'll have some sensors that can't be added. Those need to be merged into one glob and then the two globs can match up and touch each other.
This first feels like a pretty standard conways sort of thing.
But the problem is that depending on the inputs the infinite area might be 1 rather than zero. Ha. So you could do something silly like go X outside of initial area and say fuck the noise outside or could determine a default value for things in the new map on each iteration.
Can you manage to use some range rules to determine what things maps to what things. Then repeat that as you reduce the number of outstanding things.
Can you do Conway's game of life in 3d? Easy, just don't screw up the neighbors.
What about 4D? Ha ha ha. Don't worry about visualizing it. Also, debugging is impossible. Don't write bugs.
Can write an expression processor for some bullshit math rules. Also, use longs.
Recursive decent parser. Or something.
In this problem you have a bunch of 2d map tiles that you need to stitch together where they match up.
Can you rotate and flip? Can you do a recursive search? Not super hard but lots of details.
Now do some more silly modifications and look for given pattern.
Use logic to make conclusions about mappings of items to alergens.
Do some basic logic.
Find the full mapping. If you did part 1 in a reasonable way, this is easy.
Crab war cards.
Can you follow basic rules.
Can you manage some oddly phrased recusion rules.
Those crabs want to play some weird cup game.
Can you manipulate a linked list of things with some sort of cursor and add and remove things without screwing up?
Times 10 million because fuck your cpu and your shit ArrayList implementation
Some hex grid for a hotel lobby.
Can you walk a hex grid without tripping on own face?
Now play conways game of life on it.
Some weird public key RFID thing. Basically do pow-mod a bunch or don't. Whatever.
Can you write a for loop? You think it is complicated, but it isn't.
Did you get all the stars and can you press a button? It took me almost three minutes to press the button.
This is a run this assembly code problems.
I don't even know. Part 1 is easy, you run the program and it exits.
This thing runs forever. It is counting to some number of millions over and over again. You can skip some, but some of them cause magic to happen. I still don't understand it. It has something to do with the factors of some of the inputs and multipling the factors.
Don't ask me.
Wherein you run a small bit of assembly like code to figure out what inputs cause the program to terminate and what inputs cause it to run forever (or just a long time).
I spent a long time being stupid about this one. Then I realized, it doesn't read the input! At all! Well, except one compare and if it is equal, then it exits.
So you just run it and when it does the compare operation that does read the input, write down the value it compared.
Return the first value that is compared to the "input"
Keep running the problem, saving each value compared as it runs. The last new value is the winner and you are done when you get a repeat.
Basically, two problems. A parsing problem and a simulation problem. Fairly straight forward.
Wheeeeeee
Wrinkle here is there can be ties where neighter army can damage the other. Also, do it a lot.
hello string
hello lists with a little bit of mod
Fun with spirals. The trick here is to keep track of the direction you are moving as you write it out.
List -> set list.size == set.size (part 1) list -> set of sorted strings (part 2)
Problem involving jumping around. Just requires careful reading of the statement and tracking of things.
Can you follow instructions and track previous states in some sort of set?
This one is pretty simple. I thought it might get hard, like that one with the lumberjacks and the cycles and going to a billion iterations but it wasn't.
Can you handle an n-ary tree?
Fairly straight forward. Part parse problem part simulation.
A fun recursive parsing problem.
Can handle this with a finite state machine. Or with just programming.
Knot a bad problem. Mostly don't be dumb.
Basic hex grid problem. There are a bunch of ways to map a hex grid into x,y coords.
I prefer the one where straight north is -2y and south is -2y, and the angle ones are 1 x and 1 y.
Then distance is ceil( abs(x) + abs(y) / 2 ) since each step can cover 2 bits.
Pretty much a graph coloring. No bigs.
This one involves seeing when various scanners get to zero. Tricks: In the first part, you measure a score, which ends up being zero for the first scan because it multiplied by zero (position). In the second part, you need to count hits (even if the score is zero). Also, the scanner back and forth isn't as simple as it seems. Basically the period for each scan is d + (d - 2)
A simple register problem. Only trick is that I didn't notice that some values where register names and some where literals. You just have to see which as you process them.
For part 2, the easy way is to execute them until they block for input and return number of ops it does. When both are blocked and do zero ops, then you are deadlocked. Easy as eating pancakes.
This one is a really fun ascii rail shooter. Trick: use a direction vector to avoid a bunch of stupid special case code: Example: starting direction is (x=0, y=1). You just add that to current location.
A pain in the ass debug the assembly problem. Grrr.
Anyways, after reading the assmbly, it would counting the number of composit numbers (not prime) in a certain range when checking every 17. The loops I was trying to optimize out were doing real work, in that they were checking multiplication values. Bah.
What the fuck. I tried to do this with a regular A-star. Branching factor was way way too big. I tried to get clever with some recursive solution to finding good next states. Way too much branching.
I tried to use A-star to solve the sub-problem of finding a way to move the actual magic data. Way too much branching as well.
Then I started fucking up the A-star visited state data. Rather than location + path or location + map data, I trimmed to just location. I'm sure there are some inputs this won't work for. Basically, the first time we move the magic data to some location, we assume that is good regardless of what madness we might have done to the rest of the nodes. If there is some solution that involves leaving some intermediate node alone to use it later, my solution would probably clobber that and be wrong.
Maybe. Whatever, gold star, good enough.