Introduction
Sisyphus was having some troubles at work lately. It seems he just never gets anything done, and he would love to find a solution to this problem.
His current employment requires rolling a rock up a hill. He usually does his job well, but every time he is near the top of the hill it rolls down again.
He is getting really frustrated with his job and wants to solve the problem scientifically by having a computer simulate the rock rolling down the hill.
It so happens that Sisyphus isn't particularly good at programming, so maybe you can help him out?
The Challenge
After this silly introduction, let's come to business. Your program will receive an illustration of the hill and the rock which looks similar to this:
#o
##
###
######
########
Where #
represents a part of the hill and o
represents the rock.
You now have to implement a program which moves the rock 1 layer down. For example, the output of the above should be:
#
##o
###
######
########
If there is a horizontally even area, the hill just rolls horizontally, so...
o
########
...this would just make the stone roll sideways.
o
########
If there is a vertical area, the rock falls down one step, so...
#o
#
#
#####
...would yield...
#
#o
#
#####
You will also receive the width and height of the image respectively in one line above the image. So, in complete, our sample input would look like this:
10 5
#o
##
###
######
#########
(Note that the whitespace here are spaces. Select the text and see what I mean.)
Some details
When the rock is already in the last line when running the program, you can choose to either terminate the program or output the unchanged input
The hill only ever goes downwards
Your program should format the output exactly the same as the input (including the dimensions), so if you pipe the output of the program to itself, it calculates the next step.
You can assume there is always a way to the bottom, so input where the path is "blocked" may cause undefined behaviour
You can assume there is always a space in the last line. The rock should "rest" there, so after calling the program a few times, always piping it's output into itself, you should end up with the rock in the last line, laying where the space previously was.
You may accept input in any form you like (stdin, file,...). You have to post the WHOLE program (so all pre-initialized variables count as code).
The lines are terminated with
\n
.You can get some example inputs here (make sure you copy the spaces correctly!)
This is code-golf, so the working submission with the least bytes wins.
The winner will be chosen on July 26th, 2014. You can post solutions after that, but you can't win
If you have any questions, let me know in the comments.
Happy golfing!
#
s, so there is one space at the end because the width is 10. In this case (after a few iterations) the rock would lay where the whitespace is (so at the bottom-right corner). \$\endgroup\$