Not who you asked but: I save coordinates and direction into a vector each time the guard faces a #. Also every time the guard faces a #, I check if the position exists in the vector, if true, it’s an infinite loop. 78ms rust aolution.
Not who you asked but: I save coordinates and direction into a vector each time the guard faces a #. Also every time the guard faces a #, I check if the position exists in the vector, if true, it’s an infinite loop. 78ms rust aolution.
Rust
This one was the first real think for this year, but I ended up brute forcing it, placing a ‘#’ in every position and checking. part 2 runs in about 380ms 78ms (after reducing the amount ‘#’-placements to only where the guard walks) on my 2011 core i-7, so I’m happy, even though it feels like I could have been smarter.
Still in rust, and still inexperienced.
Forgot to make a separate solve for part two, for part one, imagine this without the make_valid function and some slightly different structure changes around the accumulator in babbage().
Used a hash map to track what should be in order, and a few indexed loops to keep track of where I’m at and where to look forward.
This looks so alien! Does it work with the full set? The comment says 5, choose 4, but I guess it’s written as n, choose n-1?
This is my very naive rust solution, part 2 is mostly just an extra function, so they’re bother covered in this one.
I’d like to see your solution in total. I’m not too familiar with the nuts and bolts, but hash set is quite a bit more expensive than a simple vector, there’s a bunch of overhead incurred when executing the hashing and placing of the data, and when repeating a few thousand times it sure adds up. My part one hovers around 600 microseconds.