Cody

# Problem 139. Determine if a Given Number is a Triangle Number

Solution 372520

Submitted on 19 Dec 2013 by Zikobrelli
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
%% x = 1:100; y_correct = false(1,100); y_correct([1 3 6 10 15 21 28 36 45 55 66 78 91]) = true; assert(isequal(isTriangleNumber(x),y_correct))

y = 1 y = 1 0 y = 1 0 1 y = 1 0 1 0 y = 1 0 1 0 0 y = 1 0 1 0 0 1 y = 1 0 1 0 0 1 0 y = 1 0 1 0 0 1 0 0 y = 1 0 1 0 0 1 0 0 0 y = 1 0 1 0 0 1 0 0 0 1 y = 1 0 1 0 0 1 0 0 0 1 0 y = 1 0 1 0 0 1 0 0 0 1 0 0 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 y = 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Column 17 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 18 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 19 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 20 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 21 0 0 0 0 1 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 22 0 0 0 0 1 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 23 0 0 0 0 1 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 24 0 0 0 0 1 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 25 0 0 0 0 1 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 26 0 0 0 0 1 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 27 0 0 0 0 1 0 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 28 0 0 0 0 1 0 0 0 0 0 0 1 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 29 0 0 0 0 1 0 0 0 0 0 0 1 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 30 0 0 0 0 1 0 0 0 0 0 0 1 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 31 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Column 33 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 34 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 35 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 36 0 0 0 1 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 37 0 0 0 1 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 38 0 0 0 1 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 39 0 0 0 1 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 40 0 0 0 1 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 41 0 0 0 1 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 42 0 0 0 1 0 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 43 0 0 0 1 0 0 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 44 0 0 0 1 0 0 0 0 0 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 45 0 0 0 1 0 0 0 0 0 0 0 0 1 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 46 0 0 0 1 0 0 0 0 0 0 0 0 1 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 47 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 48 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 48 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 Column 49 0 y = Columns 1 through 16 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 Columns 17 through 32 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 Columns 33 through 48 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 Columns 49 through 50 0 0 y =...

2   Pass
%% x = 1; y_correct = true; assert(isequal(isTriangleNumber(x),y_correct))

y = 1

3   Pass
%% x = [4912734125;4912734126]; y_correct = [false;true]; assert(isequal(isTriangleNumber(x),y_correct))

y = 0 y = 0 1 y = 0 1