This is a mini golf hole:
The outer boundary is a circle with radius 10 and center (0,0). The inner boundary is a circle with radius 3 and center (0,5). The tee is at (0,-8). Assume the ball is just a point with radius 0.
The dynamics of the ball are governed by the following rules:
The ball is initially hit with energy 50, and with a given angle.
- The angle is in degress in the Cartesian coordinate system, so 0° means directly to the right, 90° is directly up, and so on.
When the ball hits the edge of the inner or outer circle, it bounces off the circle using the law of reflection.
The ball loses energy as it moves.
For every unit of ground it covers, it loses 1 unit of energy.
Every time it bounces off a wall it loses 5 units of energy.
The ball stops either when it runs out of energy or when it falls into the hole.
If the ball hits a wall with <= 5 units of energy, it stops.
It falls into the hole if it has energy < 10 when it is within distance 1 of the hole, otherwise it keeps moving.
Challenge
Given the x-y coordinates of a hole, return an angle at which that you can hit the ball in order for the ball to fall into the hole (if such an angle exists).
Input
Take as input the x- and y-coordinates of the center of the hole in any convenient form. Input may be taken from STDIN (or closest alternative), command line parameters, or function arguments.
Output
Print or return an angle in degrees at which the ball can be hit from the tee such that the ball will fall into the hole. If such an angle exists, the output should be in the range [0, 360), otherwise the output should be -1.