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 :

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

Solution Stats

53.36% Correct | 46.64% Incorrect
Last Solution submitted on May 29, 2024

Problem Comments

Solution Comments

Show comments


Problem Recent Solvers306

Problem Tags

Community Treasure Hunt

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

Start Hunting!