Background
A few months ago, the adventure of your life was just about to start. Now, in this precise moment (yeah, now), after months of suffering and hard work, you and a group of friends are standing on the top of the world. Yes, you are right, you are on the summit of Sagarmāthā.
However, things aren't going as well as you would like to. A dense fog has surrounded you and an incredibly bad-looking storm is coming as fast as it can. You didn't fix any rope on the way up, and your footprints have been covered in snow. If you want to survive (at least for today), you need to get out of there as fast as you can, but you MUST first find a way to know which face of the mountain is the one you should descend.
Luckily, you brought with you your sat phone which you modified before the trip so you are able to program and execute programs in it.
Challenge
You have been able to download to your phone the map of the mountain in an ASCII-old-fashioned-unreadable-on-the-top-of-the-world way. Your task is to decide which face of the mountain presents the easiest descent so you can increase your chances of surviving. In order to do so, you have the brilliant idea to code a program on your phone that will tell which is the easiest way down. (Disclaimer: These activities have been done by professionals. No programmer was hurt during this narration. Please, do not try this at home.)
Maps are only made of the characters /
and \
(plus spaces and newlines).
In any map, the summit of the mountain is always represented by
/\
\/
and from each of the sides (1,2,3
or 4
) of the summit you will always find a "possible" way down the mountain.
1 /\ 2
3 \/ 4
The routes are always presented in the next way:
\
Steep-> / /
/ / <-Flat
/ \
Flat-> \ \
/ \ <-Steep
/\
\/
where each new character is either one place to the left/right of its predecessor. The meaning of each character is:
- If the slash/backlash is parallel to its summit side -> counts as a 'steep' part.
- If the slash/backslash is perpendicular to its summit side -> counts as a 'flat' part.
*For further reference see graphic above.
Note: The sides can have different lengths and the characters which constitute the summit also count as part of their side. In case of a draw, you can choose any of them.
Standard loopholes are disallowed.
Input
A string representing the map of the mountain or a plain text file containing the same info.
Either
C:\....\file.txt
or
\
/ /
/ /
/ \
\ \
/ \
/\
\/
\ /
\ \
\ \
\ \
/ /
as a string are valid inputs.
Output
As output, you should produce either a file in plain text or by stdout an ASCII profile representation of the side with the smallest average steepness using _
for flat parts and /
for steep parts along with the average steepness of the side (number of "/")/(total chars)
.
Output example for map above:
/
___/
/
AS:0.5
The format is not important as long as you have the profile and average steepness.
Scoring
What? Do you want a better reward than saving your and your friend's lives and being the first programmer who has ever programmed on the top of the world? Okay... this is code golf, so shortest program in bytes wins.
Test cases
Input:
\
/ /
/ /
/ \
\ \
/ \
/\
\/
\ /
\ \
\ \
\ \
/ /
Output:
/
___/
/
AS=0.5
Input:
/
\ /
/ /
\ /
\ /
/ /
/\
\/
\ /
\ \
\ \
\ \
/ /
/
/
Output:
______/
AS=0.143 (1/7)
Input:
/ \
\ \
/ /
/ \
/\
\/
\ /
\ /
\ /
/ \
Output:
/
/
/
_/
AS=0.8