27
1
Gravity Guy is a game where the only user input is a single key that flips the direction of gravity. Given an ASCII art level, determine if it is possible for Gravity Guy to reach the end.
Rules
- The initial direction of gravity is down.
- The first column of the input will always contain only one
#
, which Gravity Guy starts on top of. - Each iteration, he moves to the character directly on his right.
- If his path is blocked and he moves into a
#
, the player loses. - After moving, the player can optionally switch gravity from down to up, or up to down.
- Gravity Guy then falls on to the next
#
(in the current direction of gravity). - If there is no
#
to fall on to and he falls off the grid, the player loses. - If Gravity Guy moves off the right side of the input grid, the player wins.
Example
If this was the input grid:
###
# # #
###
Gravity Guy would start at the x
and the be at these positions after each iteration. ^
= switch gravity to up and v
= switch gravity to down.
v ^ v
-------------------------------------------------------------
### | ### | ### | ### | ### | ###
x | | x | x | x |
# # | #x # | # # | # # | # # | # # x
### # | ### # | ### # | ### # | ### # | ### #
As you can see, by switching gravity at these times Gravity Guy reaches the end, so this input would return a truthy value.
Specifications
- Input grid can be in any appropriate "grid" format (multiline string padded with spaces, array of line strings, array of array of characters, etc).
- If it is possible for the player to win the level, output a
truthy
value. If not, output afalsey
value. - The width and height of the grid will be
50
characters at most. - This is code-golf, may the shortest code in bytes win!
Test Cases
(each case separated by ----------
, any blank lines should also be padded with spaces)
True
######### ######## ###### ######
# # # # # # #
### # # # # # # # # #
# ## # # ## # # # # # ##
# # # # # # # # # #######
# # # # # ### # #
# ## # ## # # # #
# # # # # #
# #################################### #
# #
#############################################
----------
###
----------
#####
####
----------
#####
# # #
# # #
#####
----------
############
###### ######
############
----------
### ###
# #
#### # ####
# #
# #
#
----------
######
#
##
#######
### #
# #
#####
----------
#####
# #
## #
#######
###
#
######
----------
###
# # #
###
----------
### ###
### ##
# #
#####
----------
#
# #
#
# # #
#
#
#
#
----------
##### ####
# # #
# # # ## #
# #
##### #### #
#
#########
----------
###########################
# # # # # # #
# # # # # # # # # #
# # # ######### ###########
# # # # # # # #
# # # ## ##### ### #
## # # # ## ###
# ##### #### ########### #
# # # # # ## #
# # ##### ### # # # # # #
# # # # ##
###########################
False
###
#
####
----------
### ###
----------
#
### ###
#### ###
#
----------
### ###
# # #
#### # # ####
# #
# #
# #
#
----------
#######
# #
## #####
### ######
# #
#######
----------
###########################
# # # # # # # #
# # # # # # # # # #
# # # ######### ###########
# # # # # # # #
# # # ## ##### ### #
## # # # ## ###
# ##### #### ########### #
# # # # # ## #
# # ##### ### # # # # # #
# # # # ##
###########################
Are we allowed the grid in columnar format? – Neil – 2016-04-22T12:15:28.837
@Neil You mean a transposed/rotated array? I'm going to say no, since it's altering the input. But if your language has a special
column
type, that would be OK to use I guess. – user81655 – 2016-04-22T12:27:54.987Is it possible for the
#
in the first column to be in the first row? – feersum – 2016-04-22T12:53:22.247@feersum No, you can assume the grid will include space for the Gravity Guy to "stand" in. – user81655 – 2016-04-22T12:57:55.523
Shame; the transposition increases my byte count by 20%. – Neil – 2016-04-22T19:45:36.010