Cody

Problem 44457. Triangle of numbers

Solution 2541252

Submitted on 13 Jun 2020 by labib mazarib
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('triangle.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
n = 0; mat_correct = []; assert(isequal(triangle(n),mat_correct))

3   Pass
n = 1; mat_correct = 1; assert(isequal(triangle(n),mat_correct))

k = 2

4   Pass
n = 6; mat_correct = [1 0 0; 2 3 0; 4 5 6]; assert(isequal(triangle(n),mat_correct))

k = 2 k = 3 k = 4 k = 5 k = 6 k = 7

5   Pass
n = 12; mat_correct = [1 0 0 0; 2 3 0 0; 4 5 6 0; 7 8 9 10; 11 12 0 0]; assert(isequal(triangle(n),mat_correct))

k = 2 k = 3 k = 4 k = 5 k = 6 k = 7 k = 8 k = 9 k = 10 k = 11 k = 12 k = 13

6   Pass
n = 50; mat_correct = [1,zeros(1,8); 2:3,zeros(1,7); 4:6,zeros(1,6); 7:10,zeros(1,5); 11:15,zeros(1,4); 16:21,zeros(1,3); 22:28,0,0; ; 29:36,0; 37:45; 46:50,zeros(1,4)]; assert(isequal(triangle(n),mat_correct))

k = 2 k = 3 k = 4 k = 5 k = 6 k = 7 k = 8 k = 9 k = 10 k = 11 k = 12 k = 13 k = 14 k = 15 k = 16 k = 17 k = 18 k = 19 k = 20 k = 21 k = 22 k = 23 k = 24 k = 25 k = 26 k = 27 k = 28 k = 29 k = 30 k = 31 k = 32 k = 33 k = 34 k = 35 k = 36 k = 37 k = 38 k = 39 k = 40 k = 41 k = 42 k = 43 k = 44 k = 45 k = 46 k = 47 k = 48 k = 49 k = 50 k = 51