This challenge is pretty simple: Your task is to draw a schematic of a (simplified) memory array. You will be given two (positive) integers n,m
and the task is to draw the n:2^n
decoder connected to the memory array with d
data lines.
The addressing will be in the order of gray codes, to check if the sequence is correct, see A014550. For simplicity there are no input ports, write ports etc. On the top of the decoder you need to specify its type (e.g. 2:4
) and you will label the data lines with d:[d-1],...,d:1,d:0
. If the cray code wouldn't fit the decoder width, you'll need to expand the width, see the last two examples.
Rules
- Leading whitespaces are not allowed
- Trailing whitespaces are allowed
- At the end of the output there may be one or several newlines
- You can assume the following constraints on the input
0 < n
and0 < d <= 1e4
- The output is either printed to the console or you write a function that returns a newline-separated string
- For invalid input the behaviour of your program/function is left undefined
Test cases
n = 1, d = 1
.-----.
| 1:2 |
| |
| 0|---+
| | |
| | .+.
| | | +-+
| | `-' |
| 1|---+ |
| | | |
| | .+. |
| | | +-+
| | `-' |
`-----' |
d:0
n = 1, d = 10
.-----.
| 1:2 |
| |
| 0|---+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| | | | | | | | | | | |
| | .+. .+. .+. .+. .+. .+. .+. .+. .+. .+.
| | | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' |
| 1|---+--(--+--(--+--(--+--(--+--(--+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' |
`-----' | | | | | | | | | |
d:9 d:8 d:7 d:6 d:5 d:4 d:3 d:2 d:1 d:0
n = 2, d = 3
.-----.
| 2:4 |
| |
| 00|---+-----+-----+
| | | | |
| | .+. .+. .+.
| | | +-+ | +-+ | +-+
| | `-' | `-' | `-' |
| 01|---+--(--+--(--+ |
| | | | | | | |
| | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+
| | `-' | `-' | `-' |
| 11|---+--(--+--(--+ |
| | | | | | | |
| | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+
| | `-' | `-' | `-' |
| 10|---+--(--+--(--+ |
| | | | | | | |
| | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+
| | `-' | `-' | `-' |
`-----' | | |
d:2 d:1 d:0
n = 4, d = 5
.------.
| 4:16 |
| |
| 0000|---+-----+-----+-----+-----+
| | | | | | |
| | .+. .+. .+. .+. .+.
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0001|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0011|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0010|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0110|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0111|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0101|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 0100|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1100|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1101|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1111|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1110|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1010|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1011|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1001|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
| 1000|---+--(--+--(--+--(--+--(--+ |
| | | | | | | | | | | |
| | .+. | .+. | .+. | .+. | .+. |
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
`------' | | | | |
d:4 d:3 d:2 d:1 d:0
n = 1, d = 1024 (output truncated!)
.-----.
| 1:2 |
| |
| 1|---+-----+----...
| | | | ...
| | .+. .+. ...
| | | +-+ | +-+ ...
| | `-' | `-' | ...
| 0|---+--(--+--(-...
| | | | | | ...
| | .+. | .+. | ...
| | | +-+ | +-+ ...
| | `-' | `-' | ...
`-----' | | ...
d:1023d:1022d:1021...
n = 10, d = 1 (output truncated!)
.-----------.
| 10:1024 |
| |
| 0000000000|---+
| | |
| | .+.
| | | +-+
| | `-' |
... ... ...
n = 12, d = 5 (output truncated!)
.-------------.
| 12:4096 |
| |
| 000000000000|---+-----+-----+-----+-----+
| | | | | | |
| | .+. .+. .+. .+. .+.
| | | +-+ | +-+ | +-+ | +-+ | +-+
| | `-' | `-' | `-' | `-' | `-' |
... ... ... ... ... ... ...
n:2^n
+ 2, but do we need to extend it when the gray node representation wouldn't fit in it (e.g. n=10, len(10:1024
)+2 = 9, gray node repr length = 10) \$\endgroup\$max(len(n:2^n)+4,len(graycode)+3)
. The decoder name is always separated with one space from the left and the codes are right aligned without spaces. \$\endgroup\$