6 kyu

Simple Fun #398: Draw the Stereoscopic Graphics of Building Blocks

Description:

Task & Examples

In this kata, your task is to draw the stereoscopic graphics of building blocks.

We define a single block graph is:

..+---+
./   /|
+---+ |
|   | +
|   |/.
+---+..

As you can see, + represents the corners of block; | / and - represents the sides of block; . represents the background.

The input is a 2D array of positive integers. It's always a n x m matrix. That is, your output should draw blocks n rows and m columns.

The value of each element represents the height of block.

height=1    height=2    height=3
                        ..+---+   
                        ./   /|   
                        +---+ |   
            ..+---+     |   | +   
            ./   /|     |   |/|   
            +---+ |     +---+ |   
..+---+     |   | +     |   | +   
./   /|     |   |/|     |   |/|   
+---+ |     +---+ |     +---+ |   
|   | +     |   | +     |   | +   
|   |/.     |   |/.     |   |/.   
+---+..     +---+..     +---+..   

matrix=     matrix=     matrix=     
[[1]]        [[2]]       [[3]]       

If there are more elements in a row, the output should looks like:

matrix=
[[1]]  

..+---+
./   /|
+---+ |
|   | +
|   |/.
+---+..

matrix=
[[1,1]]   

..+---+---+
./   /   /|
+---+---+ |
|   |   | +
|   |   |/.
+---+---+..

matrix=
[[1,1,1]]  

..+---+---+---+
./   /   /   /|
+---+---+---+ |
|   |   |   | +
|   |   |   |/.
+---+---+---+..

Of course, your code should draw the graphics correctly when it has multi rows and multi columns.

Please see more examples in the sample tests.

Note

  • The output should be a string, each line is separated by "\n".

  • In theory, your code should be able to output infinite graphics, if you have an infinitely fast computer and an infinitely large screen. Someone said ;-) But in this kata, you only need to deal with the number of rows,columns greater than 0 and less than 50.

  • the height of each block(the element in matrix) is also greater than 0 and less than 50.

  • 8 fixed testcases

  • 100 random testcases, testing for correctness of solution

  • All inputs are valid.

  • If my reference solution gives the wrong result in the random tests, please let me know(post an issue).

Puzzles
ASCII Art

Stats:

CreatedNov 2, 2018
PublishedNov 2, 2018
Warriors Trained398
Total Skips151
Total Code Submissions173
Total Times Completed26
JavaScript Completions26
Total Stars25
% of votes with a positive feedback rating96% of 14
Total "Very Satisfied" Votes13
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • Voile Avatar
Ad