16
2
Inspired by Fibonacci domino tiling, this problem is about generating ASCII art representing another famous combinatorial sequence.
A n-step mountain diagram is a drawing of a mountain range, using exactly n '/' and n '\' characters, such that characters sketch a continuous curve which never dips below its initial "altitude". For example,
/\/\
/\/ \
and
/\
/\/ \/\
are both 4-step mountain diagrams, but
/\ /\/\
\/
is not.
Input
The program should accept an integer n from stdin or as the parameter to a function.
Output
Print all n-step mountain diagrams to stdout. The diagrams can be in any order, but should be separated by some sort of whitespace. You can decide if different diagrams will be output horizontally, vertically, etc.
As in the domino tiling problem, you can use whatever whitespace you want. This includes extra newlines before or after the printed output.
Example
Some sample valid outputs for n=3:
Valid output A:
/\
/\ /\ / \ /\/\
/\/\/\ / \/\ /\/ \ / \ / \
Valid output B:
/\
/\/ \
/\/\
/ \
/\/\/\
/\
/ \
/ \
/\
/ \/\
Valid output C:
/\
/ \ /\
/ \ /\/ \
/\/\
/\ / \
/ \/\ /\/\/\
This is code golf; shortest program (in bytes) wins.
When you say "You can decide if different diagrams will be output horizontally, vertically, etc.", can the mountain ranges themselves be sideways? – xnor – 2014-09-18T03:05:23.007
The mountain ranges themselves shouldn't be sideways. The empty skies between peaks add to the challenge, I think. – Matt Noonan – 2014-09-18T03:12:51.687
Can some ranges appear more than once? – proud haskeller – 2014-09-18T18:37:22.187
@MattNoonan You're right, printing the mountain ranges horizontally was definitely tricky. – xnor – 2014-09-18T19:48:18.137
@proud-haskeller It should be once each. – Matt Noonan – 2014-09-18T22:33:28.053