Cody

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

50.4% Correct | 49.6% Incorrect
Last solution submitted on Sep 14, 2019

Problem Comments

Solution Comments