19
2
For the purpose of this question a meandering curve is one that follows the general direction from left to right, but makes repeatedly n+1 turns at 90 degrees to the left and then n+1 turns to the right (for n>0).
In fact the meander itself will have n
segments.
The turns are denoted with +
.
The width of the meanders (the distance between two +
) is 3 at the horizon (---
) and 1 at the vertical (|
)
Here are the single segments a meandering curve with sizes n from 1 to 5:
+-------------------+
| |
+---------------+ | +-----------+ |
| | | | | |
+-----------+ | +-------+ | | | +---+ | |
| | | | | | | | | | | |
+-------+ | +---+ | | +---+ | | | +---+ | | |
| | | | | | | | | | | | | |
+---+ +---+ | +---+ | | +-------+ | | +-----------+ | |
| | 1 | | 2 | | 3 | | 4 | | 5
---+ +-------+ +-----------+ +---------------+ +-------------------+ +
Challenge:
Given two positive numbers n
and m
, draw m
segments of a meandering curve with size n
.
You can write a full program or a function.
Input:
n
> 0 The size of the curve
m
> 0 Number of segments to draw
Output:
An ASCII representation of the meandering curve.
Examples:
n = 3
m = 2
+-----------+ +-----------+
| | | |
| +---+ | | +---+ |
| | | | | | | |
+---+ | | +---+ | |
| | | |
-----------+ +-----------+ +
n = 2
m = 5
+-------+ +-------+ +-------+ +-------+ +-------+
| | | | | | | | | |
+---+ | +---+ | +---+ | +---+ | +---+ |
| | | | | | | | | |
-------+ +-------+ +-------+ +-------+ +-------+ +
n = 4
m = 4
+---------------+ +---------------+ +---------------+ +---------------+
| | | | | | | |
| +-------+ | | +-------+ | | +-------+ | | +-------+ |
| | | | | | | | | | | | | | | |
| +---+ | | | +---+ | | | +---+ | | | +---+ | |
| | | | | | | | | | | | | | | |
+-------+ | | +-------+ | | +-------+ | | +-------+ | |
| | | | | | | |
---------------+ +---------------+ +---------------+ +---------------+ +
Winning criteria:
This is code-golf, so the shortest code in bytes in each language wins. Please explain your code, if you have time to do it.
1Suggestion for future challenge: plot the first figure (the one with increasing meanders), allowing graphical output – Luis Mendo – 2018-06-27T14:13:45.057
3Isn't it
n
left turns? – LiefdeWen – 2018-06-27T14:35:52.9701@LuisMendo Yes, when I composed the 1-5 image, I realised that there is a good challenge within it - given a list L of positive integers, compose a meandering curve with segments of size L(i) – Galen Ivanov – 2018-06-27T19:45:31.267
@LiefdeWen It depends on where you start counting. I think it's
n+1
when looking at the examples, especially between the single segments.. – Galen Ivanov – 2018-06-27T19:54:46.307