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

Stats:

CreatedNov 13, 2016
PublishedNov 13, 2016
Warriors Trained225
Total Skips25
Total Code Submissions238
Total Times Completed79
JavaScript Completions70
Python Completions11
Total Stars8
% of votes with a positive feedback rating94% of 31
Total "Very Satisfied" Votes27
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • Voile Avatar
  • saudiGuy Avatar
Ad