5 kyu
Simple Fun #309: Python Snake
35 of 44myjinxin2015
Description:
Task
Amirhossein is a painter who also loves pets. He has just bought a python snake, and would love to draw a picture of it. Now the snake is lying curled up, and Amirhossen wants to draw it using the smallest canvas possible.
Write a function that draws the python according to the following rules:
- The snake's picture should be returned as a rectangular matrix,
where 'H' is its head, 'T' is its tail, and 'x' is a part of its
body. Other elements of the matrix should be filled with ' '.
- The snake's body consists of several parts. Their lengths are
stored in the array body. The first element of the array starts
with the snakes head and goes from left to right (snake's head to
the left), the second part goes from right to left, the third one
from left to right again, and so on.
- The drawing shouldn't contain empty lines or empty columns
(i.e. rows or columns that consist only of ' ').
Input/Output
[input]
integer arraybody
The length of each part of pet's body.
2 <= body.length <= 100
1 <= body[i] <= 100
[output]
a string arrayPicture of the pet as a matrix of chars.
Example
For body = [1, 2, 3]
, the output should be:
[
[' ', 'H', ' '],
['x', 'x', ' '],
['x', 'x', 'T']
]
Here's how a professionally drawn python would look like:
Puzzles
Similar Kata:
Stats:
Created | May 26, 2017 |
Published | May 26, 2017 |
Warriors Trained | 325 |
Total Skips | 86 |
Total Code Submissions | 248 |
Total Times Completed | 44 |
JavaScript Completions | 35 |
Python Completions | 13 |
Total Stars | 10 |
% of votes with a positive feedback rating | 90% of 15 |
Total "Very Satisfied" Votes | 13 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |