Draw some ASCII-boxes
Python 2, 117 Bytes
def f(h,v):r="+"+"+".join("-"*i for i in h)+"+\n";print r+r.join(("|"+"|".join(" "*i for i in h)+"|\n")*i for i in v)+r
Try it on ideone.
Not expecting too much from this. Really simple, just uses python joins and string multiplication to pull everything together.
JavaScript (ES6), 83 bytes
(a,b,g=(a,[s,t])=>t+a.map(n=>s.repeat(n)+t).join``+`
`)=>g(b,[g(a,` |`),g(a,`-+`)])
Output includes two trailing newlines.
MATL, 25 22 21 bytes
'|-+ '2:"1tiYsQ(]E!+)
Uses inputs with 1
added (allowed by the challenge).
Try it online!
Explanation
The code initially builds an array containing 1
for the column indices of non-space characters in the final result, and 0
otherwise. So if the first input is [2 1 4 1 3 1]
(would be [1 0 3 0 2 0]
in the 0-based format) this array will be
1 0 1 1 0 0 0 1 1 0 0 1 1
Note how the length of runs of zeros is related to the input. Specifically, this array is built as follows:
- Initiallize the array to a single
1
. - Compute the cumulative sum of the input and add
1
. In the example this gives[3 4 8 9 12 13]
. - Extend the array from step 1 by assigning
1
to the entries with (1-based) indices given by step 2. Intermediate entries are automatically set to0
.
A similar array is built for the rows. Second input [3 2 1 1]
(or [2 1 0 0 ]
) gives
1 0 0 1 0 1 1 1
Now the second array is multiplied by 2
, transposed and added with broadcast to the first. This gives the 2D array
3 2 3 3 2 2 2 3 3 2 2 3 3
1 0 1 1 0 0 0 1 1 0 0 1 1
1 0 1 1 0 0 0 1 1 0 0 1 1
3 2 3 3 2 2 2 3 3 2 2 3 3
1 0 1 1 0 0 0 1 1 0 0 1 1
3 2 3 3 2 2 2 3 3 2 2 3 3
3 2 3 3 2 2 2 3 3 2 2 3 3
3 2 3 3 2 2 2 3 3 2 2 3 3
Indexing into the string '|-+ '
gives the final result as a 2D char array. Since indexing is modular and 1-based, index 0
corresponds to the last element (space).
'|-+ ' % Push this string
2:" ] % Do this twice
1 % Push 1 (initial array)
t % Push another 1 (contents to be filled in)
i % Take input
Ys % Cumulative sum
Q % Add 1
( % Fill 1 into those entries of the array
E % Multiply by 2
! % Transpose
+ % Add, with broadcast
) % Index (modular, 1-based) into the string