Inspired by this lumosity mini game, Pinball Recall
We start with a rectangular grid (viewed from above) with several bumpers as follows. Entrances/exits are numbered counter-clockwise starting from the leftmost of the bottom of the grid, as number 0.
24 23 22 21 20 19 18 17 16 15
25 . . . . . / . . . . 14
26 . . . . . . . . . . 13
27 . / \ . . \ . . \ . 12
28 . . . . . . . . . . 11
29 . . . . . . / . . . 10
0 1 2 3 4 5 6 7 8 9
Pinballs can be fired from each entrance into the grid at a direction perpendicular to the grid wall, e.g. in the above example:
- 0 to 9: fired upwards
- 10 to 14: fired to the left
- 15 to 24: fired downwards
- 24 to 29: fired to the right
The pinballs will move in a straight line until they reach an exit, or a bumper, in which case the ball will bounce off the bumper and change direction. So in above diagram,
- from 0, ball goes straight to 24
- from 1, ball goes up to / and bounces off to reach \, then bounces off again and ends up at 2
- from 10, ball goes left to / and bounces off to 6
Inputs
Program shall receive the grid width and height. Then program receives the bumper orientation (represented as / or \) followed by coordinates, which also start from 0 from bottom left, e.g.
4 . . . . . . . . . .
3 . . . . . . . . . .
2 . . . . . . . . . .
1 . . . . . . . . . .
0 . . . . . . . . . .
0 1 2 3 4 5 6 7 8 9
"done" keyword used to indicate end of input
edit: as suggested by ngn, program may receive list of bumper coordinates instead so the "done" keyword is not needed
Output
Program should print out the exit locations of a pinball if they are fired from 0 to the last entrance of grid, in above case, 0 to 29
Sample input and output
Input
10 5
/ 1 2 / 5 4 / 6 0 \ 2 2 \ 5 2 \ 8 2
done
Output
24 2 1 21 20 22 10 17 14 15 6 28 16 26 8 9 12 7 29 25 4 3 5 27 0 19 13 23 11 18
Leaderboard (as of 20Oct2019)
- Neil, Charcoal, 133 bytes
- Arnauld, JavaScript (ES6), 212 bytes
- Embodiment of Ignorance, C# (Visual C# Interactive Compiler), 277 bytes
- Chas Brown, Python 2, 290 bytes
edit: FryAmTheEggman points out a similar question to try
[["/",x0,y0],["\\",x1,y1],...]
instead of input terminated withdone
? \$\endgroup\$