Recaman sequence uses zero indexing, thus `seq(n) = seq(n-1) - (n-1)` or `seq(n) = seq(n-1) + (n-1)` (not the formula used in the description).
That is correct. I have modified the sequence to avoid zero indexing.
According to the definition here, seq(2) should be 2 because seq(n-1)+n when n=2, is 2. And so on...
Adiel, Thanks for your attention. I have changed the definition.
When i preinitialise y as follows:
y = zeros(1,x);
it doesn't pass, but when i just ommit preinitialisation - it works perfectly!
Hello, Mehmet OZC. I think the problem statement is still subject to misinterpretation. At the moment it looks like "index" means "n", which is inconsistent with the formula. To avoid this misunderstanding, you could insert one extra row to show explicitly the values of "n". ... Thus you would have: seq = 0, 1, 3, 6, ... . Then, n = 0, 1, 2, 3, ... . And finally, Index = 1, 2, 3, 4, ... . ____ Alternatively, you could omit any mention of indexing and just clarify with an _example_, such as: "The first four elements are [0, 1, 3, 6]."
David, you have already made a good explanation for a possible misinterpretation. I appreciate it. Thanks for your contribution. When I said indexing I meant something like linear indexing (https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html)
good question :-)
Any idea what the time limit for the Cody solutions is? I've got code that runs the test suite in about 2.3 seconds on my (six-year old) machine, but it's timing out repeatedly on Cody.
Hi, James. The Cody time limit is reportedly around 30 seconds. [ https://www.mathworks.com/matlabcentral/cody/problems/44356 ] I just have confirmed a runtime of ~24 seconds (split across four tests) did not time out on Cody [Solution 1327589]. Although I would generally be aiming to get code complete within less than ~10 seconds in Cody. [Cf. Problem 44389.]
Reverse the Words (not letters) of a String
Implement simple rotation cypher
Create logical matrix with a specific row and column sums
Create an index-powered vector
How many Fibonacci numbers?
Lunar Arithmetic (Addition)
Recaman Sequence - III
Bridge and Torch Problem - Length of Unique Time List
Bridge and Torch Problem - Minimum time
Find a real root of a quintic function
Find the treasures in MATLAB Central and discover how the community can help you!
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