You know those wooden toys with little ball bearings where the object is to move around the maze? This is kinda like that. Given a maze and a series of moves, determine where the ball ends up.
The board is held vertically, and the ball moves only by gravity when the board is rotated. Each "move" is a rotation (in radians).
The maze is simply concentric circular walls, with each wall having exactly one opening into the outer corridor, similar to this (assume those walls are circles and not pointed):
As you can see, the ball starts in the middle and is trying to get out. The ball will instantly fall through as soon as the correct orientation is achieved, even if it's midway through a rotation. A single rotation may cause the ball to fall through multiple openings. For instance, a rotation
>= n * 2 * pi is enough to escape any maze.
For the purposes of the game, a ball located within
0.001 radians of the opening is considered a "fit", and will drop through to the next corridor.
Input is in two parts:
The maze is given by an integer
nrepresenting how many walls/openings are in the maze. This is followed by
nlines, with one number on each, representing where the passage to the next corridor is.
The moves are given as an integer
mrepresenting how many moves were taken, followed (again on separate lines) by
mclockwise rotations of the board in radians (negative is anticlockwise).
All passage positions are given as
0 rad = up, with positive radians going clockwise.
For the sample image above, the input may look like this:
7 // 7 openings 0 0.785398163 3.14159265 1.74532925 4.71238898 4.01425728 0 3 // 3 moves -3.92699082 3.14159265 0.81245687
Output the corridor number that the ball ends in. Corridors are zero-indexed, starting from the center, so you start in
0. If you pass through one opening, you're in corridor
1. If you escape the entire maze, output any integer
For the sample input, there are three moves. The first will cause the ball to fall through two openings. The second doesn't find an opening, and the third finds one. The ball is now in corridor
3, so expected output is:
Behavior is undefined for invalid input. Valid input is well-formed, with
n >= 1 and
m >= 0.
Scoring is standard code golf, lowest number of bytes wins. Standard loopholes are forbidden. Input must not be hard-coded, but can be taken from standard input, arguments, console, etc. Output can be to console, file, whatever, just make it output somewhere visible.