Premise
So recently I was about half an hour early to an appointment, and decided to wait outside. I also determined that it would look strange if I just stood motionlessly in front of the house. Therefore, I decided to go on a quick walk, within a limited area. I also concluded that if I started walking in circles that would make it obvious that I was loitering. So I was inspired to create my first Code Golf challenge.
Specification
You will be given a list, a map of the area, which will contain either " "
or "#"
, which represent free spaces and obstacles of some sort. Free spaces can only be crossed once, and it takes 1 minute to cross it. Your initial position will be signified with a "@"
per roguelike tradition, and the target will be represented with a "$"
because that's what you're going to lose there. You will also be given an integer which will represent how many minutes you have to waste before not seeming as if you were intruding. When you land on the "$"
, it will have to have been the exact amount minutes (so if you were counting down, it will have to be 1 on an adjacent tile, and be 0 on the tile). It will always be possible to reach the destination. Your program or function will have to return a list showing the shortest path with <, >, ^, and v to represent the four possible directions.
Examples
Input:
[[" ", " ", " ", " "],
["@", " ", " ", "$"],
[" ", " ", " ", " "],
[" ", " ", " ", " "]]
and
5
Ouput:
[[">", ">", ">", "v"],
["^", " ", " ", "$"],
[" ", " ", " ", " "],
[" ", " ", " ", " "]]
Input:
[[" ", "#", " ", " ", " "],
[" ", "#", " ", " ", " "],
["@", "#", " ", "$", " "],
[" ", " ", " ", " ", " "],
[" ", "#", " ", " ", " "],
[" ", "#", " ", " ", " "]]
and
7
Output:
[[" ", "#", " ", " ", " "],
[" ", "#", ">", "v", " "],
["v", "#", "^", "$", " "],
[">", ">", "^", " ", " "],
[" ", "#", " ", " ", " "],
[" ", "#", " ", " ", " "]]
Input:
[[" ", "#", " ", " ", " "],
[" ", "#", " ", " ", " "],
["@", "#", " ", "$", " "],
[" ", " ", " ", " ", " "],
[" ", "#", " ", " ", " "],
[" ", "#", " ", " ", " "]]
and
17
Output:
[[" ", "#", " ", "v", "<"],
[" ", "#", " ", "v", "^"],
["v", "#", " ", "$", "^"],
[">", ">", "v", ">", "^"],
[" ", "#", "v", "^", "<"],
[" ", "#", ">", ">", "^"]]
Rules
- Standard loopholes apply
- Each tile must only be moved over once
- The exact amount of time must be spent on the board
- Only one path needs to be displayed in the case of multiple paths
- This is a code golfing question so shortest answer wins
- As per user202729's question in the comments, you may assume valid input.
Add a comment if any further clarification is required