50
12
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!
1If your language has good array built-ins, then you can turn the input into a stream of operations (
\_/
) with the following steps: split into array of lines, rotate, flatten, strip spaces. – Cyoce – 2016-01-20T00:09:24.3271This is really more of a fixed-track mechanism than a golf course :P – Zach Gates – 2016-01-20T01:27:19.240
24I like that
\/\/\/\/\/
is a more efficient course than__________
. – ezrast – 2016-01-21T00:53:31.5032That's what I was thinking, 4 down, 5 up, then .5 must be average. Oh, flat is 1? – Leif Willerts – 2016-01-21T13:21:29.647
Will each line in a course always be the same length (with trailing spaces filling in the end of shorter lines)? – SnoringFrog – 2016-01-25T17:02:18.083
@SnoringFrog If you want it to. That's what it means by "Courses can optionally be padded with spaces". – user81655 – 2016-01-25T21:31:11.210
Cool. Wasn't sure if that meant "you can if you want" or "they may or may not come like that so code for both" – SnoringFrog – 2016-01-25T21:35:23.553