Challenge
Given two binary vectors (containing two consistent values of your choice) of length \$n\$ and \$m\$, output a corresponding ascii-art hitomezashi stitching pattern.
You are to fill the following pattern, where \$n\$ is the number of A
-columns and \$m\$ is the number of B
-rows:
A A A A A
B+B+B+B+B+B
A A A A A
B+B+B+B+B+B
A A A A A
Here A
can be one of |
and
(space), and B
can be one of -
and
(space). The rows and columns alternate between these two values. The binary vectors indicate, whether to start in the "on" (|
/-
) or "off" (
) position for each row or column.
You may be interested in a recent Numberphile video on that topic.
Rules
- \$n,m \geqslant 1\$
- There are \$ n \times m \$
+
s. - You may take input in any consistent order (rows first or columns first) and following any direction (right-to-left and top-to-bottom or reversed or mixed).
- Output in any reasonable format, including one of: single string with newlines, list of lines, matrix of characters. Output as char codes is allowed only if your language doesn't support strings natively.
- Trailing whitespace is optional.
Test cases
Input: 0 1 0 1
, 0 1 1
Working out:
0 1 0 1
0+?+?+?+?
? ? ? ?
1+?+?+?+?
? ? ? ?
1+?+?+?+?
? ? ? ?
Output:
| |
+-+ +-+
| |
-+ +-+ +-
| |
-+ +-+ +-
| |
Input: 0
, 0
Output:
+-
|
Input: 1
, 1
Output:
|
-+
Input: 1 0 1 0 1
, 1 0 1 0 1 0 1
Output:
| | |
-+ +-+ +-+
| |
+-+ +-+ +-
| | |
-+ +-+ +-+
| |
+-+ +-+ +-
| | |
-+ +-+ +-+
| |
+-+ +-+ +-
| | |
-+ +-+ +-+
| |
n
) indicates how don
columns start, the second - how dom
rows start. I provided a working out for the first test case - hope it clarifies a little. \$\endgroup\$