Every day I think, surely today's problem can't be solved in BQN, every day I am proven wrong
5 күн бұрын
It's turing complete.
@kevinmarques93345 күн бұрын
I didn't quite understand your counter approach to check if the guard's path is in a loop... I figured that the obstacle only makes any difference if it's placed in the guard's path, so for each position in the guard's path I put a obstacle and recalculate the new route. My solution to check if an array of positions is in a loop I separated the last two positions and compared if it appeared in the tail of the list. It was a nightmare in JavaScript, but after some tries (3-5 min each) I managed to solve it
@relacibo5 күн бұрын
I think, because a loop will run infinitly, the counter will be greater then the array size eventually. It's just very inefficient. I suspect the bqn solution, as elegant as it might be, will not run in any reasonable amount of time with the "real" problem input. Also because of the missed optimization opportunity, that you mentioned. Even in rust it took ~20-30 seconds for me.
@batlin4 күн бұрын
I stored each new (x,y,dir) triple in a set so a loop is discovered when the next state is already in the set. Together with the other optimisation you mentioned, only placing obstacles along the path generated in part 1, made it faster but still a bit slow in Picat (maybe 30s).
@aly-bocarcisse6134 күн бұрын
@@batlinyou just replied to my question on direction, thanks
@bzboii3 күн бұрын
1:45 actually -90 deg turn
@aly-bocarcisse6134 күн бұрын
Can someone explain the delta trick to compute the new direction ? I did not get it.😊
@code_report4 күн бұрын
You always make a right turn. So dx is a list of 4 x y deltas of the offsets to move your position either up, right, ,down or left (in that order). Dir (direction) is used to index into that, and whenever you need to make a turn you just +1 to dir (and also mod 4 to reset to 0).