You are piloting a spaceship, outfitted with an engine that can accelerate you at 1km/s^2 in the direction the ship is facing (you have very good inertial dampers). You also have thrusters which can rotate you 180 degrees in 1s (rotating 45 degrees takes 0.25s, etc.).
You see on your scanner another ship, and decide to rendezvous with it. You'll need to plot a course which brings you within 1km of it while your speed is within 1km/s of its speed.
Write a function which takes the following pieces of data as inputs:
other_location - The location of the other ship in kms. You may assume that this is no more than 100 units away from the origin for optimization, but your entry should be able to handle larger distances (even if it takes a long time).
other_acceleration - The other ship is accelerating at a constant rate no more than 0.5km/s^2 (their inertial dampers aren't quite as good). You may take this in whatever form you wish - facing + acceleration, or separated into x and y components). The other ship starts at a speed of 0.
You always start at
[0,0], facing the positive direction on the x axis.
Your function's output is significantly more constrained. You must return a list of actions your ship will take. There are three possible actions.
Acceleration. You accelerate in the direction your ship is facing for an amount of time you specify.
Rotation. You rotate to face a direction you specify.
Drift. You do nothing for the amount of time you specify.
Your output must have the listed data, but it can be in any format you wish. Please make it human-readable; this isn't code golf.
At the end of the final action in your list, your ship must be within 1km of the other ship and its speed must be within 1km/s of the other ship's speed. Note that if you accelerate from a stop for 1s, you will have moved 0.5kms.
I will run each entry on my machine, a i7-9750H 2.6 GHz Windows 10 laptop. Ideally, there will be straightforward installation instructions for your language; please specify whatever build command I need to run it.
The score of an entry on a particular input will be the product of the time it takes to run and the time that it takes for your ship to intercept the other ship squared. Entries may be non-deterministic, but I will run any non-deterministic entry 10 times on each input and take the worst score.
The winner will be the entry that has the lowest total score across the inputs.
Here are a bunch of sample inputs (that I'll use as the test set, though I might add some more if some programs are very quick). Feel free to post preliminary outputs/scores for each of these (run on your machine), but note that it's a standard loophole to tailor your program to these inputs.
other_location (x, y), other_acceleration (x, y) [10,0], [0,0] [6,-3], [0,0.5] [-2,8], [0.1,-0.2] [5,5], [0.3,0.3] [15,18], [0.1, 0.3] [20,5], [0.2,-0.2]
For the first example input (
[10,0], [0,0]), these are all valid outputs:
[Accelerate, 1], [Drift, 8.5] [Accelerate, 2.7], [Rotate, 180], [Accelerate, 2.7] [Accelerate, 2], [Rotate, [-1,0]], [Drift, 2], [Accelerate, 2]
For the second example input (
[6,-3], [0,0.5]), this is a valid output:
[Accelerate, 2.23], [Rotate, 180], [Accelerate, 2.23], [Rotate, -90], [Accelerate, 11.5], [Drift, 5.5] // The first 3 actions put me directly behind the moving ship (actually // at [5.9729, 0]) in 5.96s (the other ship is now at [6,5.8804] and // moving [0, 2.98]), the remainder catch up to it. // Total time for this route: 22.96s