13
0
Your job is to write a program that finds the optimal number of moves it takes to get from the lower-left corner of a rectangle to the upper-right corner directly opposite.
Your program will accept input as an ordered pair (width, height)
. These will be the dimensions of the rectangle you will work with. Your program will create an ASCII-art of the solution (use .
for empty square and #
for part of the solution, X
for starting square) and count the number of moves it takes to reach the endpoint. Diagonal moves are not allowed. If there are multiple solutions, choose one to output.
The shortest program in bytes wins.
Example
Input: (4, 5)
Output:
..##
..#.
.##.
.#..
X#..
Move count: 7
So should the output contain the number of
#
in "the optimal solution" (which is any solution that never moves left or down) as well? – Martin Ender – 2016-04-02T16:32:39.98712
Re "Sorry, this is my first code-golf question so I'm not very good at making these." Let me recommend the sandbox where you can post challenge ideas and receive feedback before posting them on main. And welcome to PPCG! :)
– Martin Ender – 2016-04-02T16:33:44.430@MartinBüttner Yes, the move count is essentially the number of
#
because it's illogical to go left or down. – ericw31415 – 2016-04-02T16:35:49.220Is it ok to separate each char with spaces? – Blue – 2016-04-02T17:28:41.687
1Do we have to output the move count AND the ascii art? How exactly should the output look like? – James – 2016-04-02T19:29:51.107
Nice easy question to practice
string repetition
ornested for loop
:) – Leaky Nun – 2016-04-03T02:08:22.263