Problem 44338. Recaman Sequence - I
Recaman Sequence (A005132 - - OEIS Link) is defined as follow;
seq(0) = 0; for n > 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, otherwise seq(n) = seq(n-1) + n.
seq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ... index = 1, 2, 3 ,...
To avoid zero index, start indexing from 1. return the first n elements in Recaman Sequence
Related Challenges :
- Recaman Sequence - I
- Recaman Sequence - II
- Recaman Sequence - III
Solution Stats
Problem Comments
-
8 Comments
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 :-)
Solution Comments
Show commentsGroup

Cody5:Easy
- 31 Problems
- 159 Finishers
- Energy of a photon
- Breaking Out of the Matrix
- The Top 5 Primes
- I Plead the Fifth
- Pentagonal Numbers
- Is this is a Tic Tac Toe X Win?
- Inscribed Pentagon?
- Circle/Pentagon Overlap
- Octoberfest festival
- Polarisation
- Missing five
- ASCII Birthday Cake
- Find the nearest prime number
- Extra safe primes
- 5 Prime Numbers
- Is this is a Tic Tac Toe X Win?
- Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
- MATLAB Counter
- Basic electricity in a dry situation
- How to subtract?
- Pernicious Anniversary Problem
- 5 Prime Numbers
- Is it really a 5?
- The glass half full
- Pi Digit Probability
- A Simple Tide Gauge with MATLAB
- Predicting life and death of a memory-less light bulb
- Write c^3 as sum of two squares a^2+b^2
- Van Eck's Sequence's nth member
- Sums of Multiple Pairs of Triangular Numbers
- Recaman Sequence - I
- Recaman Sequence - II
- Spot the First Occurrence of 5
- Energy of a photon
Problem Recent Solvers310
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!