Cody

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

Solution 1999438

Submitted on 2 Nov 2019
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))

a = 1 a = 1 3 a = 1 3 6 a = 1 3 6 10 a = 1 3 6 10 15 a = 1 3 6 10 15 21 a = 1 3 6 10 15 21 28 a = 1 3 6 10 15 21 28 36 a = 1 3 6 10 15 21 28 36 45 a = 1 3 6 10 15 21 28 36 45 55 a = 1 3 6 10 15 21 28 36 45 55 66 a = 1 3 6 10 15 21 28 36 45 55 66 78 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 a = 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Column 30 465 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 31 465 496 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 32 465 496 528 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 33 465 496 528 561 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 34 465 496 528 561 595 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 35 465 496 528 561 595 630 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 36 465 496 528 561 595 630 666 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 37 465 496 528 561 595 630 666 703 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 38 465 496 528 561 595 630 666 703 741 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 39 465 496 528 561 595 630 666 703 741 780 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 40 465 496 528 561 595 630 666 703 741 780 820 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 41 465 496 528 561 595 630 666 703 741 780 820 861 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 42 465 496 528 561 595 630 666 703 741 780 820 861 903 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 43 465 496 528 561 595 630 666 703 741 780 820 861 903 946 a = Columns 1 through 29 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325 351 378 406 435 Columns 30 through 44 465 496 528 561 595 630 666 703 741 780 820 861 903 946 990 a = Columns 1 through 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 Columns 15 through 28 120 136 153 171 190 210 231 253 276 300 325 351 378 406 Columns 29 through 42 435 465 496 528 561 595 630 666 703 741 780 820 861 903 Columns 43 through 45 946 990 1035 a = Columns 1 through 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 Columns 15 through 28 120 136 153 171 190 210 231 253 276 300 325 351 378 406 Columns 29 through 42 435 465 496 528 561 595 630 666 703 741 780 820 861 903 Columns 43 through 46 946 990 1035 1081 a = Columns 1 through 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 Columns 15 through 28 120 136 153 171 190 210 231 253 276 300 325 351 378 406 Columns 29 through 42 435 465 496 528 561 595 630 666 703 741 780 820 861 903 Columns 43 through 47 946 990 1035 1081 1128 a = Columns 1 through 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 Columns 15 through 28 120 136 153 171 190 210 231 253 276 300 325 351 378 406 Columns 29 through 42 435 465 496 528 561 595 630 666 703 741 780 820 861 903 Columns 43 through 48 946 990 1035 1081 1128 1176 a = Columns 1 through 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 Columns 15 through 28 120 136 153 17...

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

a = 1 y = logical 1

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

a = 1 a = 1 3 y = 2×1 logical array 0 0

Assertion failed.