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

806 Solutions

318 Solvers

Last Solution submitted on Feb 04, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers318

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!