Problem 52462. Easy Sequences 1: Find the index of an element
Solution Stats
Problem Comments
-
6 Comments
@Ramon, if you are submitting a question on Cody for everybody to solve, it is recommended you put atleast 3 test suites, mostly so that it encourages people to learn and not hard code solutions.
Thanks, @Dyuman. There are now 4 test suites.
@Ramon, Wonderful!
-a+(1-(-1)^(n+1))/2 will be negative in the 4th test. I believe it should be: index(a-(1-(-1)^(n+1))/2).
This works fine in my MATLAB software. But not here.
Any comments, please?
function n = index(a)
for idx = 1:1000
b = idx*((-1)^(idx^3+1));
if b==a
break
else
continue
end
end
n=idx;
end
Because you are not doing what the question is asking
Problem Recent Solvers26
Suggested Problems
-
2195 Solvers
-
Recurring Cycle Length (Inspired by Project Euler Problem 26)
83 Solvers
-
Get the length of a given vector
6138 Solvers
-
Back to basics - mean of corner elements of a matrix
331 Solvers
-
729 Solvers
More from this Author66
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!