Given a row vector, x, return 1 if it is an arithmetic series, or 2 if it is a geometric series. If it is neither, return 0.
x = 1:8
y = 1
x = 2^(1:8)
y = 2
x = [1 1 2 3 5 8 13 21 34]
y = 0
Perhaps a better strategy is to make a new problem instead of frequently re-scoring due to incremental changes. BTW, the newly added last test case (#11) should return 2, not 1.
Yes, Test 11 -> 2
Test case 11 is still incorrect.
x = [i -2 -4i 8 16i] is an arithmetic serie ?
Test case 11 fixed. Thanks.
Your "if ..." returns false positive on complex input.
This solution will fail a test with x = [1 1 -1 -1]; y_correct = 0; assert(isequal(stype(x),y_correct)); Thus, I recommend to reinforce the test suite by adding this test.
Indeed. Test added. Thanks!
Solve the Sudoku Row
Flip the main diagonal of a matrix
Is the Point in a Triangle?
Spot the outlier
Symmetry of vector
Mean number of letters per word (Hard)
Factorizing a number into a given number of factors
Return the sequence element II
Juggler sequence revisited
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office