I feel that for a site named code-golf we have a shockingly little amount of golf being played. Let's fix that.
Determine whether the hole of a minigolf course can be reached after exactly a certain number of movements and whether it can be reached at all.
How to play
Inputs are an integer "power level" and an ASCII art minigolf course. The ball starts on the
X (capital) and the hole is an
O (capital). The walls of the course are made of the characters
/. The characters
- rotate the direction of the ball 180 degrees and the characters
/ rotate the direction 90 degrees as you would expect. When a ball hits the wall it enters the wall for that turn and then leaves the next turn.
Launch the ball in each of the four cardinal directions from the starting
- If the ball enters the hole after exactly the power level moves, then output
- If the ball could make it to the hole given a different power level, then output
- If the ball cannot enter the hole regardless of the power level, output
- This is code-golf so shortest answer in bytes wins.
- Assume only valid input will be given.
- All input strings will be rectangular. (All rows will be the same length)
- Assume that there is no way to escape the course and leave the edge of the string.
- No solution will require the ball to be in the same place facing the same direction twice.
- Standard loopholes disallowed.
- Only a string or a list of strings is acceptable for the course input.
- Output can be any three distinct values.
- The ball will never hit the characters
11 -----+ / X | | +----+ | | |O| +-+
This is true. If the ball starts heading east it will be on the wall after two movements.
-----+ / X o<- ball right here. movements:2 | +----+ | | |O| +-+
It will then change directions until it hits the corner
-----+ o X | movements:8 | +----+ | | |O| +-+
Now it is heading south and will end in the hole after 11 moves. Note that 13 would also be true as the ball could bounce off of the bottom wall and into the hole. Other valid power levels for this course are 7 and 9.
All answers validated using this java code: https://github.com/Dragon-Hatcher/CodeGolfMiniGolf/tree/master/MinigolfCodeGolf/src
power course output 11 -----+ / X | | +----+ | | |O| +-+ truthy 10 +---+ | X | +---+ +-+ |O| +-+ falsy 25 --------- / X \ +++-------+ | | | | | |O| | | | \-------/ | \ / --------- truthy 2 +-+ |X| | | | | |O| +-+ mediumy 34 +------+ |/ \| | +--+ | |X| | | +---+ +--+ | | O /| +---+ +----+ +-+ true