Recaman Sequence - I - MATLAB Cody - MATLAB Central

Problem 44338. Recaman Sequence - I

Difficulty:Rate

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 :

  1. Recaman Sequence - I
  2. Recaman Sequence - II
  3. Recaman Sequence - III

Solution Stats

53.58% Correct | 46.42% Incorrect
Last Solution submitted on Jun 06, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers311

Suggested Problems

More from this Author92

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!