Recamans sequence geeks for geeks problem of the day python solution gfg potd python solution

Опубликовано: 10 Февраль 2024
на канале: VS Code
176
2

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.


На этой странице сайта вы можете посмотреть видео онлайн Recamans sequence geeks for geeks problem of the day python solution gfg potd python solution длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь VS Code 10 Февраль 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 176 раз и оно понравилось 2 зрителям. Приятного просмотра!