Given a side-view of a mini-golf course and the power of the swing, determine if the ball will make it into the hole.
A course will be in this format:
____ ____ _
__/ \ / U \
__/ \ / \_
\_/
The ball starts directly before the first piece of ground on the left and follows the contour of the course until it reaches the hole (an upper-case U
below the current level of the ground). If it reaches the hole, output a truthy value. The power of the swing will be the initial speed of the ball. The ball moves to the next character on the right at each iteration, then the speed is altered depending on the character it is now on. If the speed reaches 0
or less before the hole, output a falsey value.
_
decreases the speed by1
/
decreases the speed by5
\
increases the speed by4
Courses can optionally be padded with spaces. The power of the swing will always be a positive integer.
You do not need to worry about the ball going too fast to enter the hole, rolling backwards or jumping/bouncing off hills.
Test Cases
Input: 27
____ ____ _
__/ \ / U \
__/ \ / \_
\_/
Output: true
----------
Input: 26
____ ____ _
__/ \ / U \
__/ \ / \_
\_/
Output: false
----------
Input: 1
U
Output: true
----------
Input: 1
_
U
Output: false
----------
Input: 22
/U
/
/
/
\/
Output: true
----------
Input: 999
_ _
\ /
\ /
\ /
U
Output: true
----------
Input: 5
/
/U
Output: false
----------
Input: 9
/\/\/\/\/U
Output: false
----------
Input: 16
_/\ _
\ __ /\/\/\ /
\ / \ / \ /
\__/ \ / \____________ _/
\_/ U
Output: true
This is code mini-golf, shortest answer in bytes wins!
\_/
) with the following steps: split into array of lines, rotate, flatten, strip spaces. \$\endgroup\$\/\/\/\/\/
is a more efficient course than__________
. \$\endgroup\$