# The plus-minus sequence

## Jelly, 5 bytes

```
ṄI;Sß
```

This is a recursive approach. Due to tail call optimization, the only limit is the ability to fit both integers into memory. Output is one list per line.

Try it online!

### How it works

```
ṄI;Sß Main link. Argument: [b[n], a[n]] (n = 0 for original input)
Ṅ Print [b[n], a[n]] to STDOUT.
I Compute the increments of the list, i.e., [a[n] - [b[n]].
S Compute the sum of the list, i.e., b[n] + a[n].
; Concatenate the results to the left and to the right.
ß Recursively call the main link.
```

### Python 2, 31 bytes

```
def f(a,b):print a,b;f(a+b,a-b)
```

Prints forever. Well, eventually you exceed the recursion limit, but that's a system limitation.

## MATL, 10 bytes

```
`tDtswPdhT
```

This version will output an infinite number of elements in the plus-minus sequence.

**Try it Online!**
(stop it after running due to infinite loop)

**Explanation**

```
% Implicitly grab input as a two-element array [a,b]
` % do...while loop
tD % Duplicate and display the top of the stack
ts % Duplicate [a,b] and add them together
w % Swap the top two elements on the stack
P % Swap the order of b and a in preparation for diff
d % Compute the difference between b and a
h % Horizontally concatenate [a+b, a-b]
T % Explicit TRUE to make it an infinite loop
% Implicit end of the do...while loop
```