The task is to print a sequence of numbers starting from n, without using a loop. In the sequence, subtract 5 from n repeatedly (i.e., n, n-5, n-10, etc.) until n becomes less than or equal to 0. Once n reaches this condition, start adding 5 back to n (i.e., n+5, n+10, etc.) until n returns to its initial value. Implement a function pattern(n) that takes n as input and returns a list of the generated sequence.
Example 1
Input: n = 13
Output: 13 8 3 -2 3 8 13
Explanation: The value decreases until it goes below 0. After that, it increases back to 13.
Example 2
Input: n = 5
Output: 5 0 5
Explanation: The value decreases until it reaches 0. After that, it increases back to 5.
Sign in to write, run, and submit your solution against the full test suite.