Medium Article - / recamans-sequence
Problem - https://www.geeksforgeeks.org/problem...
Given an integer n, return the first n elements of Recaman’s sequence.
It is a function with domain and co-domain as whole numbers. It is recursively defined as below:
Specifically, let a(n) denote the (n+1)th term. (0 being the 1st term).
The rule says:
a(0) = 0
a(n) = a(n-1) - n, if a(n-1) - n 0 and is not included in the sequence previously
= a(n-1) + n otherwise.
Example 1:
Input:
n = 5
Output:
0 1 3 6 2
Explaination:
a(0) = 0,
a(1) = a(0)-1 = 0-1 = -1 and -10, therefore a(1) = a(0)+1 = 1,
a(2) = a(1)-2 = 1-2 = -1 and -10, therefore a(2) = a(1)+2 = 3,
a(3) = a(2)-3 = 3-3 = 0 but since 0 is already present in the sequence, a(3) = a(2)+3 = 3+3 = 6,
a(4) = a(3)-4 = 6-4 = 2.
Therefore the first 5 elements of Recaman's sequence will be 0 1 3 6 2.
Sur cette page du site, vous pouvez voir la vidéo en ligne Recamans sequence geeks for geeks problem of the day python solution gfg potd python solution durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur VS Code 10 février 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 176 fois et il a aimé 2 téléspectateurs. Bon visionnage!