The nth element of a series A is defined by:
. Obviously, the first element
. Given the nth element
, find the value of the corresponding index n.
Solution Stats
Problem Comments
8 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers52
Suggested Problems
-
Return the 3n+1 sequence for n
8491 Solvers
-
3790 Solvers
-
Return fibonacci sequence do not use loop and condition
855 Solvers
-
Write a function man that takes a row vector v and returns a matrix H as follows..
647 Solvers
-
1042 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
@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
I think the last test case is wrong
Rahul Gulia, in the last test, there will be numbers greater than 1000. And the last test is not wrong. Just remember that indexes are always positive (I had trouble with that also, we are so focused on the sequence that we forget that indexes can't be negative).