5 kyu
Fill an array with numbers and their square
70 of 79myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
Give you a number sequence seq
(array format), make a n*(n+1) matrix using these number and their square:
seq = [1,2,3,4,5,6]
Fill these numbers to the upper left triangle region of the matrix:
[
[1,2,3],
[4,5,?],
[6,?,?],
[?,?,?]
]
And then fill their square to the lower right triangle region of the matrix:
[
[ 1, 2, 3],
[ 4, 5, 1],
[ 6, 4, 9],
[16,25,36]
]
If the length of seq
is invalid(Can not form a triangle),return []
.
The valid length such as 1,3,6,10,15
can form a triangle such as:
1 3 6 10 15 ....
x xx xxx xxxx xxxxx
x xx xxx xxxx
x xx xxx
x xx
x
Some examples:
makeMatrix([2]) should return:
[
[2],
[4]
]
makeMatrix([2,4,6]) should return:
[
[ 2, 4],
[ 6, 4],
[16,36]
]
makeMatrix([9,8,7,6,5,4]) should return:
[
[ 9, 8, 7],
[ 6, 5,81],
[ 4,64,49],
[36,25,16]
]
makeMatrix([9,8,7,6,5,4,3]) should return []
Arrays
Algorithms
Similar Kata:
Stats:
Created | Nov 13, 2016 |
Published | Nov 13, 2016 |
Warriors Trained | 225 |
Total Skips | 25 |
Total Code Submissions | 238 |
Total Times Completed | 79 |
JavaScript Completions | 70 |
Python Completions | 11 |
Total Stars | 8 |
% of votes with a positive feedback rating | 94% of 31 |
Total "Very Satisfied" Votes | 27 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |