Cody

# Problem 44457. Triangle of numbers

Solution 1393693

Submitted on 25 Dec 2017 by Yair Fridman
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))

x = 1 y = 1

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

x = 1 y = 1 x = 2 y = 1

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

x = 1 y = 1 x = 2 y = 1 y = 2 x = 3 y = 1 y = 2 y = 3 x = 4 y = 1

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))

x = 1 y = 1 x = 2 y = 1 y = 2 x = 3 y = 1 y = 2 y = 3 x = 4 y = 1 y = 2 y = 3 y = 4 x = 5 y = 1 y = 2 y = 3

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))

x = 1 y = 1 x = 2 y = 1 y = 2 x = 3 y = 1 y = 2 y = 3 x = 4 y = 1 y = 2 y = 3 y = 4 x = 5 y = 1 y = 2 y = 3 y = 4 y = 5 x = 6 y = 1 y = 2 y = 3 y = 4 y = 5 y = 6 x = 7 y = 1 y = 2 y = 3 y = 4 y = 5 y = 6 y = 7 x = 8 y = 1 y = 2 y = 3 y = 4 y = 5 y = 6 y = 7 y = 8 x = 9 y = 1 y = 2 y = 3 y = 4 y = 5 y = 6 y = 7 y = 8 y = 9 x = 10 y = 1 y = 2 y = 3 y = 4 y = 5 y = 6

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!